Jump to content
  • Advertisement

Archived

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

ManifestDestiny

Direct 3D and HUDs

This topic is 5299 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone! I''m still a beginner programmer as far as my experience with DirectX goes, and I''ve run into a little problem. Right now I''m making a simple game - Space Invaders 3D. The problem occurs now due to the fact that I need a HUD (just a simple printout of the current score and level). Are there any functions that will print text out onto the screen? GDI calls don''t work; the flicker would give just about anyone a seziure after long enough. If there aren''t any simple functions to do so (I can''t imagine why there wouldn''t be, though) how would I go about doing this? Thanks in advance. Und so weiter. Na ja?

Share this post


Link to post
Share on other sites
Advertisement
In Direct3D can you modify the backbuffer directly, like lock it etc? Couldn''t you then do some 2D based drawing onto it?

Share this post


Link to post
Share on other sites

mixing hardware 3D rendering and software 2D rendering is a no-no thise days.

The usual way to draw 2D stuff now is either use D3DXFont, or D3DXSprite, or build your own DirectX wrapper for drawing 2D polygons (3d polygons with an isometric perspective)... I did the last one, with extremely good results.

Share this post


Link to post
Share on other sites
Using GDI calls is perfectly possible. Just remember to get the device context from your BACK BUFFER in stead of your FRONT BUFFER, or flickering will occur ofcourse . Use a call like this:


if( !SUCCEEDED(m_ddbbuff->GetDC(&m_hDC))) {
ENGINE_LOG(("failed to get device context from back surface"));
}


After that you can print text with calls like this:


SelectObject(m_hDC, font);
SetTextColor(m_hDC, RGB(r,g,b));
SetBkMode(m_hDC, TRANSPARENT);
ExtTextOut(m_hDC, x, y, 0, NULL, text, lstrlen(text), NULL);


When you're done with the GDI calls, don't forget to release the DC:

m_ddbbuff->ReleaseDC(m_hDC);


HTH

Marc

[edited by - Marc aka Foddex on May 10, 2004 7:38:11 AM]

[edited by - Marc aka Foddex on May 10, 2004 7:39:11 AM]

Share this post


Link to post
Share on other sites
GDI is slow, but pretty simple stuff to get working.

The D3D Fonts are all faster, but not nearly as simple to get up and running.

For printing a couple things to the screen in a fairly basic game GDI would probably be more than enough. However, learning to use the various 3D fonts available won''t be a bad thing for projects down the road, and they aren''t THAT tough to figure out.

Share this post


Link to post
Share on other sites
ID3DXFont couldn''t be called hard to use.


ID3DXFont *d3d_font;

D3DXCreateFont(d3d_device, height,0,
FW_NORMAL,1,FALSE,
DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,
ANTIALIASED_QUALITY,DEFAULT_PITCH|FF_DONTCARE,
"Arial",&d3d_font);

SetRect(&rect,x,y,640,480);
d3d_font->DrawText(NULL,"Text goes here",-1,&rect,DT_LEFT|DT_NOCLIP,0xFFFFFFFF);
[source]

Of course you need to do error checking, lost device recovery and release the font interface when finished but thats no big deal.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
GDI is indeed slow, but theres way''s around that. I attach my dc to a texture then render that texture on a quad.

The texture is updated only when needed - and even if that is a few times a second I still get good performance.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!