about reshaping

i’m a beginner of computer graphics. i cant figure out why i cant reshape my image in the screen window. that is whenever i resize the screen window, the screen in the window becomes black in color and the image previously drawn disappear. is this a problem related the reshaping function or other functions?

here is my reshaping function:

myReshape(GLsizei width, GLsizei height)

WinHeight = height;
WinWidth = width;

glViewport(0,0, WinWidth, WinHeight); 
	// set current viewport, ie. the portion of the window to which 
	// everything will be clipped

	// set current matrix mode to the given mode

	// load identity matrix to matrix stack so that current matrix
	// is the identity matrix

gluOrtho2D(0, WinWidth , 0, WinHeight);



You should not have a glutSwapBuffers in the reshape call back this is only called when the window changes size and allows you to for example call glViewPort to set the viewport size.

All rendering related calls including glutSwapBuffers shoyld be placed in the display callback where the rendering is done.


i see. thank you for your reply. but after i deleted the glSwapBuffers() in it, the rectangle image in the screen window still didnt change size when i resized the screen window. why? ?_?

the problems seem to be that you

  1. do not clear the color/depth buffer
  2. do not redraw the scene

thank you very much. i got my problem now. now i have another question. what is the difference between glutPostRedisplay() and glutSwapBuffers()?

glutPostRedisplay asks glut to run the display callback after it has processed all pending events. Call this function when you need your window to be redrawn.

glutSwapBuffers exchanges the two drawbuffers when using double buffering. Double buffering means, that you have two separate buffers, one being displayed (the front buffer) and one that you draw into (the back buffer). This way you have a stable image on screen, even while drawing. When you finish drawing to the back buffer you have to exchange the two to have your new image displayed. Call glutSwapBuffers from you display callback, when you’ve finished drawing the new frame.