Hello everbody!
I have a problem with opengl fonts in my QGLWidget:
I have many different objects such as polygons, lines … which i can paint to my widget. The Problem is with my TextObject.
When i set my Text, i would make a Init which looks as ( please have a look down this page). And when a make this procedure, there is nothing in the widget, also the graphic objects i drew would dissapear, please help me :
int TextObj::InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
glEnable(GL_LIGHT0); // Enable Default Light (Quick And Dirty) ( NEW )
glEnable(GL_LIGHTING); // Enable Lighting ( NEW )
glEnable(GL_COLOR_MATERIAL); // Enable Coloring Of Material ( NEW )
BuildFont(); // Build The Font ( ADD )
return TRUE; // Initialization Went OK
}
GLvoid TextObj::glPrint(const char *fmt, …) // Custom GL “Print” Routine
{
float length=0; // Used To Find The Length Of The Text
char text[256]; // Holds Our String
va_list ap; // Pointer To List Of Arguments
if (fmt == NULL) // If There's No Text
return; // Do Nothing
va_start(ap, fmt); // Parses The String For Variables
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
va_end(ap);
for (unsigned int loop=0;loop<(strlen(text));loop++) // Loop To Find Text Length
{
length+=_gmf[text[loop]].gmfCellIncX; // Increase Length By Each Characters Width
}
// glTranslatef(-length/2,0.0f,0.0f); // Center Our Text On The Screen
glTranslatef((float)(_pointX/_videoSizeX),(float)(_videoSizeY-_pointY/_videoSizeY),1-((GetZCoord())/*+(float)1/(1024*1024)*/) );
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(_base); // Sets The Base Character to 0
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text
glPopAttrib(); // Pops The Display List Bits
}
and if i want do draw my text i made an new function which looks as:
GLvoid TextObj::glPrint(const char *fmt, …) // Custom GL “Print” Routine
{
float length=0; // Used To Find The Length Of The Text
char text[256]; // Holds Our String
va_list ap; // Pointer To List Of Arguments
if (fmt == NULL) // If There's No Text
return; // Do Nothing
va_start(ap, fmt); // Parses The String For Variables
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
va_end(ap);
for (unsigned int loop=0;loop<(strlen(text));loop++) // Loop To Find Text Length
{
length+=_gmf[text[loop]].gmfCellIncX; // Increase Length By Each Characters Width
}
// glTranslatef(-length/2,0.0f,0.0f); // Center Our Text On The Screen
glTranslatef((float)(_pointX/_videoSizeX),(float)(_videoSizeY-_pointY/_videoSizeY),1-((GetZCoord())/*+(float)1/(1024*1024)*/) );
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(_base); // Sets The Base Character to 0
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text
glPopAttrib(); // Pops The Display List Bits
}
thank you very much for making a look on this,
Andi
[This message has been edited by Andreas.Kriechbaum (edited 10-28-2003).]