FTGL rendering problem
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:
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!
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!
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).
In general, FTGL's bitmap fonts are not useful. Outline, Polygon and Texture are (and don't mess with the raster position).
I've tried outline and texture, and it's the same result, so I'm stilling having the same problem.
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.
Hmm, even doing that it still moving aways after the first second of rendering...
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.
The demo app is a working example...
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...
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.
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.
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
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| FTGL Outline Font | choubi | 2 | 3,184 |
Jul 3, 2006 02:48 AM Last Post: choubi |
|
| Is FTGL really that slow ? | quarus | 3 | 3,968 |
May 27, 2006 09:33 AM Last Post: vbuser1338 |
|
| Making A Font With FTGL | Nick | 2 | 3,388 |
Sep 16, 2005 07:15 AM Last Post: Nick |
|
| Compiling FTGL | Nick | 4 | 3,153 |
Sep 8, 2005 08:49 PM Last Post: Nick |
|

