Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Esap1

OpenGL Disable Z-Buffer in OpenGL?

This topic is 6906 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
I found out it was just glDisable(DEPTH_TEST);, but how do I turn off clipping, Like Near Plane Clipping??

Share this post


Link to post
Share on other sites
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 here
glPopMatrix();
glMatrixMode( GL_MODELVIEW );


-Sirius

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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!