# Opengl font

This topic is 4819 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Could someone recommend a good and FAST opengl font library. I've been busting my hump for the past 3 days with no luck. I finally got one to work called gltext but after drawing enough objects, performance really drops. When I used SDL_TTF and blit surfaces, there was barely a drop at all. I could handle over 20 text surfaces on the screen at once with no problem. Now that I've made the switch to OpenGL, I can't handle five. I really need help. I'm desperate [bawling]!!

##### Share on other sites
You can still use SDL_TTF and blit surfaces with OpenGL! You can use SDL_Surface* with any gl functions that require a GLvoid* pixels parameter. I wish I had some code to give you but it is at home. You can check out the SDL port of NeHe lesson 6 to see how to texture map with SDL_Surfaces - and build off that.

I don't know if this will work if you're not already using SDL to setup OpenGL. Hope this helps!

##### Share on other sites
I forgot to add that I'm using windows [embarrass] (Unless there's some sort of program that opens tar.gz programs), but thanks!

##### Share on other sites
Winzip will open .tar.gz

##### Share on other sites
And if you don't have WinZip and only have the default windows zip access, here it is in .zip format.

By the way, I think you should definitly have a look at this thread [wink]

##### Share on other sites
Well it looks like a lot to work with for someone like me but I'll see what I can do. Thanks! But are you sure I can get my text blitting speed back?

EDIT: And as to this link, I got the first part but rendering was slow and I was completely baffled on the FontMGR library.

##### Share on other sites
Arggg!! I'm still lost!!! Am I supposed to convert the sdl surface to a texture surface then draw it ( That was slow the last time I've done it). Am I supposed to somehow get the text to go straight to a surface? Am I supposed to load the surface once and somehow draw the characters in parts (clueless as how to do that?). Any info at all would be much obliged.

##### Share on other sites
I like BMF_font, but I have no idea about its speed compared to other libs.

##### Share on other sites
The simplest and fastes way is this. You could use SDL to generate the font bitmap though.

edit: this wasn't what I thought it was... So here some code I use. (be warned of the ugglynes ;)

void glPrint(GLint x, GLint y, int set, const char *fmt, ...) {        char     text[1024];        va_list ap;        GLuint err;        if (fmt == NULL)                return;        va_start(ap, fmt);                vsprintf(text, fmt, ap);        va_end(ap);        if (set > 1)                set = 1;        glPushAttrib(GL_ALL_ATTRIB_BITS);        glDisable(GL_DEPTH_TEST);        glDisable(GL_LIGHTING);        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);        glEnable(GL_BLEND);        glEnable(GL_TEXTURE_2D);        glAlphaFunc ( GL_GREATER, 0.1f ) ;        glEnable ( GL_ALPHA_TEST ) ;        glMatrixMode(GL_PROJECTION);        glPushMatrix();        glLoadIdentity();        /*you have to change this to match your settings*/        glOrtho(0, 1600, 0, 1200, -1, 1);         glMatrixMode(GL_MODELVIEW);        glPushMatrix();        glLoadIdentity();        glTranslated(x,y,0);        glListBase(font_base-32+(128*set));        glScalef(1.0f,-1.0f,1.0f);        glBindTexture(GL_TEXTURE_2D, font_texture[0]);        glCallLists(strlen(text),GL_UNSIGNED_BYTE, text);        glPopMatrix();        glMatrixMode(GL_PROJECTION);        glPopMatrix();        glPopAttrib();        glMatrixMode(GL_PROJECTION);}void build_font() {        int loop;        float cx, cy;        printf("loading font...\n");        font_texture[0] = load_texture_tga(TEXTURE_FONT);        if (font_texture[0]) {                font_base = glGenLists(256);                for (loop = 0; loop < 256; loop++) {                        cx = (float)(loop % 16)/16.0f;                        cy = (float)(loop / 16)/16.0f;                        glNewList(font_base+loop, GL_COMPILE);                                glBegin(GL_QUADS);                                        glColor3f(0.0f,1.0f,0.0f);                                        glTexCoord2f(cx,cy+0.0625f);                                        glVertex2d(0,16);                                        glTexCoord2f(cx+0.0625f,cy+0.0625f);                                        glVertex2d(16,16);                                        glTexCoord2f(cx+0.0625f,cy+0.001f);                                        glVertex2d(16,0);                                        glTexCoord2f(cx,cy+0.001);                                        glVertex2d(0,0);                                glEnd();                                glTranslated(9,0,0);                        glEndList();                }        } else {                printf("Error: font\n");        }}

[Edited by - nefthy on June 2, 2005 10:41:24 AM]

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 16
• 12
• 20
• 12
• 14
• ### Forum Statistics

• Total Topics
632155
• Total Posts
3004477

×