Jump to content
  • Advertisement
Sign in to follow this  
arbuckle911

stupid ortho problem

This topic is 3997 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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);

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!