Click to See Complete Forum and Search --> : Problem with GluOrtho and resizing


hannibar
October 12th, 2004, 11:35 AM
I'm having trouble in the program I'm writing. I've written the code to create a window, and a few other functions.

//is called right after the creation of the window
bool init_ogl()
{
glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0,0,800,600);
gluOrtho2D(0, 800, 600, 0);
return true;
}

//is called after resizing the window
//x and y are the width and height of the window.
void resize_scene(float x, float y)
{
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0,0,int(x),int(y));
gluOrtho2D(0,x,y,0);
draw_scene();
}
This works very well when I don't write the "gluOrtho2D(0,x,y,0)" in resize_scene(). But the problem then is that after resizing everything is resized inside the window too. I can't for example say : draw a square of 50 by 50 pixels. It will be either larger or smaller. except when it is default sized.

When I call "gluOrtho2D(0,x,y,0)" in resize_scene() however, the screen is all red. (the clearing color).

Is it impossible to call gluOrthon2D() twice?

Bornish
October 12th, 2004, 11:50 AM
Replace with://is called right after the creation of the window
bool init_ogl()
{
glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0,0,800,600);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 800, 600, 0);
return true;
}

//is called after resizing the window
//x and y are the width and height of the window.
void resize_scene(float x, float y)
{
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0,0,int(x),int(y));
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,x,y,0);
draw_scene();
}You have to do so, because "The current matrix is multiplied by this matrix with the result replacing the current matrix. That is, if M is the current matrix and O is the ortho matrix, then M is replaced with M • O".
Best regards,