Disable Z-Buffer in OpenGL?

Started by
8 comments, last by Esap1 23 years, 11 months ago
Im want to disable the Z-Buffer before I draw TEXT then Enable it again after, it is a slow proccess if done every frame?, and how do you do it?
Advertisement
I found out it was just glDisable(DEPTH_TEST);, but how do I turn off clipping, Like Near Plane Clipping??
You don''t have to disable anything to do text.
glMatrixMode( GL_PROJECTION );glPushMatrix();glLoadIdentity();glRasterPos2f( x, y ); //gl coords, not screen//do font stuff hereglPopMatrix();glMatrixMode( GL_MODELVIEW ); 


-Sirius

Confucius say: Do not disturb sleeping dragon, for you are crunchy
and will taste good with ketchup.
Confucius say: Do not disturb sleeping dragon, for you are crunchyand will taste good with ketchup.
When I do that none of the text shows up, Im new to OpenGL, and I just dont get it. Could anyone point me to a console tutorial, or got some code, or know how to write text over 3d objects, thanks alot.
Im using Nehe''s Bitmap Font Code, does that change anything?
Well, if you don't mind using the Windows functions,
GLuint FontCreateBitmaps( HDC hdc, char *typeface,      int height, int weight, DWORD italic )   {   GLuint base;   HFONT font;   if (( base = glGenLists( 96 )) == 0 )   	return 0;   if ( stricmp( typeface, "symbol" ) == 0 )   	font = CreateFont( height, 0, 0, 0, weight, italic, FALSE, FALSE, SYMBOL_CHARSET,              OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DRAFT_QUALITY, DEFAULT_PITCH, typeface );   else   	font = CreateFont( height, 0, 0, 0, weight, italic, FALSE, FALSE, ANSI_CHARSET,              OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DRAFT_QUALITY, DEFAULT_PITCH, typeface );   SelectObject( hdc, font );   wglUseFontBitmaps( hdc, 32, 96, base );   DeleteObject( font );   return base;   }void FontDelete( GLuint font )   {   if ( font == 0 )      return;   glDeleteLists( font, 96 );   }void FontPuts( GLuint font, char *s )   {   if ( font == 0 )      return;   glPushAttrib( GL_LIST_BIT );   glListBase( font - 32 );   glCallLists( strlen( s ), GL_UNSIGNED_BYTE, s );   glPopAttrib();   }   

Make sure you have your rendering context set up before you call these. wglUseFontBitmaps basically creates a series of display lists, each of which corresponds to a letter or symbol. The GLuint that FontCreateBitmaps returns refers to the start of the series. Once you have the font set up, you can use the code in my last post. Set the location with glRasterPos2f and draw text with FontPuts. I hope that helps!

-Sirius

Confucius say: Do not disturb sleeping dragon, for you are crunchy
and will taste good with ketchup.

Edited by - Sirius on May 15, 2000 9:15:30 PM

Edited by - Sirius on May 15, 2000 9:18:25 PM
Confucius say: Do not disturb sleeping dragon, for you are crunchyand will taste good with ketchup.
When I use the code, it does the same thing as Nehe''s code, nothing. The Only way I can figure out how to make the text on the screen is by going:

glLoadIdentity();
glTranslatef(0.0f,0.0f,-0.1f);
glRasterPos2f( 0.0, 0.0 ); //gl coords, not screen
FontPuts("HI");
, Yet it is behind the objects, and is hard to tell coords, and the relation to the screen. Please Enlighten Me.

Hi,

You have to set your Projection Matrix correctly... do the following:

glMatrixMode(GL_PROJECTION);
glLoadIdentity;
gluOrtho2D(0, WINDOW_WIDTH, WINDOW_HEIGHT, 0);
(* with gluOrtho2D, you will set an orthografic projection, and all coordinates will be in window coordinates...*)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
glRasterPos2i(X, Y); // the x and y are in window coordinates
DrawText("Blah");


You might want to disable lighting too, since you probably don''t want your text lit... use glDisable(GL_LIGHTING) before glRasterPos2i, and enable it again after drawing your text.
I think that will solve your problem.

Hope that helps,
Nicodemus.
Nicodemus.----"When everything goes well, something will go wrong." - Murphy
FINALLY, Thank You, I got it to work. I have to Calculate the 3D Projection Matrix back every frame though, is it that slow?, this:

glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW); glLoadIdentity();

Is there a way I can save the Perspective Matrix, then just Switch to it, So it doesnt have to be calculated every frame. Or is there another way? Thanks Again Nicodemus, and others who posted
Hi again,

Yes Esap1, you can save your projection Matrix... in your initialization code, set it as usual, and after that:


GLfloat ProjMatrix[16]; // must be a global variable
glGetFloatv(GL_PROJECTION_MATRIX, *ProjMatrix);


Using glGet*, you can retrieve every (well, if I''m not wrong ) OpenGL state, but it''s SLOW, because the data must be retrieved from the card... don''t do it every frame!
Now, every time you want to setup that Projection again, you do:


glMatrixMode(GL_PROJECTION);
glLoadMatrixf(*ProjMatrix);


Other way to do it is using glPushMatrix and glPopMatrix, like this:


glMatrixMode(GL_PROJECTION);
glPushMatrix; // saves the current matrix into the matrix stack
glLoadIdentity;
gluOrtho2D(...);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
glRasterPos2i(...);
DrawText(...);

glMatrixMode(GL_PROJECTION);
glPopMatrix; // restores the last matrix saved
glMatrixMode(GL_MODELVIEW);


But I think you can just calculate the matrix every frame, because it''s a cheap operation anyway. Between the two methods, I choose the 2nd thought, because it''s cleaner in my opinion.

Hope that helps.

Nicodemus.

----
"When everything goes well, something will go wrong." - Murphy
Nicodemus.----"When everything goes well, something will go wrong." - Murphy

This topic is closed to new replies.

Advertisement