Archived

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

Moe

mixing 2D and 3D with DX8?

Recommended Posts

I have been through several tutorials about DirectX 8. I have yet to see one that mixes 2D and 3D. Is it even possible without having to use a legacy interface and go through Direct Draw? I would like to make a menu system so that when I click on menu option (or something like that) something happens. I had an idea about how to do this. I would use the 3D untransformed vertices and find out where they were on the sceen in screen co-ordinates, then I would put that into my program and have it so if it clicked in that area it would do what I wanted. The problem is getting the 3D quads to look like it is really a 2D quad. Anybody following me? Anyone have any ideas about this? Never cross the thin line between bravery and stupidity.

Share this post


Link to post
Share on other sites
I made a program in DX8 that mixes 2D and 3D effects? Is that what you want?

I can draw 2D sprites with DX8 by making a triangle fan, and putting a texture on it. Is that what you are asking?

It''s in visual basic, but it is the same function calls as in c++. If you want to see it goto my homepage at www.ews.uiuc.edu/~jrbennet/

Share this post


Link to post
Share on other sites
No, I am afraid thats not what I''m after. I want to be able to make 2D looking menus and be able to do 3D stuff all in the same program.

Never cross the thin line between bravery and stupidity.

Share this post


Link to post
Share on other sites
What I did for my menysystem in DX8 was to ues the CopyRects function of the DX8 library (see below: d3dDevice is a legal D3D device and pBkgBitmap is a D3D8 surface)

  
LPDIRECT3DSURFACE8 pBackBuffer = NULL;
d3dDevice->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);


RECT rcSource[] = {0, 0, 800, 600};
POINT ptDest[] = {0, 0};
d3dDevice->CopyRects(pBkgBitmap, rcSource, 1, pBackBuffer, ptDest);


And top of this I can make 3D effects

PS. Dunno if this was what you asked for but for menusystem / none-in-game graphics CopyRects works great, although you can''t use colorkeys and stuff Ds.

Share this post


Link to post
Share on other sites
I found a few good examples of what I am after:

In half-life there was the health and HEV suit strength numbers on the screen. They seemed 2 dimensional and never moved when you moved. They also never got covered over by anything in the world. The same is in Deus Ex. How do they mix 2d and 3d elements? Are they just billboarded quads set the closest to the near clipping plane as possible?

I want to create a 2d menu system for part of my game, but still have 3d elements (untransformed vertices) in the same program. How is this done?

Never cross the thin line between bravery and stupidity.

Share this post


Link to post
Share on other sites
Hello Moe,

quote:


Are they just billboarded quads set the closest to the near clipping plane as possible?




Yes, I think they do. Don´t use CopyRect, it´s slow. Use a vertex shader with the flag D3DFVF_XYZRHW. Then you just set z position to 0 in your quad vertex structure.

Gandalf the Black

Share this post


Link to post
Share on other sites
If you use transformed polys for the 2d elements, then you can set the screen co-ordinates yourself, compensating for different screen res''s.

Maybe you could use z-biasing to ensure these polys are always drawn on top, or maybe you could draw your 2d elements last in the list, and temporarily turn off z-buffering before you draw them.

Share this post


Link to post
Share on other sites
Thats the problem. How do I convert world space coordinates to screen coordinates? And what would happen if something was clipped on the near clipping plain where the 2d object was supposed to be?

Share this post


Link to post
Share on other sites
If you use *transformed* triangles (just for the 2d elements) then D3D doesn''t transform them for you and you specify each vertex in actual screen coordinates.

I don''t know if this works since i''ve never tried it, but you would draw your 3d scene as normal, with untransformed polys, then switch to using transformed polys and draw your 2d elements, and you would be able to specify their positions in screen coordinates (since that''s what transformed polys are, the x,y are straight screen co-ords).

To guarantee they are drawn on top of everything else, switch off z-buffering, draw the polys, then switch it back on. As long as they are drawn last they''ll appear ontop always.

Share this post


Link to post
Share on other sites