Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Multiple rotating objects on one window

Hybrid View

  1. #1
    Intern Contributor
    Join Date
    Jan 2005
    Location
    Karachi, Pakistan
    Posts
    86

    Multiple rotating objects on one window

    Hello there.
    I want to make an application having half of the window showing the front profile of an object whereas the other half showing the top profile. Now I have done this by creating two viewports. I get my objects in the correct orientation but as soon as i rotate them i don't see them both rotate together. I tried to push matrix and pop it
    just to give you the idea this is what I am doing
    in my rendering function.

    clear
    setViewport1()
    push matrix
    rotate()
    drawObject()
    pop matrix

    setViewport2()
    push matrix
    rotate()
    drawObject()
    pop matrix

    Help me please. I tried to replace the push pop matrix calls with loadIdentity but still get the same result. Thanx in advance.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Feb 2004
    Location
    Long Island, New York
    Posts
    586

    Re: Multiple rotating objects on one window

    Does your setViewport function set the camera transformations (for a top view for example).

    what do you mean you don't see them rotate together? only one rotates?

    I don't see anything obviously wrong with your code there, it's probably elsewhere.

  3. #3
    Guest

    Re: Multiple rotating objects on one window

    Check your glMatrixMode() calls carefully, perhaps you are doing everything on top of the projection matrix (which usually has a stack limit of two).

  4. #4
    Intern Contributor
    Join Date
    Jan 2005
    Location
    Karachi, Pakistan
    Posts
    86

    Re: Multiple rotating objects on one window

    Originally posted by Aeluned:
    Does your setViewport function set the camera transformations (for a top view for example).

    what do you mean you don't see them rotate together? only one rotates?

    I don't see anything obviously wrong with your code there, it's probably elsewhere.
    My setViewport is nothing but
    glViewport(0,0,300,300);
    and the second one is
    glViewport(300,0,300,300);
    Thus I have two 300x300 regions.

    By not seeing them together, I mean that when I place glRotate call before first DrawObject call then both of the objects rotate however when I place two glRotate calls (one before each drawObject function) then nothing rotates everything is static.

  5. #5
    Intern Contributor
    Join Date
    Jan 2005
    Location
    Karachi, Pakistan
    Posts
    86

    Re: Multiple rotating objects on one window

    Originally posted by <Honk>:
    Check your glMatrixMode() calls carefully, perhaps you are doing everything on top of the projection matrix (which usually has a stack limit of two).
    Well, I have setup the projection in my reshape function. I would check to see if I have changed the matrix to modelview in or before my render function. Thanx for that.

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Feb 2004
    Location
    Long Island, New York
    Posts
    586

    Re: Multiple rotating objects on one window

    your pseudocode looks fine though...
    hhmm...could you post the actual code?

  7. #7
    Intern Contributor
    Join Date
    Jan 2005
    Location
    Karachi, Pakistan
    Posts
    86

    Re: Multiple rotating objects on one window

    Originally posted by Aeluned:
    your pseudocode looks fine though...
    hhmm...could you post the actual code?
    Sure here you go.
    Code :
    /////////////////////////////////////////////////
    //Main.cpp
    #include <GL/glut.h>
     
     
    struct point2D{
    	GLfloat x,y;
    };
     
     
     
    void Init()
    {
       glClearColor(1.0,1.0,1.0,0.0);
     
       glMatrixMode(GL_PROJECTION);
       gluOrtho2D(-100,100,-100,100);
     
       glMatrixMode(GL_MODELVIEW);
    }
     
    void DrawTriangle(point2D *pts)
    {
       GLint i;
     
       glBegin(GL_TRIANGLES);
       for(i=0;i<3;i++)
    	   glVertex2f(pts[i].x, pts[i].y);
       glEnd();
    }
     
    void Render()
    {
       point2D pts[3]={{-50.0,-25.0 },{50.0,-25.0},{0.0,50.0}};
     
       glClear(GL_COLOR_BUFFER_BIT);
     
       glColor3f(0, 0 , 1);				//Change color to blue
       glViewport(0,0,300,300);         //SetViewport1
       glPushMatrix();					//Push matrix
       glRotatef(2.0f,0.0f,0.0f,1.0f);	//Rotate in z axis
       DrawTriangle(pts);				//DrawObject
       glPopMatrix();                   //Pop matrix 
     
       glColor3f(1, 0 , 0);			   //Change color to red
       glViewport(300,0,300,300);      //SetViewport2
       glPushMatrix();				   //Push matrix
       glRotatef(2.0f,1.0f,0.0f,0.0f); //Rotate in x axis
       DrawTriangle(pts);			   //Pop matrix
       glPopMatrix();
     
       glFlush();
     
    }
     
    void Idle()
    {		
       glutSwapBuffers();
       glutPostRedisplay();
    }
     
    void main(int args, char **argv)
    {
       glutInit(&amp;args,argv);
       glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
       glutInitWindowSize(600,300);
       glutCreateWindow("Test vieports in GLUT");
       Init();
       glutDisplayFunc(Render);  
       glutIdleFunc(Idle);
       glutMainLoop();
    }
     
    /////////////////////////////////////////////////
    Let me know your comments.Thanx for putting in your time.

  8. #8
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: Multiple rotating objects on one window

    Try this: Remove the glutSwapBuffers from the idle loop and replace the glFlush in the Render function with it.
    In general, do not rely on backbuffer contents after SwapBuffers.

  9. #9
    Intern Contributor
    Join Date
    Jan 2005
    Location
    Karachi, Pakistan
    Posts
    86

    Re: Multiple rotating objects on one window

    Originally posted by Relic:
    Try this: Remove the glutSwapBuffers from the idle loop and replace the glFlush in the Render function with it.
    In general, do not rely on backbuffer contents after SwapBuffers.
    Tried what you said but now I don't see my triangles. When the program runs now, it sort of takes a snapshot of my screen and displays it. Now I do not see my triangles. What is wrong now???

  10. #10
    Advanced Member Frequent Contributor plasmonster's Avatar
    Join Date
    Mar 2004
    Posts
    750

    Re: Multiple rotating objects on one window

    Hi MMMovania,

    I changed the gluOrho2D call to

    glOrtho(-100,100,-100,100,-100,100),

    and now I see 2 happy triangles.

    I think you were seeing the right triangle clipped by the far-plane.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •