Sign in to follow this  
chilun

glortho function - assistance required...

Recommended Posts

chilun    122

Hi all;

 

I have some trouble with trying to use the glOrtho function to scale some graphics to a window (height - 500, width - 500).

I've created a function called reshape to do this, but for some reason I think my numbers are off as the graphics are scaling to the size I would like, but for some reason it is only scaling into the top-left hand corner of the window - I want to make sure that the scaling fills the entire size of the window. Can anyone provide any tips on what I can do?

 

Thank you

...void reshape(int w, int h)
{
glViewport(0,0, w, h);
GLfloat aspect = (GLfloat)w / (GLfloat) h;
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, w, h, 0.0f, 0.0f, 1.0f);
}
...


int main (int argc, char **argv)
{

...
glutInitWindowSize(500, 500);
glutReshapeFunc(reshape);
...
}

Share this post


Link to post
Share on other sites

Try:

 

GLfloat x = w / 2;
GLfloat y = h / 2;
glOrtho(-x, x, -y, y, -1.0f, 1.0f);

 

Scaling the projection matrix will scale everything in the scene. If you just want to scale a specific object, you should do so by scaling its world transform matrix.

 

... Is the example small enough to post somewhere? That would help.

Share this post


Link to post
Share on other sites
chilun    122

Hi Goran;

 

I'll definitely try what you suggested and will come back to you with a response.

 

Thank you very much indeed :)

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