I am trying to make an equivalent of a printf() implementation so that OpenGL will print in the lower, left-hand corner, but for some reason it will only print the last function I send to it.
Only the "CamPos: (0.00, 0.00, 0.00)" is printed, but it is printed 3 times. I have two functions, one is GLOUT, which is supposed to take the text, put the numbers into the string, and save it in TextHolder[], and DrawDebigInfo() which is called once at the end of every frame.
char text[256];
char * TextHolder[16];
staticint DebugNum = 0;
void GLOUT(constchar * fmt, ...){
va_list ap; // Pointer To List Of Arguments
va_start(ap, fmt); // Parses The String For Variables
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
va_end(ap); // Results Are Stored In Text
TextHolder[DebugNum] = text;
DebugNum++;
}
void DrawDebugInfo(){
float xLocation = -14;
float yLocation = -8;
for (int i = 0; TextHolder[i] != 0; i++){
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glDisable(GL_TEXTURE_2D);
glLoadIdentity();
glTranslatef(0,0,-.002);
glColor3f(1,1,1);
glRasterPos2f(xLocation/10000, (yLocation+i)/10000);
glPopMatrix();
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(base - 32); // Sets The Base Character to 32
glCallLists(strlen(TextHolder[i]), GL_UNSIGNED_BYTE, TextHolder[i]); // Draws The Display List Text
glPopAttrib(); // Pops The Display List Bits
}
DebugNum = 0;
}
You are using the same string (text) each time GLOUT is called.
TextHolder[0], TextHolder[1], and TextHolder[2] all point to the same string data: 'text' which was most recently overwritten with the camera position.
If you want to save the string data, use a string.
Also I'm not sure how your drawing code is even working. AFAIK you can't pass a char* to glCallLists and just expect it to print a string.
1 2 3 4 5 6 7
string TextHolder[16]; // <- make it a string
void GLOUT(constchar * fmt, ...){
// ...
TextHolder[DebugNum] = text; // <- now this will actually copy of the string
}
You can then use TextHolder[i].length() instead of strlen... and if you still need a char* for whatever reason you can use TextHolder[i].c_str(), but again I'm really confused as to how you're drawing.