Sign in to follow this  
coolkehon

FTGL (ttf lib) in orthographic projection

Recommended Posts

I'm trying to use the FTGL library in ortho projection because my game is purely 2D but i'm having problems with it. I had a function to make the screen's top left corner 0,0 called enable 2D but when i used it FTGL drew the fonts upside down. So i used a function in FTGL's demo and now it draw's in the center of the screen. I don't understand the projection matrices either so some help would be greatly appreciated.
    glMatrixMode (GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity ();
		gluPerspective(90, (float)GraphicsInstance::SCREEN_WIDTH / (float)GraphicsInstance::SCREEN_HEIGHT, 1, 1000);

    glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glLoadIdentity();
		gluLookAt(0.0, 0.0, (float)GraphicsInstance::SCREEN_HEIGHT / 2.0f, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

float res = (font->Render(text,length,FTPoint(x,y,0))).X();
	
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

Share this post


Link to post
Share on other sites
For startskis you're using a perspective projection and frankly that isn't reconciled readily with the fact that you want an orthographic one (i.e. glOrtho). On flipping your y, just reverse the sense of the 3rd and 4th arguments.

Share this post


Link to post
Share on other sites
i got it fixed :D

i did this

//glEnable2D() called before this. Got it from gamedev.net
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glScalef(1,-1,1);

float res = (font->Render(text,length,FTPoint(x,-(y+abs(font->Descender())),0))).X();

glMatrixMode(GL_MODELVIEW);
glPopMatrix();

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this