MS Paint effect in resizing the screen?

Started by
0 comments, last by Falken42 18 years, 5 months ago
I have made a basic paint application with Opengl using Glut I want the screen to resize just like MS Paint. That means the top left hand corner stays where it is when a resize happens. So the camera stays where it is, and only the right or bottom edges move. Heres what happens when I resize the screen: before resize Now i resize a little, but it moves the camera to the center of the image after resize :(, i want the squigly box to start in the top left hand corner This is what I want to happen: This is what I want to happen! (I made this picture in MS paint) Here is the code for my resize:
void changeSize(int w, int h)
{
	glViewport(0, 0, w, h);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    
	halfw = w / 2;
	halfh = h / 2;

	glOrtho(-halfw,halfw,-halfh,halfh,-1.0,1.0);
}




What do I need to change in glViewport or glOrtho to get this to happen?
Advertisement
The parameters you are passing to your glOrtho call cause OpenGL's projection matrix to be initialized with the origin (0, 0) at the center of the screen. This is why when you resize, the image is centered in the middle.

If you set your ortho matrix to be aligned to (0, 0) rather than (-halfw, -halfh), it should work.

Try this:
glOrtho(0, w, 0, h, -1.0, 1.0);

This topic is closed to new replies.

Advertisement