Should I make 2D based engine wich can use 3D to draw?

Started by
7 comments, last by Craazer 20 years, 4 months ago
Hi! I''m making a 2D engine using DX SDK v8.0, and infact it''s mostly done but I would like to have suport for 3D accelaration to get more speed perhaps. But it seems to be a bit tricky to make code wich would use direct-x''s 3D capilities to draw 2D and same time use direct draw. So I supose I have to check if there''s 3D suport and use it but unless it ins''t avaible then I should initialize direct draw instead of direct 3D. Is that how it goes? Lot of if statements to check wich one init and use... Could it be easier whit DX 9.0?
Advertisement
I have no clue about DX but I''d create a base graphic class with all graphic functions you need, then create a class specific to DDraw and one for D3D.
Then when you start the game check for 3D support or a user option and use the right class.
You''d simply use the base class everywhere and overload the specific methods. I.e. you could have a BitBlt method in the base class and overload it in the DDraw class to use the DDraw function for it, same for D3D and all other functions (mainly init, load sprite and draw sprite).
The problem is it is pretty hard to convert a few things from Direct Draw to Direct3D. One huge problem for example is the fact you can only use textures in the powers of two. This can always be solved by generating oversized textures at run-time, but it isn''t neat in situations like when you have a 520x520 texture and therefore have to scale it up to 1024x1024. You can still store other textures on that though.

However, as I said the main problem is that converting straight between Direct Draw and Direct3D can be very hard, and you''ll probably have to make lots of changes. Please don''t take this as discouragement from using D3D for 2D, rather I encourage you to start using D3D instead, since it offers so much more than it sacrifices.

Arguments for moving to Direct 3D:
1. Hardware alpha blending.
2. Hardware scaling and rotation.
3. Hardware Lighting.

The list goes on, basically most special effects you needed to ultra-optimize in software before, can now be done very easily in hardware with high speeds.

Go for Direct3D!
why not just use 3d? instead of setting where everything is to be shown, and if its onscreen draw, 3d does all thatr for u
Pretty much everything supports Direct3D these days. Definitely any new computer sold in the last 4 years, and probably most computers that are less than 7 years old.

If you want to target an API that only allows power of two texture sizes, how about actually designing your art to those limitations? If you don''t, then your 520x520 can still be split into a 512x512, an 8x512, a 512x8, and an 8x8. Just beware of filtering at the edges; you may want to replicate pixels across edges and putting 510x510 into one, 10x510 in one, etc to make filtering work right. Or just use no filtering.

Things like arbitrary rotation are of course trivial when using a 3D API.
enum Bool { True, False, FileNotFound };
You can load arbitrary sized images to appropriate sized surfaces. Instance LPDIRECT3DSURFACE8 and then use m_D3DDevice->CreateImageSurface() to create a appropriate surface. Use D3DXLoadSurfaceFromFile() to load graphics and use D3DXLoadSurfaceFromSurface() (or copy rects) to blit to the backbuffer. You can access your backbuffer with m_D3DDevice->GetBackBuffer()

"The Holocaust was an obscene period in our nation's history. I mean in this century's history. But we all lived in this century. I didn't live in this century."...Governor George W. Bush, 9/15/95
I have decided to rely 3D capilities. I first though it would be cool to have 2D suport in case some one''s craphics card doesn''t support some techniques like rotation. (I made very fast surface rotation blit on direct draw for that and all.)

Well thanks for opening my eyes and cheers and such to all!
quote:Original post by Craazer
I have decided to rely 3D capilities. I first though it would be cool to have 2D suport in case some one''s craphics card doesn''t support some techniques like rotation. (I made very fast surface rotation blit on direct draw for that and all.)

Well thanks for opening my eyes and cheers and such to all!


If someone''s card doesnt support rotation (via moving vertices), someone''s card doesn''t support any 3d acceleration at all.

quote:Original post by glassJAw
quote:Original post by Craazer
I have decided to rely 3D capilities. I first though it would be cool to have 2D suport in case some one''s craphics card doesn''t support some techniques like rotation. (I made very fast surface rotation blit on direct draw for that and all.)

Well thanks for opening my eyes and cheers and such to all!


If someone''s card doesnt support rotation (via moving vertices), someone''s card doesn''t support any 3d acceleration at all.



Ok good, I supose.

This topic is closed to new replies.

Advertisement