OpenGL HUD
I'm extremely new to OpenGL, but not game design (i used to use SDL). Is there any way to draw directly to the screen to do a HUD without having to use glTranslate or glRotate or anything else. Either opengl doesn't do this or I'm just looking through the wrong functions. Any insight would be awsome Ozwald~
Search for the millions of threads about 2d using OpenGL. The same method can be used to draw a hud over your 3d scene.
it's simple, use glOrtho and the turn off depthwriting and depthtesting with
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
and you have a good hud drawing mode.
also you can use these functions to help switching back and forth between the different modes.
you might still have to use glTranslate (you won't get away from that in openGL) but it's definitly a lot easier to draw the hud in this mode.
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
and you have a good hud drawing mode.
also you can use these functions to help switching back and forth between the different modes.
void ViewOrtho(int x, int y) // Set Up An Ortho View{ glMatrixMode(GL_PROJECTION); // Select Projection glPushMatrix(); // Push The Matrix glLoadIdentity(); // Reset The Matrix glOrtho( 0, x , y , 0, -1, 1 ); // Select Ortho Mode glMatrixMode(GL_MODELVIEW); // Select Modelview Matrix glPushMatrix(); // Push The Matrix glLoadIdentity(); // Reset The Matrix}void ViewPerspective(void) // Set Up A Perspective View{ glMatrixMode( GL_PROJECTION ); // Select Projection glPopMatrix(); // Pop The Matrix glMatrixMode( GL_MODELVIEW ); // Select Modelview glPopMatrix(); // Pop The Matrix}
you might still have to use glTranslate (you won't get away from that in openGL) but it's definitly a lot easier to draw the hud in this mode.
www.flashbang.se | www.thegeekstate.com | nehe.gamedev.net | glAux fix for lesson 6 | [twitter]thegeekstate[/twitter]
just print what you want to the screen...here's a routine from nehe's tutorial for printing...works just like printf in c
it uses lists for the font...if you look through nehe's tutorials, and find some of the font/printing text tutorials, you find how to load such.
hope that helps.
Oz~
PS:
GLvoid glPrint(GLuint glfontlist, GLfloat x, GLfloat y, const char *fmt, ...){ if( glIsList( glfontlist ) == GL_FALSE ) { // Error Report? return; } glRasterPos2f( x, y ); char text[256]; va_list ap; if(fmt==NULL) return; va_start(ap, fmt); vsprintf(text, fmt, ap); va_end(ap); glPushAttrib(GL_LIST_BIT); glListBase(glfontlist - 32); glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); glPopAttrib();}
it uses lists for the font...if you look through nehe's tutorials, and find some of the font/printing text tutorials, you find how to load such.
hope that helps.
Oz~
PS:
int score = 50;glPrint( yourfont, 1.0f, 500.0f, "Your score is: %d", score );
The coordinates using ortho mode should be the same as the window coordinates (as in if the res is 800x600, x goes 0-800, y goes 0-600)
If you want true windows coords, use ScreenToClient( hWnd, POINT coords );
or ClientToScreen( <same parameters> );
Oz~
PS:
glOrtho(0, winWidth, winTop, 0, -1, 1);
that should fix it :p
If you want true windows coords, use ScreenToClient( hWnd, POINT coords );
or ClientToScreen( <same parameters> );
Oz~
PS:
glOrtho(0, winWidth, winTop, 0, -1, 1);
that should fix it :p
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement