stupid ortho problem

Started by
1 comment, last by arbuckle911 16 years, 8 months ago
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.
Advertisement
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);

Best Regards,KumGame07
If I do that the pixel stays at the same place when I scale Y. I would have expected it to stay 10 pixels from the bottom no matter what.

This topic is closed to new replies.

Advertisement