Skip to main content
gamedev.net
🔒 Locked

FPS Style

Started by PSD 5 replies 1.2k views
Original Post
PSD
PSD
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.
Endar
Endar
I know nothing about this, but just to clarify, you're looking for a HUD (heads-up-display)?

Oh, and show us the code you're currently using to display it.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
PSD
PSD
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 )}         
LJ_1102
LJ_1102
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.
Jan F. Scheurer - CEO @ Xe-Development Sign Up fo
Perost
Perost
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.
PSD
PSD
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
Ravuya
Ravuya
You must switch to orthogonal mode (perhaps using glOrtho) and disable depth testing.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.