Thread: OpenGL 3D Polygon question

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    5

    OpenGL 3D Polygon question

    Currently, OpenGL has whichever part of the polygon drawn last, is on top.
    So in 3D, if I rotate this object so the part that was drawn last should be behind the part that was drawn first, the former still shows up on top of the latter.

    Is there any easy way to fix this so it always draws the part closer to the screen on top of the part farther from it when two parts overlap?

    Here's what I'm currently using to draw this shape:
    Code:
                glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
                glClear (GL_COLOR_BUFFER_BIT);
    
                glPushMatrix();
                glRotatef (xtheta, 1.0f, 0.0f, 0.0f);  
                glRotatef (ytheta, 0.0f, 1.0f, 0.0f);  
                glRotatef (ztheta, 0.0f, 0.0f, 1.0f); 
                
                glBegin(GL_POLYGON);
                glColor3f (0.0f, 0.0f, 1.0f); glVertex3d(0, 0, 0);
                glColor3f (0.0f, 0.5f, 1.0f);glVertex3d(.75, 0, 0);
                glColor3f (0.0f, 1.0f, 0.5f);glVertex3d(0, .8, 0);
                glColor3f (0.0f, 1.0f, 0.0f); glVertex3d(0, 0, 1);
                glEnd();
                glPopMatrix();
    Any help is appreciated.

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    sounds like you need to enable the depth buffer or something like that... it's been a while.

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    im drunk and i'm lisrenign to muse!!!!
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    5
    Alright, I've tried adding in glEnable (GL_DEPTH_TEST) after the glClear, but doing that causes the polygon to not show up at all.

    I've also tried messing throwing in glDepthFunc, but I still can't manage to find a way to get it to work. What am I missing?

  5. #5
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Sorry about that last post.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  6. #6
    Registered User
    Join Date
    Mar 2008
    Posts
    5
    I was missing GL_DEPTH_BUFFER_BIT in my glClear() method.

    Problem solved. Thanks

  7. #7
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    Quote Originally Posted by ahluka
    Sorry about that last post.
    You're excused since Muse is awesome.

    /offtopic
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  8. #8
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Quote Originally Posted by psychopath View Post
    You're excused since Muse is awesome.

    /offtopic
    H.A.A.R.P released today! WEWT!
    /offtopic
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL lighting question...
    By psychopath in forum Game Programming
    Replies: 3
    Last Post: 07-31-2004, 03:28 PM
  2. OpenGL question
    By Leeman_s in forum C++ Programming
    Replies: 8
    Last Post: 09-07-2002, 11:17 AM
  3. OpenGL question
    By kas2002 in forum Game Programming
    Replies: 16
    Last Post: 08-02-2002, 12:29 PM
  4. OpenGL Question?
    By TheGr8one in forum Game Programming
    Replies: 4
    Last Post: 09-11-2001, 08:22 PM
  5. OpenGL question
    By Malek in forum Windows Programming
    Replies: 1
    Last Post: 09-10-2001, 12:00 PM