Thread: glViewport()

  1. #1
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926

    glViewport()

    I am trying to create 2 viewports on my screen to display two things with different PROJECTION matrices next to eachother. However it only displays the first set of primitives. What is wrong?
    Code:
    #include <GL/gl.h>
    #include <GL/glu.h>
    #include <GL/glut.h>
    
    int x;
    
    void init(void){
            glClearColor(0.0,0.0,0.0,0.0);
            glShadeModel(GL_SMOOTH);
    }
    
    void idle(void){
            x++;
            x%=360;
            glutPostRedisplay();
    }
    
    void reshape(int w,int h){
            glViewport(0,0,(GLsizei)w,(GLsizei)h);
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            gluPerspective(60.0,1.0,1.5,20.0);
            glMatrixMode(GL_MODELVIEW);
    }
    
    void display(void){
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            glViewport(0,0,(GLsizei)250,(GLsizei)500);
            gluPerspective(60.0,1.0,1.5,20.0);
            glMatrixMode(GL_MODELVIEW);
            glClear(GL_COLOR_BUFFER_BIT);
            glColor3f(1.0,1.0,1.0);
            glLoadIdentity();
            glTranslatef(0.0,0.0,-5.0);
            glutWireSphere(0.3,10,10);
            glRotatef(x,0.0,1.0,0.0);
            glScalef(1.0,2.0,1.0);
            glutWireCube(1.0);
            glutSwapBuffers();
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            glViewport(0,0,(GLsizei)250,(GLsizei)500);
            gluPerspective(60.0,1.0,1.5,20.0);
            glMatrixMode(GL_MODELVIEW);
            glClear(GL_COLOR_BUFFER_BIT);
            glColor3f(1.0,1.0,1.0);
            glLoadIdentity();
            glTranslatef(0.0,0.0,-5.0);
            glutWireSphere(0.3,10,10);
            glRotatef(x,0.0,1.0,0.0);
            glScalef(1.0,2.0,1.0);
            glutWireCube(1.0);
            glutSwapBuffers();
    }
    
    int main(int argc,char **argv){
            glutInit(&argc,argv);
            glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
            glutInitWindowSize(500,500);
            glutInitWindowPosition(100,100);
            glutCreateWindow(argv[0]);
            init();
            glutReshapeFunc(reshape);
            glutDisplayFunc(display);
            glutIdleFunc(idle);
            glutMainLoop();
            return 0;
    }

  2. #2
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    i figured it out. I forgot to change the parameters for glViewport() for the second run. So effectively I had two viewports on top of eachother.

Popular pages Recent additions subscribe to a feed