Jump to content
  • Advertisement
Sign in to follow this  

OpenGL MS Paint effect in resizing the screen?

This topic is 4863 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 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
Sign in to follow this  

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!