Results 1 to 5 of 5

Thread: Objects being drawn through other objects

  1. #1
    Junior Member Newbie
    Join Date
    May 2009
    Location
    Sweden
    Posts
    3

    Objects being drawn through other objects

    I started learning OpenGL from http://www.videotutorialsrock.com/ a few days ago. To learn something, I decided to make an analog clock.

    Things went pretty good, I made the arms and made them move the way they should. Then I got the suggestion to cover the middle, since the arms looked funny. So I made a little box to cover it. Ran into some issues because I had screwed up beforehand, but managed to do it. Then I decided to make some kind of background, so I could try out lightning and perhaps textures. This wasn't a big issue either, just copying the code I made for the little "cover box" and change its parameters.

    Also, since my brother didn't believe the clock was actually 3D (which some might say it's not, but whatever) I did some keyhandling so the camera rotates left, right, up, down, in and out. That's about as far as I've come at this point.

    Now the question. The arms, backgrounds and cover are outputted on different places on the Z axis, like:

    cover - arms - background

    with a small gap in between. To my understanding, this is what decides which object is in front of something else when rendering. However, I noticed something funny when moving the camera around the back of the clock - looking at it from behind, I still see the arms and the cover, even though they're supposed to be on the far side (the front) of the background.

    I looked around, but can't find any info on this. So can someone explain why this is? That is the question, sorry for all the background info.

    The source (it's just one file, hopefully properly commented and not too large) can be found here:
    http://fryspunkten.se/coding/OGL_Clock.cpp
    if anybody feels like trying it out themselves.

    Any other questions, just ask. But I would like to solve this before moving on with the program (got big plans for my clock, yay!). And the window which prints the variables all the time is for error checking a problem I had, sorry about that.

  2. #2
    Member Newbie
    Join Date
    May 2009
    Location
    Portugal
    Posts
    45

    Re: Objects being drawn through other objects

    I'm not sure if your problem is this but try to put this before drawing the quads, glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    I repeat, I'm not sure if this will solve your problem
    "If you can't be a good example, you'll have to serve as a good warning..."

  3. #3
    Junior Member Newbie
    Join Date
    May 2009
    Location
    Sweden
    Posts
    3

    Re: Objects being drawn through other objects

    Hey, thanks for the quick reply!

    I read up on it and tried that solution. I put the line you gave before drawing the background (first quad). I could still see the arms through the back of the background. So I put
    glPolygonMode(GL_FRONT, GL_FILL);
    glPolygonMode(GL_BACK, GL_POINT);
    in front of the second arm. This actually kind of solved the issue of the second arm being showed from the back. So it can be used as a solution in this case.

    But if I have some bigger construction, like a pyramid (instead of the 2D shapes I have now) which is behind a wall, it wouldn't work, as the "outside" of the pyramid has to have GL_FILL, if anything. So the topic is still open I guess

  4. #4
    Senior Member Regular Contributor remdul's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands
    Posts
    346

    Re: Objects being drawn through other objects

    It seems like you'll want to use the depth-buffer?

    Try glEnable(GL_DEPTH_TEST) , it is commented out in your code so I'm not sure what you're after...

  5. #5
    Junior Member Newbie
    Join Date
    May 2009
    Location
    Sweden
    Posts
    3

    Re: Objects being drawn through other objects

    There we go, thank you!
    I have no idea why it's commented. Might have been me trying out glEnable(GL_SMOOTH), and for some reason thinking they can't both be called :S

    It's slightly embarrassing, but at least I (hopefully) won't be doing that same mistake again. Thanks a bunch

Similar Threads

  1. Replies: 6
    Last Post: 02-12-2013, 03:37 PM
  2. [SOLVED] Objects drawn in odd order
    By metalac in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-09-2010, 10:50 AM
  3. Small objects are partially not drawn
    By AstroBistro in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-11-2010, 02:38 PM
  4. Objects aren't always drawn
    By Shelling in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-16-2008, 11:18 AM
  5. How to erase part of the drawn objects?
    By earth_walker in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 07-27-2003, 04:18 AM

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