PDA

View Full Version : HELP with glPrintf



xLaR8oR
01-04-2004, 05:21 PM
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?

epajarre
01-05-2004, 03:33 PM
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.

xLaR8oR
01-06-2004, 05:55 AM
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.

xLaR8oR
01-06-2004, 05:58 AM
by the way i use bulidfont() in the initGL and the killfont in the desinitializations when i unregister the class.

epajarre
01-08-2004, 11:08 PM
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

Pragma
01-09-2004, 03:25 PM
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.

CPF
02-01-2006, 12:51 PM
Originally posted by epajarre:
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.

EeroI 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...)