glutSwapBuffers() is usually the second last command in a display function, right before glutPostRedisplay() when double buffering.
Here's a function I use with glut for printing text messages:
Code:
void messg2screen (int pos, char *messg, const float fg[3]) {
int i, x, y, len = strlen(messg);
float bg[3];
switch (pos) {
case (TXTBLEFT):
x = 10;
y = 10;
break;
case (TXTBRIGHT):
x = Config.wid-12*strlen(messg)-10;
y = 10;
break;
case (TXTBCENTER):
x = Config.wid/2-12*strlen(messg)/2;
y = 10;
break;
case (TXTCENTER):
x = Config.wid/2-12*(strlen(messg)/2);
y = Config.high/2-12;
break;
case (TXTTCENTER):
x = Config.wid/2-12*(strlen(messg)/2);
y = Config.high-20;
default: break;
}
for (i=0;i<3;i++) bg[i] = 1.0f-fg[i];
glColor4f(bg[0],bg[1],bg[1],1.0f);
glWindowPos2i(x,y);
for (i=0; i<len; i++) glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,messg[i]);
glColor4f(fg[0],fg[1],fg[2],1.0f);
glWindowPos2i(x+2,y+2);
for (i=0; i<len; i++) glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,messg[i]);
}
This creates an inverse colored shadow so that it stands out regardless of the background. The predefined global enum for the switch/case is:
Code:
enum {
TXTBLEFT,
TXTBRIGHT,
TXTBCENTER,
TXTCENTER,
TXTTCENTER
};