I hope someone can explain this to me because I feel rather stupid not being able to understand it. I create a window with another subwindow in it using glut. My main functions is this:
int mainWindow, infoWindow;
glutInitWindowPosition(0, 0);
glutInitWindowSize(600, 700);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInit(&argc, argv);
mainWindow = glutCreateWindow(“GLUT Window”);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(kInput);
glutMouseFunc(mInput);
init();
infoWindow = glutCreateSubWindow(mainWindow, 0, 600, 600, 100);
glutDisplayFunc(info_display);
glutReshapeFunc(info_reshape);glutMainLoop();
My main window reshape (reshape) function is this:
glViewport(0, 50, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,
(GLdouble)w / (GLdouble)h, 10.0f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
and my info window reshape function (info_reshape) is this:
glClearColor(1, 1, 1, 1);
glEnable(GL_DEPTH_TEST);
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-300, 300, -50, 50, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
My problem is why do I have to write glViewport(0, 50, w, h) for my main window to appear centered instead of glViewport(0, 100, w, h)? I mean I create my main Window having w x h: 600x700. Then I create the subwindow on the bottom 100 pixels (glutCreateSubWindow(mainWindow, 0, 600, 600, 100)). Why the viewport coordinates are half of the window coordinates? Thanks in advance!