Adding 2D elements in 3D scene
Hi all,
Can someone point me in the right direction? I would like to add some 2D elements to my 3D scene like an energy bar / score / lives left etc using graphics not text (I can do that already). I guess I need to use the stencil buffer but I''m not sure how.
Any articles or sample code would be great. Or just a few function names to point me in the right direction.
Cheers
Andy
-----------------------------
Andy Pike
DirectX 8 Tutorials: www.andypike.com
The SDK refers to "Compositing". That sounds like what I''m after.
"Using DirectX Graphics" > "Techniques and Special Effects" > "Stencil Buffer Techniques" > "Compositing"
-----------------------------
Andy Pike
DirectX 8 Tutorials: www.andypike.com
"Using DirectX Graphics" > "Techniques and Special Effects" > "Stencil Buffer Techniques" > "Compositing"
-----------------------------
Andy Pike
DirectX 8 Tutorials: www.andypike.com
You don''t have to use a stencil. After you draw the 3d scene, turn off the z-buffer, so anything you draw will appear on top of the scene. Then, set an orthogonal projection matrix and position your camera for 2D.
- set up orthogonal-projection viewpoint
- disable the depth buffer
- render sprites in screen space rather than world-space
- restore depth buffer
- restore the worldspace viewpoint
- disable the depth buffer
- render sprites in screen space rather than world-space
- restore depth buffer
- restore the worldspace viewpoint
So, when it comes to rendering, do I render textures of my energy bar (for example) on to polygons? Or should I blit to the screen (if you can)?
-----------------------------
Andy Pike
DirectX 8 Tutorials: www.andypike.com
-----------------------------
Andy Pike
DirectX 8 Tutorials: www.andypike.com
G''day!
Definitely render them as sprites. Whether you use D3DXSprite, or just some quads, it''ll do the trick. Don''t blit, it can cause some nasty performance hits.
If your 2D elements are fairly static you can just use XYZRHW vertices and edit them manually for changes, that way you don''t have to mess with the Ortho view. but if doing more fancy things, the Ortho view is a big win.
Stay Casual,
Ken
Drunken Hyena
Definitely render them as sprites. Whether you use D3DXSprite, or just some quads, it''ll do the trick. Don''t blit, it can cause some nasty performance hits.
If your 2D elements are fairly static you can just use XYZRHW vertices and edit them manually for changes, that way you don''t have to mess with the Ortho view. but if doing more fancy things, the Ortho view is a big win.
Stay Casual,
Ken
Drunken Hyena
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement