Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm developing a minesweeper game. I'm having a problem with reshaping(resize) the window. I'm using Ubuntu Linux. Following are the code snippets and the entire code is here:

This is my initializing code that I write at the starting of main()

glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (400, 300);
glutCreateWindow ("MineSweeper");
glClearColor (1.0, 1.0, 1.0, 0.0);

glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);

This is my display() func that I pass into glutDisplayFunc() which actually draws the grid requires for minesweeper game.


glColor3f (0.0, 0.0, 0.0);
glLineWidth (3);

float i;
for(i = step; i< 1; i+=step) {

glFlush ();

I searched many forum and finally tried this code for reshape() function in the glutReshapeFunc()

void reshape (int width, int height) {
   glViewport(0, 0, width, height);
   glOrtho(0, width, 0, height, -1.0, 1.0);

But it didn't work and the output was a plane window.

share|improve this question
You're asking several questions at the same time, so it's hard to give you a good answer. I suggest you try to narrow down your question to the problem that is the most important for you at the moment. What exactly is blocking you? –  Laurent Couvidou Sep 26 '13 at 20:19
Is it OK @LaurentCouvidou. Can you now please help me atleast with the resizing window problem? –  meteors Sep 27 '13 at 2:03
Could you tell us what exactly is the problem with the resizing? Is it impossible to resize? –  MiJyn Sep 27 '13 at 3:30
@MiJyn No when I resize the window everthing that I've drawn turns blank into white. –  meteors Sep 27 '13 at 4:53

1 Answer 1

up vote 1 down vote accepted
glViewport(0, 0, width, height); // reset the viewport
glMatrixMode(GL_PROJECTION); // modify the projection matrix
glLoadIdentity();            // load an identity matrix into the projection matrix
glOrtho(0, width, 0, height, -1.0, 1.0); // create new projection matrix

/// Important!!! You need to switch back to the model-view matrix
/// or else your OpenGL calls are modifying the projection matrix!
glMatrixMode(GL_MODELVIEW); // return to the model matrix
glLoadIdentity();           // load an identity matrix into the model-view matrix

// OpenGL has now compensated for the resized window, and is ready to draw again.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.