-
Displaying text on 2D overlay
Hi,
I'm having a strange problem with my first steps in OpenGL. I have a scene displayed in projected 3D and want to draw overlayed text with texture mapped quads. So I setup a glOrtho projection after the drawing of my 3D parts, but... nothing happens! There is nothing displayed on the screen (only the 3D scene).
My initializiation of the scene looks like this:
---------
glShadeModel(GL_SMOOTH);
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glClearDepth(1.0f);
glEnable(GL_FOG);
glFogi (GL_FOG_MODE, GL_LINEAR);
glFogfv (GL_FOG_COLOR, fogColor);
glHint (GL_FOG_HINT, GL_DONT_CARE);
glFogf (GL_FOG_START, 1.0f);
glFogf (GL_FOG_END, 60.0f);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspectiv (45.0f,640.0f/480.0f,0.1f,60.0f);
glMatrixMode(GL_MODELVIEW);
glEnable (GL_TEXTURE_2D);
glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);
------------
And this is my rendering loop:
------------
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(cam_orientation[0],1.0f,0,0);
glRotatef(360.0f - cam_orientation[1],0,1.0f,0);
glRotatef(cam_orientation[2],0,0,1.0f);
glTranslatef(xtrans, ytrans, ztrans);
glBindTexture(GL_TEXTURE_2D, texture[tnr]);
(... drawing some texture mapped triangles ...)
(... and now, the 2D overlay: This is normally held in an extra function of my font class 
glDisable(GL_DEPTH_TEST);
glPushMatrix();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,640,480,0,-1,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslated(x,y,0);
glBindTexture(GL_TEXTURE_2D, tfont);
glListBase(base-32+(128*set));
glCallLists(strlen(text), GL_BYTE, text);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
-------------
That's all. The code to display the text is exactly the same as in most of the tutorials on the www.
The text is not the problem. ANYTHING I draw onto the Ortho screen isn't displayed!
Can anybody tell me why?
Thanks a LOT for your answers!
Jens Hassler
-
Re: Displaying text on 2D overlay
try disabling all kinds of stuff and then draw something very simple. your code appears to be correct... of course, it's easy to miss something...
try something like
glDisable( GL_TEXTURE_2D );
glDisable( GL_LIGHTING );
glDisable( GL_BLEND );
glDisable( GL_CULL_FACE );
// ...etc.
glBegin( GL_LINES );
glColor3f( 1.0f, 1.0f, 1.0f );
glVertex2f( 0.0f, 0.0f );
glVertex2f( 640.0f, 480.0f );
glEnd();
BTW -- it looks like your dimensions (640x480) are backwards in your glOrtho call. this isn't your problem, but it won't hurt anything to fix it. 
[This message has been edited by phlake (edited 11-28-2000).]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules