So I'm trying to learn how to use glViewport (), "MULTIPLE TIMES". Below is my code, I tried to follow other examples, but they are either so confused with other things that are not related to what I am doing, or, I do not understand what they are doing. By the way, I use oversaturation to control my window system. Therefore, the best way for me is to get a simple example for yourself, and then extrapolate from there. Below is my code for a simple program that divides the screen into two parts and draws two identical spheres, I cannot understand why the sphere on the right is stretched when gluPerspective () is identical for both view ports. Please, if you could just explain to me what I'm doing wrong in my code, this will help a lot. External resources are great, but I need simple, simple examples (not Nate Robinson examples).
GLfloat width = 800, height = 600, x_0 = 470, y_0 = 0;
int mainWindow;
void resize(int w, int h){
width=w;
height=h;
}
void draw(void){
glEnable(GL_SCISSOR_TEST);
glClearDepth(1.0);
glClearColor(0.0, 0.0, 0.0, 1.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
GLfloat color[4] = {1.0, 0.0, 0.0, 1.0};
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, (float)width/2 , height);
gluPerspective(45, ((float)width/2)/(float)height, 1, 2000);
glMatrixMode(GL_MODELVIEW);
glScissor(0, 0, (float)width , height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt( 0.0, 0.0, 50.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0 );
glPushAttrib(GL_LIGHTING_BIT | GL_CURRENT_BIT);
glPushMatrix();
glMaterialfv(GL_FRONT, GL_DIFFUSE, color);
glutSolidSphere(10.0, 20, 40);
glPopMatrix();
glPopAttrib();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport((float)width/2, 0, width , height);
gluPerspective(45, ((float)width)/2/((float)height), 1, 2000);
glMatrixMode(GL_MODELVIEW);
glScissor(((float)width/2), 0, width , height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt( 0.0, 0.0, 50.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0 );
glPushAttrib(GL_LIGHTING_BIT | GL_CURRENT_BIT);
glPushMatrix();
glMaterialfv(GL_FRONT, GL_DIFFUSE, color);
glutSolidSphere(10.0, 20, 40);
glPopMatrix();
glPopAttrib();
glDisable(GL_SCISSOR_TEST);
glFlush();
glutSwapBuffers();
}
void glutAppInitialize(void){
GLfloat light_ambient[] = {0.2, 0.2, 0.2, 1.0};
GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat light_position[] = {1.0, 1.0, 0.0, 0.0};
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}
int main(int argc, char* argv[]){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(x_0, y_0);
glutInitWindowSize(width ,height);
glutAppInitialize();
mainWindow = glutCreateWindow("Tori App");
glutDisplayFunc(draw);
glutReshapeFunc(resize);
glutMainLoop();
return(0);
}
, , , , , , , . , 1/4 , , .
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(width/4, 0, width , height);
gluPerspective(45, ((float)width)/(((float)height)), 1, 2000);