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);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
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.
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.0, 0.0, 0.0);
glLineWidth (3);
float i;
for(i = step; i< 1; i+=step) {
glBegin(GL_LINES);
glVertex3f(i,0,0);
glVertex3f(i,1.0,0);
glEnd();
glBegin(GL_LINES);
glVertex3f(0,i,0);
glVertex3f(1.0,i,0);
glEnd();
}
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);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, -1.0, 1.0);
glFlush();
}
But it didn't work and the output was a plane window.