Sign in to follow this  
PSD

FPS Style

Recommended Posts

PSD    122
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 this post


Link to post
Share on other sites
Endar    668
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.

Share this post


Link to post
Share on other sites
PSD    122
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 this post


Link to post
Share on other sites
LJ_1102    1233
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 this post


Link to post
Share on other sites
Perost    332
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 this post


Link to post
Share on other sites
PSD    122
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this