HELP with glPrintf

hi ppl ! i’m using the glPrintf code of nehe… but when i for example output this glPrintf(100,100,“My name is %s and i’m %d years old and i live in %s”,Me.Name,Me.Age,Me.Location); it cuts 500 fps from my program. i have a clean opengl app and it gives me 2000 fps and if i output that the fps drops to 1500 or 1400 fps. That can’t be normal, because i think this is the way Game Programmers use to output Text. Can anyone help me?

Could you be more specific in what you mean by NeHe glprintf? His site includes several font tutorials, and some of them will provide relatively slow printing.

Also can you check the printing with some real graphics on screen? Comparing 2000 fps to 1500 fps might get you into some benchmarking errors.

GLvoid BuildFont(GLvoid)
{
HFONT font;
HFONT oldfont;

base = glGenLists(96);	

font = CreateFont(	16,							// Height Of Font
					0,								// Width Of Font
					0,								// Angle Of Escapement
					0,								// Orientation Angle
					FW_BOLD,						// Font Weight
					FALSE,							// Italic
					FALSE,							// Underline
					FALSE,							// Strikeout
					ANSI_CHARSET,					// Character Set Identifier
					OUT_TT_PRECIS,					// Output Precision
					CLIP_DEFAULT_PRECIS,			// Clipping Precision
					ANTIALIASED_QUALITY,			// Output Quality
					FF_DONTCARE|DEFAULT_PITCH,		// Family And Pitch
					"Courier New");					// Font Name

oldfont = (HFONT)SelectObject(hDC, font);
wglUseFontBitmaps(hDC, 32, 96, base);	
SelectObject(hDC, oldfont);				
DeleteObject(font);						

}

GLvoid KillFont(GLvoid)
{
glDeleteLists(base, 96);
}

GLvoid glPrintf(float x,float y,float redcolor,float greencolor,float bluecolor,const char *fmt, …)
{
SetOrthoView(GameResX,GameResY);
char text[256];
va_list ap;

if (fmt == NULL)
{
	return;											
}
glColor3f(redcolor,greencolor,bluecolor);
glRasterPos2f(x,y);
va_start(ap, fmt);									
    vsprintf(text, fmt, ap);						
va_end(ap);											

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

}

My printf has a a few changes in the paramaters but it is only for color… i already tryed with the pure
Nehe Font Code and it does the same problem. I’m writing the glPrintf with 2 projections at the same time. The perspective has a plane with a moving Texture (to give the feeling that we are walking) and in the ortho i have the text outputing that.

by the way i use bulidfont() in the initGL and the killfont in the desinitializations when i unregister the class.

Ok,

So you end up using glBitmap for each of your
characters. You almost certainly get better performance if you render each character with a texture maaped quad. Especially if you can pack all your characters into a single texture.

The NeHe tutorial 17 seems to demo something like that. (I have not tried running it myself).

All the NeHe tutorialas seem to use one display list for each character. I myself push my text quads to OpenGL directly with vertex arrays or by using a single glBegin(GL_QUADS)/glEnd() pair in my glprint" function.

Eero

This may be obvious to everyone, but it is worth considering that dropping 500 fps is relative. Going from 2000-1500 fps means you are spending 1/6000 of a second per frame. If your app were running at 30 fps without text, it would drop to 29.85 fps with text. While faster is always better, I personally wouldn’t spend too much time optimizing something that takes a 6000th of a second to get that extra 0.15 fps until I had optimized absolutely everything else.

Originally posted by epajarre:
[b]Ok,

So you end up using glBitmap for each of your
characters. You almost certainly get better performance if you render each character with a texture maaped quad. Especially if you can pack all your characters into a single texture.

The NeHe tutorial 17 seems to demo something like that. (I have not tried running it myself).

All the NeHe tutorialas seem to use one display list for each character. I myself push my text quads to OpenGL directly with vertex arrays or by using a single glBegin(GL_QUADS)/glEnd() pair in my glprint" function.

Eero[/b]

I am having the same problem, and read your solution, yet I do not understand, can you explain your “glBegin(GL_QUADS)/glEnd()” thing?? (I am relative new to openGL, with exp. of DirectX though…)

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.