FPS Style

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

Recommended Posts

Hey, I'm developing a driving simulator using opengl/c++ and I wanted to get the speed of the vehicle fixed to the screen. so far I followed some nehe tutorials and i can get the speed to come up, but trying to get it to follow the camera view is abit difficult and also if i go near a wall it gets lost in it. i'm sure theres a simple way to do it but i cant find any. I just need it fixed to the view no matter what is in the view it should always be on top. like in doom, where your health and bullets are always at the bottom of the screen. Any help will be much appreciated.

Share on other sites

Oh, and show us the code you're currently using to display it.

Share on other sites
Yeah thats right i want to code a HUD, thanx i forgot the right term for it.

Well this is the code that is in the draw method:
glColor3f(1.0f,1.0f,1.0f);glRasterPos3f(camera.mView.x+3.0f,0.5f,camera.mView.z);glPrint("%0.0f mph", vehicle->getVel().magnitude());

This works as in it shows the speed, but this makes it an actual 3d object of the scene and doesn't look good wen i collide against walls cos it disappears into the wall. It also doesn't follow the view correctly, i could probably fix that though by minusing -3.0f when the car turns around and vice-versa, but what im really after is a HUD.

I'll just put up some code of how the font gets printed just incase anyone wants to take a look:

GLvoid BuildFont(GLvoid) {       HFONT font;       HFONT oldfont;              base = glGenLists(96);              font = CreateFont( -24,                            0,                            0,                            0,                            FW_BOLD,                            FALSE,                            FALSE,                            FALSE,                            ANSI_CHARSET,                            OUT_TT_PRECIS,                            CLIP_DEFAULT_PRECIS,                            ANTIALIASED_QUALITY,                            FF_DONTCARE|DEFAULT_PITCH,                            "Eurostile");      	oldfont = (HFONT)SelectObject(hDC, font);		// Selects The Font We Want	      wglUseFontBitmaps(hDC, 32, 96, base);			// Builds 96 Characters Starting At Character 32	      SelectObject(hDC, oldfont);				// Selects The Font We Want	      DeleteObject(font);					// Delete The Font}GLvoid KillFont(GLvoid)	{					// Delete The Font List 	glDeleteLists(base, 96);				// Delete All 96 Characters ( NEW )}GLvoid glPrint(const char* fmt, ...) {       char text[256];       va_list ap;              if (fmt==NULL) return;              va_start(ap, fmt);					// Parses The String For Variables	      vsprintf(text, fmt, ap);				// And Converts Symbols To Actual Numbers	      va_end(ap);						// Results Are Stored In Text       glPushAttrib(GL_LIST_BIT);				// Pushes The Display List Bits		( NEW )	      glListBase(base - 32);					// Sets The Base Character to 32	( NEW )       glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);	// Draws The Display List Text	( NEW )       glPopAttrib();						// Pops The Display List Bits	( NEW )}

Share on other sites
How do you draw your HUD ?
Maybe try to make a poly->
set it direct before the cam and
draw to the texture of it.
Otherwhise you must change you'r rendering order.

Share on other sites
I sounds like you want to use orthogonal mode, which enables you to draw your HUD in 2D. I know that NeHe has some tutorials about it, otherwise you should get plenty of help from google.

Share on other sites
Thanx for the help but i just found a thread that solves this problem and it works perfectly...

heres the link if anyone wants to know:
http://www.gamedev.net/community/forums/topic.asp?topic_id=388298

Share on other sites
You must switch to orthogonal mode (perhaps using glOrtho) and disable depth testing.