I'm trying to display text on the screen, but my worst nightmare happens: the program compiles, no errors, but nothing happens when I run the program. All I get is a black screen.
I wrote the code so that I code write text onto the screen by simply doing
Code:
glPrint("Hello World %2.2f", float_var);
It's supposed to parse strings just like a real printf() would do.
This is the code I'm using:
Code:
// this selects the current font to be used in drawing
void buildfont() {
base = glGenLists(96); // storage for 96 charecters
aglUseFont(aglGetCurrentContext(),
kFontIDMonaco, // Choose your font. These are listed in Fonts.h,
// or use GetFNum() toolbox function.
bold, // Style, Also in Fonts.h
24, // 12 point
32, // start at 32 ...
96, // go for 96 characters ...
base);
}
// supposed to look like an "official" opengl function :)
void glPrint(const char *fmt, ...) {
char text[256]; // holds the string
va_list ap; // pointer to list of arguments
if (fmt == NULL) // make sure there is text here
return;
va_start(ap, fmt); // parses the string for variables
vsprintf(text, fmt, ap); // convert the symbols into actual numbers
va_end(ap); // results are stored in text
glPushAttrib(GL_LIST_BIT); // pushes the display list bits
glListBase(base-32); // sets the base charecter to 32
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // draws the display list text
glPopAttrib(); // pops the display list bits back to the way it was before
}
Does the problem lie within the Apple specific code, agl? Or am I doing something wrong with GLUT?