Results 1 to 6 of 6

Thread: Multiple viewports

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2006
    Posts
    25

    Multiple viewports

    I've got a 3D openGL window in my application. I've created two viewports. The first viewport is the leftmost 85% of the openGL window. The second viewport is the rightmost 15% of the window. I've done this successfully. I then succesfully draw my objects in the left viewport.

    NOW FOR THE HELP I NEED. The object that I'm drawing the second viewport needs to be perfectly centered, and rotate around it's middle axis, like a person spinning around a pole. However, when I rotate the objects in the window, the second viewport's object isn't rotating TIGHTLY. Instead, it's rotating simlarly to the model in the left veiwport.

    Any thought?

    Thanks very much.

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Multiple viewports

    I am confused by your sparse explanation

    Anyway, you may want to swap your glTranslate and glRotate calls, it is a common error.

  3. #3
    Member Contributor
    Join Date
    Sep 2006
    Location
    US(California)
    Posts
    58

    Re: Multiple viewports

    Wat do you mean by TIGHTLY and why caps? Is that a constant?(...)

    I imagine wat you mean is that the object is not rotating along it its own axes, but along the global center axes. To fix this first call glLoadIdentity(); Then call glTranslatef(x,y,z);

    x,y,z being the x,y,x of the objects location or position.

    Then call:

    glRotatef(x,1,0,0);
    glRotatef(y,0,1,0);
    glRotatef(z,0,0,1);

    x,y,z being the rotation in that axes (in degrees)

    Ok hopefully that is the correct answer to the correct question.

    Post back.
    -Josh

  4. #4
    Junior Member Newbie
    Join Date
    Oct 2006
    Posts
    25

    Re: Multiple viewports

    Here's my code:

    SetProjection();

    // clear background to white and clear depth buffer
    glClearColorfv( m_fvClearColor );
    glClearDepth( 1.0 );
    glEnable( GL_DEPTH_TEST );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glFlush();

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glTranslated(x,y,z);
    glRotated(dRotation, 0.0, 0.0, 1.0);

    // draw object in the first viewport
    glPushAttrib( GL_ALL_ATTRIB_BITS );
    glEnable( GL_CULL_FACE );
    glCullFace( GL_BACK );
    glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );

    glPushMatrix();

    //here's drawing code for the object itself, in the first view port (it's simply a disk)

    quadObj = gluNewQuadric();
    gluQuadricOrientation( quadObj, GLU_INSIDE );
    gluQuadricDrawStyle( quadObj, GLU_FILL );
    gluQuadricNormals( quadObj, GLU_SMOOTH );
    gluDisk( quadObj, 0.0, dLength, 16, ;
    gluDeleteQuadric( quadObj );

    glPopMatrix();

    glPopAttrib();

    glPopMatrix();

    //draw object in the second viewport
    //(this is the one I'm having trouble with)

    glViewport(....);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    gluPerspective( m_dFOV, dAspectRatioOfSecondViewport, 1.0, 15.0);
    glClear (GL_DEPTH_BUFFER_BIT);

    //draw the object in the second viewport
    .....

    glPopMatrix();

    SwapBuffers(wglGetCurrentDC());


    Everything in my first viewport draws perfectly. It's only the second viewport that's giving me problems. I don't even see the object in my second viewport, with the above code. Perhaps my openGL function calls are out of sequence? I've tinkered around with changing the order, but to no avail.

  5. #5
    Junior Member Newbie
    Join Date
    Oct 2006
    Posts
    25

    Re: Multiple viewports

    Ok, I modified my code and now my object in my second viewport draws, but it does NOT rotate. Viewport #2 needs rotate simultaneously with Viewport #1.


    Here's my code:

    SetProjection();

    // clear background to white and clear depth buffer
    glClearColorfv( m_fvClearColor );
    glClearDepth( 1.0 );
    glEnable( GL_DEPTH_TEST );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glFlush();

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glTranslated(x,y,z);
    glRotated(dRotation, 0.0, 0.0, 1.0);

    // draw object in the first viewport
    glPushAttrib( GL_ALL_ATTRIB_BITS );
    glEnable( GL_CULL_FACE );
    glCullFace( GL_BACK );
    glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );

    glPushMatrix();

    //here's drawing code for the object itself, in the first view port (it's simply a disk)

    quadObj = gluNewQuadric();
    gluQuadricOrientation( quadObj, GLU_INSIDE );
    gluQuadricDrawStyle( quadObj, GLU_FILL );
    gluQuadricNormals( quadObj, GLU_SMOOTH );
    gluDisk( quadObj, 0.0, dLength, 16, ;
    gluDeleteQuadric( quadObj );

    glPopMatrix();

    glPopAttrib();

    glPopMatrix();


    //NOW I HANDLE THE VIEWPORT #2

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glViewport();//set viewport #2

    gluPerspective( m_dFOV, dAspectRatio, .1, 6.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    //draw the object in viewport #2
    ......
    .....

    glClear (GL_DEPTH_BUFFER_BIT);
    SwapBuffers(wglGetCurrentDC());

    Again, viewport #1 is perfect, rotates correctly, etc. Viewport #2 is ok, except that the object does not rotate whatsoever. It should rotate when the object in viewport #1 is rotated by the user.

    Thanks again.

  6. #6
    Junior Member Newbie
    Join Date
    Oct 2006
    Posts
    25

    Re: Multiple viewports

    I figured out the issue(s). Mainly, the problem was not moving (glTranslate) to the proper location in viewport #2 before drawing that viewport's model. When calling gluPerspective(...), you've got to be sure that the 'near Z' and 'far Z' are set such that the Z of the drawing itself falls between them.

    Thanks for your help, darkrappey and ZbuffeR.

Similar Threads

  1. Multiple viewports
    By EugChriss in forum Vulkan
    Replies: 2
    Last Post: 03-29-2018, 06:54 PM
  2. Multiple Viewports, Multiple Textures - 3D
    By Cyndy in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 04-08-2010, 04:47 PM
  3. multiple viewports
    By jra3084 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-29-2003, 08:52 AM
  4. Multiple ViewPorts
    By PlayBoy in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-08-2003, 02:02 PM
  5. Multiple viewports?
    By spdow in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 11-16-2001, 04:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean