Archived

This topic is now archived and is closed to further replies.

mjones0

Questions From Someone New To Direct3D

Recommended Posts

I’ve just switched from DirectDraw 7 to Direct3D 8 for some 2D graphics. I’m using ID3DXSprite which makes it very easy to get the benefits of Direct3D without knowing anything about 3D programming. The 512x512 and power of 2 limitations are a bit inconvenient, but overall I’m glad I left DirectDraw 7 behind. Anyway, I had a few questions and a friend directed me here. I’d be grateful if you could answer any of these: 1) When I get a D3DERR_DEVICENOTRESET result back from TestCooperationLevel() I call IDirect3DDevice8::Reset(), ID3DXSprite::OnLostDevice() and ID3DXSprite::OnResetDevice(). I’m not actually releasing and reacquiring the back buffer, or reloading any of the images to the Direct3DTextures as I would have had to do with DirectDraw7. Without doing this it seems to work fine. Should I be reloading the images and reacquiring the back buffer or is it not necessary with Direct3D/ID3DXSprite? 2) I read that you should only call BeginScene() and EndScene() once per frame because of the overheads involved. Does the length of time between calling BeginScene() and EndScene() cause any overheads, meaning you should try to keep the amount of code between them to a minimum, or does it not matter? 3) Is it possible to use ID3DXSprite::Draw() to draw to a surface other than the back buffer, and if so how? Apologies if any of these questions are a bit stupid. Thanks for your help.

Share this post


Link to post
Share on other sites
quote:
Original post by mjones0
I’ve just switched from DirectDraw 7 to Direct3D 8 for some 2D graphics. I’m using ID3DXSprite which makes it very easy to get the benefits of Direct3D without knowing anything about 3D programming. The 512x512 and power of 2 limitations are a bit inconvenient, but overall I’m glad I left DirectDraw 7 behind.


Umm, the 512x512 limitation is probably imposed by your graphics card. Common hardware limits are 256x256, 1024x1024 and 2048x2048.

(1)
As long as your textures are created in the managed space (the default) that''s perfectly OK.

(2)
What EndScene does is wait for the graphics card finish everything it''s doing so you can access the backbuffer. As far as I know, BeginScene..EndScene isn''t anything like Lock..Unlock, so you should be pretty fine putting considerable code between the calls, and usually will only want to end the scene just before you Present() it. I might be wrong though.

(3)
Look up SetRenderTarget() in the DirectX SDK, it''s well documented.

- JQ
Full Speed Games. Coming soon.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
For the end and begin scene.... well I don''t know exactly what it does, but my experience tells me that you can put a lot of code in the middle with no real hassle. On a "test" I was doing I even created the whole scene, did some extra calculations for movements and reactions and filled all the vertex and index buffers every frame in the middle of the begin and end calls (as you can see I followed every shred of advice on how to program ;-)) ) and I didn''t have any noticeable slowdown (even when I decided to organize the code properly). So I''ll suppose that end/begin calls are probably just to set flags and (more importantly) for debugging cases when the card isn''t ready to begin the next scene.
Just as an extra... If I remeber correctly one of the D3D examples calls begin and end scene various times per frame, I''m not sure which one it is and I''m not sure for what reason (if it''s to create the various cubemaps then forget this part as the various calls would be to make each face of the cubemap).

If you want to try something different than set render target then you can try the render to surface interface that comes in the D3Dx part. It''s easy to set up and it actually is quite useful to do somestuff, and it takes part of the housekeeping off your hands.

Share this post


Link to post
Share on other sites
Thanks a lot to both of you for your help. I was unsure about those three issues but that’s really cleared it up for me.

Thanks also for the information about the maximum texture size. I thought I read somewhere that this was a feature, so it’s lucky you corrected. I’ll have to have a look into what I’m doing wrong.

Thanks again

Share this post


Link to post
Share on other sites