Sign in to follow this  
Kincaid

Ortho Troubles

Recommended Posts

I'm trying to display fonts in my scene. this is the code i use void setOrthographicProjection() { glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); // set a 2D orthographic projection glOrtho(0, 800, 600, 0, -1, 1); // invert the y axis, down is positive glScalef(1, -1, 1); // mover the origin from the bottom left corner // to the upper left corner //glTranslatef(0, -600, 0); glMatrixMode(GL_MODELVIEW); } void resetPerspectiveProjection() { glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); } void RENDERSCENE() { .... do the scene as usual ...... setOrthographicProjection(); glPushMatrix(); glLoadIdentity(); PrintTXT("TESTING"); glPopMatrix(); resetPerspectiveProjection(); } But the text just shoots through the screen once from the left bottom corner to the right... Does anyone know whats going on here. Tried gluOrtho en gluOrtho2d, works the same it seems. Guess it's not a translatef which is summated. And it doesn't seem that the pushes and pops miss eachother somewhere...

Share this post


Link to post
Share on other sites
By the way,
this is my PrintTXT function.

It works, in the sense that i can display text correctly,
but i cant seem to display it in the correct place yet

void PrintTXT (const char *fmt, ...)
{
char text[256]; // Holds Our String
va_list ap; // Pointer To List Of Arguments

if (fmt == NULL) // If There's No Text
return; // Do Nothing

va_start(ap, fmt); // Parses The String For Variables
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
va_end(ap); // Results Are Stored In Text

glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(base - 32); // Sets The Base Character to 32
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text
glPopAttrib(); // Pops The Display List Bits
}

Share this post


Link to post
Share on other sites
Bitmap fonts? You aren't setting the raster position. Check out glRasterPos* functions.
Quote:
// set a 2D orthographic projection
glOrtho(0, 800, 600, 0, -1, 1);
// invert the y axis, down is positive
glScalef(1, -1, 1);
That looks weird, you set up your orthographic projection with bottom=600 and top=0 (positive going down) and than invert the y-axis so that... down is positive?

Share this post


Link to post
Share on other sites
most part of the code is what i got from internet.
Tried Raster2D but also couldn't get the text in place. When moving through my 3d landscape, the text in 2d also moved every which way.

Why they scale it, i also dont know, cause i dont really yet get how the projection mode en orthomode function to set up a proper 2d window over the 2d scene...
Guess its because coordinate system may function in a top down positive manner..

But what should I do with raster2d to make it work properly ??
And why is the text flying through the screen once ??

Share this post


Link to post
Share on other sites
Ok, got it to work by accident by toying with the commands
But still got the problem that the text dissappears when i translate in the 3d scene. Rotations go fine...

void setOrthographicProjection()
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0f, 800.0f, 600.0f, 0.0f, -1.0f, 1.0f);
}

void resetPerspectiveProjection()
{
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}

void RENDERSCENE()
{
setOrthographicProjection();
glPushMatrix();
glLoadIdentity();
glRasterPos2f(0,0);
PrintTXT("TEST" );
glPopMatrix();
resetPerspectiveProjection();
}

(wondering whether i posted my quesiton a little to early :S ...)

Share this post


Link to post
Share on other sites
Quote:
Original post by Kincaid
But what should I do with raster2d to make it work properly ??
And why is the text flying through the screen once ??
Because when you render bitmap fonts it renders at the current raster position and then sets the raster position to the correct position for the next character. And since you don't change the raster position, it gets set to right after the last character each frame, then renders from there on the next frame. So call glRasterPos* before PrintTXT. Assuming you want to render the string "TESTING" at (25, 50) you would do something similar to this...
void RENDERSCENE()
{
.... do the scene as usual ......
setOrthographicProjection();
glPushMatrix();
glLoadIdentity();
glRasterPos2f(25.0f, 50.0f);
PrintTXT("TESTING");
glPopMatrix();
resetPerspectiveProjection();
}


EDIT: Nevermind. [grin] Congrats and good luck with your future programming.

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