Sign in to follow this  
arbuckle911

stupid ortho problem

Recommended Posts

I'm trying to setup a ortho projection. The problem is that with the code below when I resize the y component of the window a point drawn at 10,10 moves in the opposite direction of the resize. the x resizes have no effect on the raster position of 10,10 in world coords. I'll post all the resize and drawing code here:

void Application::Resize(int width, int height) 
{
    Application::height = height;
    Application::width = width;
    Application::halfHeight = height/2;
    Application::halfWidth = width/2;
    
    if(height == 0)
    {
        height = 1;
	halfHeight = 1;
    }
    
    glViewport(0,0,width,height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0f,width,height,0,-1.0f,1.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();	
}

void Application::Render() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    glBegin(GL_POINTS);
	glVertex2d(10.0, 10.0);
    glEnd();
    
    glFlush();
}


the initial window setup works fine until the y component of the window is changed, then the point is no longer at 10,10 pixels from the top left.

Share this post


Link to post
Share on other sites
The window coordinates in OpenGL have origin in "bottom-left" not in "top-left".

So change the parameters to 'glOrtho()' as follows

glOrtho(0.0f,width,0,height,-1.0f,1.0f);

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