• Advertisement

Archived

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

Direct 3D and HUDs

This topic is 5033 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
Don''t use the GDI it is as slow as a wet weekend. Look up ID3DXFont as has been said. It is very simple to use.

Share this post


Link to post
Share on other sites
Your bets bet is to use either D3DXFont or CD3DFont (from the SDK samples).

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
the DXFont is really slow it used to cut the fps in half on my application. Do this instead.

make a texture with ABCDEFGHIJKLMNOPQRSTUVXYZ and whatever other letters you''d want to use.

Share this post


Link to post
Share on other sites
Uh, I hate to break it to you but this is exactly what the DXFont class does. It uses GDI to setup a texture with all the letters in it.

Share this post


Link to post
Share on other sites
quote:
Original post by yzzid
Uh, I hate to break it to you but this is exactly what the DXFont class does. It uses GDI to setup a texture with all the letters in it.
And your source on this is... ?

Share this post


Link to post
Share on other sites
quote:
Original post by OOCCO
And your source on this is... ?


It''s fairly common knowledge that D3DX used GDI to make a font cache. It''s been stated by the DX team a number of times.

D3DXFont (as of the Summer 2003 Update) is quite fast. The older version was pretty slow but that''s old news.

Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
quote:
Original post by Dakiar
the DXFont is really slow it used to cut the fps in half on my application. Do this instead.


Were you using the Summer 2003 SDK?

Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
Yes D3DX uses the GDI to create the font letters. I think only at creation time though and apparently as the last poster said this is improved in summer update. I tried using it for a gui and ended up rolling my own instead due to the speed hit but I aim to try it again as it is less hassle than making your own

Share this post


Link to post
Share on other sites

  • Advertisement