OpenGL Tutorials


Window Resizing

Tutorials > OpenGL > Window Resizing

View Full Source


Window Resizing You may have noticed that when you resize the window, the shape does not resize with it.

This tutorial will show you how to change the view of the window so that no matter what size the window is, you will still be able to see everything on the screen and every object will resize accordingly.

Contents of main.cpp :

In this tutorial, we finally make use of the resize function. This is because we want to change the properties of the projection matrix every time the window is resized.

This code is exactly the same as the previous tutorial, except that the changed width and height are passed to the glViewport function. The same values are passed to gluOrtho2D resulting in the same image, but simply larger.

void resize(int w, int h)

	glViewport(0, 0, w, h);
	gluOrtho2D(0.0, 1.0, 0.0, 1.0);


The last step is to indicate that we are using a resize function in WinMain. If you are using glut, you will need to make a call to glutReshapeFunc.

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
		LPSTR lpCmdLine, int nShowCmd)
	opengl = OpenGL::create();


Most users will prefer having the option of having the window resized. You now have the knowledge to achieve this while allowing your objects to resize appropriately.

Please let me know of any comments you may have : Contact Me

Win32 Source Files : Visual Studio Dev-C++
GLUT Source Files : Visual Studio Dev-C++ Unix / Linux

Last Updated : 14 October 2005

< Tutorial 08 - Color And Shading Tutorial 10 - Transformations >

Back to Top

All Rights Reserved, © Zeus Communication, Multimedia & Development 2004-2005

Read the Disclaimer