I suppose that to use subwindows under GLUT could be easier than to use viewports with glViewPort. But I’d like to know the mechanism of glViewPort too.
I’ve made an little program to test it. In the program viewprot should be the quarter of the entire window and should take place in the lower-left corner, but it doesn’t want to work. Please check this code and tell me what did I wrong:
#include <stdio.h>
#include <GL\glut.h>
#include “LC_gui.h”// The Following Directive Fixes The Problem With Extra Console Window
#pragma comment(linker, “/subsystem:"windows" /entry:"mainCRTStartup"”)//-------------------->> Global variables <<--------------------
//GLint GUIwindowWidth, GUIwindowHeight;
GLint GUIwindow;
void GUIwindowInit(void);
void NormalKeyboardEvent(unsigned char key, int x, int y);
void MouseEvent(int button, int state, int x, int y);
void GUIScene();
//-------------------->> The Main Function <<--------------------
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowSize(500, 500);GUIwindow = glutCreateWindow(" — LightCounstruct v001 —");
GUIwindowInit();
glutDisplayFunc(&GUIScene);
glutKeyboardFunc(&NormalKeyboardEvent);
glutMouseFunc(&MouseEvent);
// glutFullScreen();glutMainLoop();
return 0;
}//-------------------- Funkciók —<<
void GUIwindowInit(void)
{
GLdouble AspectRatio;glClearColor (0.0, 0.2, 0.0, 0.0);
glShadeModel (GL_FLAT);
AspectRatio = (GLfloat)LC_GUI_WINDOW_WIDTH / (GLfloat)LC_GUI_WINDOW_HEIGHT;
glViewport(0, 0, 250, 250);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0f, 250/250, 0, 20);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 7.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}
void NormalKeyboardEvent(unsigned char key, int x, int y)
{
switch (key) {
case 27 :
glutDestroyWindow(GUIwindow);
exit(0);
}
}
void MouseEvent(int button, int state, int x, int y)
{
switch (button)
{
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN)
exit(0);
break;
default:
break;
}
}
void GUIScene()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_QUADS);
glVertex3f(-30.0, 30.0, 0.0);
glVertex3f(30.0, 30.0, 0.0);
glVertex3f(30.0, -30.0, 0.0);
glVertex3f(-30.0, -30.0, 0.0);
glEnd();glColor3f(0.0, 1.0, 0.0);
glBegin(GL_LINES);
glVertex3f(-40.0, 40.0, 0.0);
glVertex3f(40.0, 40.0, 0.0);
glVertex3f(40.0, -40.0, 0.0);
glVertex3f(-40.0, -40.0, 0.0);
glEnd();
glColor3f(1.0, 0.5, 0.0);
glutWireSphere(2.0, 20, 16);
glFlush();
}
brown