FTGL rendering problem

Member
Posts: 312
Joined: 2006.10
Post: #1
Hey, I've trying to render to a NSOpenGLView using FTGL. It renders, but then quickly dissappears, as if it was rendered in my init function (initGL, from unknown's template + some modifications). I even put a glClearColor call before it, and it render before the screen is cleared of that color.... I

Here's the code:
Code:
// I've declared FTFont *font; in the header file of the view and included FTGLBitmapFont.h

// Then in my initGL function
font = new FTGLBitmapFont( "/Users/jeddhaberstro/desktop/annifont.ttf" );
    
if( font->Error() )
{
    fprintf( stderr, "Failed to open font" );
    exit(1);
}
if( !font->FaceSize( 144 ) )
{
    fprintf( stderr, "Failed to set size");
    exit(1);
}

// and in the drawGL method (which is called by the drawRect method
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glColor3f( 1.0, 0.0, 0.0);
//glRasterPos2f( 0, 0 ); If I uncommented this, the text wouldn't appear at all
font->Render( "test" );

Also, It also seems to be moving to right, maybe the screen is translating to the left (I don't call glTranslatef() at all though...)?

Thanks for any help tha is provided! Grin
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
You're correct; the raster pos is updated when you draw the text, and you don't reset it.

In general, FTGL's bitmap fonts are not useful. Outline, Polygon and Texture are (and don't mess with the raster position).
Quote this message in a reply
Member
Posts: 312
Joined: 2006.10
Post: #3
I've tried outline and texture, and it's the same result, so I'm stilling having the same problem.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
You may need to call glPushMatrix and glPopMatrix around drawing Outline and Texture fonts, I suppose. Otherwise, I highly doubt it's "the same" problem, since they're drawn in a completely different manner.
Quote this message in a reply
Member
Posts: 312
Joined: 2006.10
Post: #5
Hmm, even doing that it still moving aways after the first second of rendering...
Quote this message in a reply
Member
Posts: 312
Joined: 2006.10
Post: #6
Can anyone else help me out? I still can't figure it out...
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #7
Look at the FTGL demo app's code. The library works for the demo app, so all you gotta do is figure out what you're doing differently.
Quote this message in a reply
Member
Posts: 312
Joined: 2006.10
Post: #8
I have, nothing works! Do you have a working example I could try?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #9
The demo app is a working example...
Quote this message in a reply
Member
Posts: 312
Joined: 2006.10
Post: #10
There is a lot of extra, unneeded stuff with it though. I'm telling you I've nearly copied it (I took out only the stuff needed for one font [I tried all of them though] ), I can't get it to work...
Quote this message in a reply
Member
Posts: 277
Joined: 2004.10
Post: #11
The Demo example is old... here's my rendering code.

Note, whenever you draw a texture mapped font, it uses gltranslatef, so make sure you call glPushMatrix before a render, and glPopMatrix after.
Code:
FTFont * fpsFont; // my global font variable

void initFonts(void) // my init function, call once or suffer crashes.
{
    fpsFont = new FTGLTextureFont("font.ttf");
    if (!fpsFont->FaceSize(24)) {
        // something went wrong...
        return;
    }
}

void DrawFont(void)
{
    glPushMatrix();
        fpsFont->Render("Hello World");
    glPopMatrix();
}

Make sure to setup your ortho correctly (and translate it correctly)


As OneSadCookie said, Textured, Polygon, and Outline are the best to use. Although outline isn't very useful. Texture mapped is the most accurate and fastest for me.

Your translation is because FTGL uses glTranslate, which in my mind it should either include it's own push and pop of the matrix. Or not use glTranslate at all.

Also, you don't need to include the global path to the font, just the local.

Global warming is caused by hobos and mooses
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  FTGL Outline Font choubi 2 3,695 Jul 3, 2006 02:48 AM
Last Post: choubi
  Is FTGL really that slow ? quarus 3 4,840 May 27, 2006 09:33 AM
Last Post: vbuser1338
  Making A Font With FTGL Nick 2 3,784 Sep 16, 2005 07:15 AM
Last Post: Nick
  Compiling FTGL Nick 4 3,526 Sep 8, 2005 08:49 PM
Last Post: Nick