Sign in to follow this  

OpenGL MS Paint effect in resizing the screen?

Recommended Posts

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

	halfw = w / 2;
	halfh = h / 2;


What do I need to change in glViewport or glOrtho to get this to happen?

Share this post

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

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