PDA

View Full Version : Problem with text rendered



openujs
10-12-2006, 04:40 AM
I have following codes to render text to display FPS and other information. I am calling DrawText() in main display loop. Problem is-the text flickers, means it is rendered once then it doesnot , and again it does. I usually see that if i am moving model object or camera. but model object is rendered at all times-no problem there.

char text[256];
va_list args;

if( base==0 || str == NULL ){
return;
}
va_start(args, str);
vsprintf(text, str, args);
va_end(args);

glRasterPos3f(x, y, z);

glPushAttrib(GL_LIST_BIT);
glListBase(base - 32);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();

10-13-2006, 06:38 PM
Hi


hmmm., try putting :

glRasterPos2f instead of 3f and render it every frame in 2d orthographic projection mode:

glColor4f(1.0f, 0.0f,0.0f, 1.0f); // Red text
glRasterPos2f ( (width/screenCenter),(height/screenCenter) );
glPrint("hello World" ) ;

make sure yu go back to perspective view before rendering 3d models and re establish whatever states yu had to turn off to get into ortho 2d mode.


Ref

dorbie
10-16-2006, 09:04 PM
There are also many other things that might affect your text. OpenGL is a state machine so the state of the last thing you drew is used for the next thing with any incremental modifications you make betwen the two applied. This goes for EVERYTHING, including matrices etc. So for example you may want to glDisable texture and other state, you'll have to figure out how much stuff you want/need to initialize, it can be quite heavyweight.