Direct3D for 2D tile rendering
I recently read the article Direct3D for 2D tile rendering by Bracket and I found it very interesting.
I tried to mess with it a little and now I understand pretty good. But now I would like to use a normal BackBuffer from DirectDraw to do some stuff I made in my old engine.
Anyone wouls be kind enough to tell me how to make it and maybe post some code cause I''m kinda new in DirectX. Seeing the code of an example help me a lot to understand it.
Thanks
---------------------------Unfortunately, no one can be told what a bug is.You have to see it for yourself...
You can use the backbuffer in the same way as you did before, just render the 3D stuff, and then apply your functions to the backbuffer.
Render();
BackBuffer->Blt(▭, &lpdds, ▭, DDBLT_WAIT, NULL);
// Any other BackBuffer functions here
Render();
BackBuffer->Blt(▭, &lpdds, ▭, DDBLT_WAIT, NULL);
// Any other BackBuffer functions here
Working on: DoP
Someone please correct me if I''m wrong but isn''t mixing 2d blits and 3d rendering a bad idea? My understanding is that the video card has to change states and flush its memory of vertex (not sure about textures) information before it can think about accepting your 2d command. The end result is bad performance. The MS docs suggest if you use 3d rendering for something do it for all you items from tiles to objects to "HUD" type information.
Sieggy
Sieggy
One question I would like answering related to the whole 2D using D3D issue... is the software mode of Direct3D fast enough to not require a straight DirectDraw version for older machines that don''t have hardware acceleration? How does Direct3D''s software rendering compare to Blt() and
BltFast()?
BltFast()?
I''m not sure if this Direct3D stuff works for me - using it, don''t I have to keep all my textures and sprites in video memory? And since there are limits to texture size, how do I draw large images on the screen for menus or HUDs and such?
I was under the impression (from reading "Tricks of the..." that Direct3D actually uses the 2D functionality of DirectDraw for the final scene rendering. Correct me if I''m wrong, but I think this would explain why its ok to use DirectDraw calls outside of your BeginScene() EndScene() section, but not inside (where D3D is using DDraw and shouldn''t be messed with)
Sphet: You lose most of your hardware excelleration if you keep textures (or surfaces) in sysmem instead of vidmem. If you want to render a large area (say a background image) you can break it into a couple textures and render it with D3D that way. For example, the most efficent way to break up a 640x480 background is into a set of 75 tiles (each 128x32) This is, unfortunately, the *least* number of tiles which have dimensions that are mutliples of 2 that will cover a 640x480 screen without overlap (since 640=2^7 * 5 and 480=2^5 * 3 * 5)
If you don''t really want to have to keep track of 75 textures for one background (that would be 150 triangles to render) and you don''t mind using a little extra memory, you can make the textures overlap and use a tile pattern such as 3x2 (256x256) or even better, a 3x2 where the first 4 tiles are 256x256 and the last two are 128x256:
where you would have a 32 pixel overlap at the center. I think you could even do better if you developed a more complicated tileing system that uses iregular tile shapes:
640 = 0b1010000000
480 = 0b0111100000
so the absolute best you could do is use a 2x4 grid where dimensions of the tiles are determined by the bits that are set in the size:
sorry the scale is a little off... The dimentions add up, though (you might have to break the 512 down into two columns of 256, but you get the point) If this seems like an overly complicated way to draw a background, well, you''re right! Its probably easier to just use DirectDraw and take whatever performance hit it entails, but if you are interested in going the D3D route, this is the way to do it
Hope that helps,
-- Chip
Sphet: You lose most of your hardware excelleration if you keep textures (or surfaces) in sysmem instead of vidmem. If you want to render a large area (say a background image) you can break it into a couple textures and render it with D3D that way. For example, the most efficent way to break up a 640x480 background is into a set of 75 tiles (each 128x32) This is, unfortunately, the *least* number of tiles which have dimensions that are mutliples of 2 that will cover a 640x480 screen without overlap (since 640=2^7 * 5 and 480=2^5 * 3 * 5)
If you don''t really want to have to keep track of 75 textures for one background (that would be 150 triangles to render) and you don''t mind using a little extra memory, you can make the textures overlap and use a tile pattern such as 3x2 (256x256) or even better, a 3x2 where the first 4 tiles are 256x256 and the last two are 128x256:
+------+------+---+l l l ll l l l+------+------+---+l l l ll l l l+------+------+---+
where you would have a 32 pixel overlap at the center. I think you could even do better if you developed a more complicated tileing system that uses iregular tile shapes:
640 = 0b1010000000
480 = 0b0111100000
so the absolute best you could do is use a 2x4 grid where dimensions of the tiles are determined by the bits that are set in the size:
+--------------------------------+--------+l l ll l ll l ll 512x256 l 128 ll l x ll l 256 ll l ll l l+--------------------------------+--------+l l ll l 128 ll 512x128 l x ll l 128 l+--------------------------------+--------+l l 128 ll 512x64 l x64 l+--------------------------------+--------+l 512x32 l 128x32 l+--------------------------------+--------+
sorry the scale is a little off... The dimentions add up, though (you might have to break the 512 down into two columns of 256, but you get the point) If this seems like an overly complicated way to draw a background, well, you''re right! Its probably easier to just use DirectDraw and take whatever performance hit it entails, but if you are interested in going the D3D route, this is the way to do it
Hope that helps,
-- Chip
Thanks all for your posts
I have another question for you guys
I tried to create a surface, a backbuffer and a clipper rect but when I try to attach my clipper to the surface, it crash
Do I have to initialize DirectDraw in the same way I do when I''m rendering with it or I need to use Direct3D for something ?
I have another question for you guys
I tried to create a surface, a backbuffer and a clipper rect but when I try to attach my clipper to the surface, it crash
Do I have to initialize DirectDraw in the same way I do when I''m rendering with it or I need to use Direct3D for something ?
---------------------------Unfortunately, no one can be told what a bug is.You have to see it for yourself...
I''m having some really weird experiences with this code when trying to get the wireframe version working. If I use the HAL, all the triangles in a triangle strip are bound on one point to the origin in the upper left corner. If I run it in software rendering, this works fine. Whats the deal? It seems that ANY of the triangle formats are not working correctly. Is there something wrong here?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement