This function does not change anything even though I already called glOrtho(). What's wrong with the code? Did I miss something?
void glKeyCallback(unsigned char key, int x, int y){
if (key == 'z'){
width -= 10; height -= 10;
cout << "Z" << endl;
cout << width << " " << height << endl;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 800, 600, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
}else if (key == 'x'){
width += 10; height += 10;
cout << "X" << endl;
cout << width << " " << height << endl;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 100, 100, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
}
}
I expected for the scene to zoom in / out when I pressed z or x. But it does not change anything. For the record, I have already registered this on glutKeyboardFunc
OpenGL is not a scene graph, it's a drawing API. Just changing the projection matrix will do nothing. You also have to redraw things.