Sign in to follow this  
luckystar78

OpenGL OpenGL 3.0 and Fonts / GLUT, Gltools and Superbible 5.th

Recommended Posts

Hi all,

Since I am migrating my old code which I wrote with the fixed function pipline of OpenGL to OpenGL 3.0, all the fixed functions are gone. That is good and bad. I am using the (GL) Tools from the Superbible 5.th so that I don't have to write everything from the ground up. Everything worked out well until now. Now I would like to display 2D text on the screen (simple test output like FPS, time left, ...) and I am kind of stuck. With the fixed functions pipeline I wrote the following routines:

[code]void setOrthographicProjection() {
// switch to projection mode
glMatrixMode(GL_PROJECTION);
// save previous matrix which contains the
//settings for the perspective projection
glPushMatrix();
// reset matrix
glLoadIdentity();
// set a 2D orthographic projection
gluOrtho2D(0, WIDTH, 0, HEIGHT);
// invert the y axis, down is positive
glScalef(1, -1, 1);
// mover the origin from the bottom left corner
// to the upper left corner
glTranslatef(0, -HEIGHT, 0);
glMatrixMode(GL_MODELVIEW);
}

void resetPerspectiveProjection() {
// set the current matrix to GL_PROJECTION
glMatrixMode(GL_PROJECTION);
// restore previous settings
glPopMatrix();
// get back to GL_MODELVIEW matrix
glMatrixMode(GL_MODELVIEW);
}

void renderBitmapString(float x, float y, void *font2,char *string)
{ char *c;
glRasterPos2f(x, y);// set position to start drawing fonts
// loop all the characters in the string
for (c=string; *c != '\0'; c++) {
glutBitmapCharacter(font2, *c);
}
}

void text_out(int text[2],char* string) {
bool status = glIsEnabled(GL_LIGHTING);
if (status) { glDisable(GL_LIGHTING); }
glDisable(GL_TEXTURE_2D);
glColor3f(1.0f,1.0f,1.0f);
setOrthographicProjection();
glPushMatrix();
glLoadIdentity();
renderBitmapString(text[0],text[1],(void *)font2,string);
glPopMatrix();
resetPerspectiveProjection();
if (status) { glEnable(GL_LIGHTING); }
text[1] += pos_increment;
}[/code]

which worked. In the OpenGL superbible 5.th the GLSL shader language is introduced, the stock shaders which come with the book are called like this:

shaderManager.InitializeStockShaders();
shaderManager.UseStockShader(GLT_SHADER_FLAT,transformPipeline.GetModelViewProjectionMatrix(),triangle_color);

When I use my old routines with this new setup, I can see the text output on the screen for 1/2 sec and then it vanishes. I remembered: When I was still using the fixed function pipeline, the same happend until I turned off the Lightning before I rendered the Bitmap string:

[code] bool status = glIsEnabled(GL_LIGHTING);
if (status) { glDisable(GL_LIGHTING); } [/code]

Now I am wondering how I can do this as the fixed functions are gone and this approach does not work with the new Stock shaders...

Thanks for your help.

Share this post


Link to post
Share on other sites
[quote name='alligevel' timestamp='1312874911' post='4846570']
In the OpenGL superbible 5.th the GLSL shader language is introduced, the stock shaders which come with the book are called like this:

shaderManager.InitializeStockShaders();
shaderManager.UseStockShader(GLT_SHADER_FLAT,transformPipeline.GetModelViewProjectionMatrix(),triangle_color);

When I use my old routines with this new setup, I can see the text output on the screen for 1/2 sec and then it vanishes. I remembered: When I was still using the fixed function pipeline, the same happend until I turned off the Lightning before I rendered the Bitmap string:

[code] bool status = glIsEnabled(GL_LIGHTING);
if (status) { glDisable(GL_LIGHTING); } [/code]

Now I am wondering how I can do this as the fixed functions are gone and this approach does not work with the new Stock shaders...
[/quote]
If you are using forward compatibility mode, then the lighting is calculated in the shaders, which takes place after you've submitted geometry for rendering; so I don't understand why you'd need to disable the lighting to get it to work. You can disable lighting by having the application pass a uniform variable to the shader that can be checked with an if statement right before the light computation. For debugging purposes, you could create a "dummy" shader pair that does nothing but pass unaltered geometry and sets everything to one solid color, say red. If that works fine, then you know there is something wrong with the lighting shader otherwise the problem is in the application.

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