Results 1 to 10 of 10

Thread: Draw objects at the same position

  1. #1
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    14

    Draw objects at the same position

    I am writing a small application that used opengl library and I met a problem as follow. When I draw some objects at the same position they blend together. for example some lines in this image become dot.


    Could you please tell me how to fix this problem. I would like to appreciate your help on this

    Thanks,

  2. #2
    Member Newbie m3xican's Avatar
    Join Date
    Nov 2007
    Location
    Italy -> Naples
    Posts
    36

    Re: Draw objects at the same position

    I suppose it's a z-fighting problem.

    This webpage and a google search should help you.

  3. #3
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    14

    Re: Draw objects at the same position

    Could you please tell me the best solution to fix this problem

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    990

    Re: Draw objects at the same position

    You can try this.

  5. #5
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    14

    Re: Draw objects at the same position

    Thanks, I tried this and it seems that it works well, but I meet another problem when I fill on a face of a wall some time they blend together as the image bellow. could you please tell me how to fix it? thank you very much


  6. #6
    Senior Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    990

    Re: Draw objects at the same position

    Can you post your rendering call where you setup the projection matrices and render the quads/lines? The gray lines seem to render above the blue surface just fine. Maybe the offset for the white lines just isn't large enough.

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

    Re: Draw objects at the same position

    Looks like he means the blue face is rendered on a white face and the white lines is bleed-through corruption from the white block underneath.
    In that case you need to (polygon-)offset the two faces from another as well. That is, shift the blue faces nearer to the viewer and the grey lines on top of the blue with it as you did before.

  8. #8
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    14

    Re: Draw objects at the same position

    Yes, the white lines appear when I fill a blue face on a white face as the image bellow



    I used this function to shift the line nearer the viewer and the line problem is fixed

    GL.Enable(GL.POLYGON_OFFSET_FILL);
    GL.PolygonOffset(1, 0.0001f);

    Could you please tell me which function should I used to fix this bug

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

    Re: Draw objects at the same position

    That was for the blue face only? Which would push the blue face about a depth unit back.

    Now you need to render the whole white block with an even bigger offset and that should separate the white from the blue face.

    The order in which you render the things doesn't matter with depth test enabled, just make sure they are separated from each other enough with polygon offset to prohibit depth bleeding.

    // depth test is enabled
    DrawTheGreyLines(); // These are rendered at their original depth and should come out in front.
    GL.Enable(GL.POLYGON_OFFSET_FILL);
    GL.PolygonOffset(1.0f, 1.0f);
    DrawTheBlueFace(); // This goes behind the grey lines.
    GL.PolygonOffset(2.0f, 2.0f);
    DrawTheWhiteBox(); // This goes behind the blue face.
    GL.Disable(GL.POLYGON_OFFSET_FILL);

  10. #10
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    14

    Re: Draw objects at the same position

    Thank you for your help, it works well

Similar Threads

  1. Replies: 14
    Last Post: 06-30-2015, 03:40 AM
  2. how to draw at right position?
    By imported_davie in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 04-15-2010, 09:13 AM
  3. How to draw a frustrum from a given position
    By kreyszig in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 09-30-2008, 01:03 PM
  4. Draw object at particular position
    By girish3110 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-05-2008, 06:07 AM
  5. how to draw a cylinder in specific position
    By wf in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 02-22-2002, 11:02 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