Results 1 to 5 of 5

Thread: rect is not seen behind the other

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2005
    Posts
    2

    rect is not seen behind the other

    i am using a perspective projection.
    now i am drawing a white rectangle(using LINE_LOOP) in the middle of the screen.
    and then i am translating the z axis 1 point back
    ( glTranslate(0,0,-1)) and then i am drawing the same rectangle using the red color(again , in the middle of the screen).

    now , Logicly , i am not supposed to see the
    second rectangle , because the white
    rectangle has to cover it , but what i see
    infront of me is the red rect smaller then the
    white rect and the red is like above the white one.

    i know that the red Rect should be smaller
    because it is more far from the point of view.
    but but why the white rect is apearing behind
    the red one, the red one should be covered.

    Help please, i don't know what to do.
    I am new to Opengl , and this is a basic thing.

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

    Re: rect is not seen behind the other

    ensure you've enabled depth testing and writes to the depth buffer.

    glEnable(GL_DEPTH_TEST);
    glDepthMask(1);

    Also, make sure you've requested a Pixel Format Descriptor with a depth buffer.

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2005
    Posts
    2

    Re: rect is not seen behind the other

    I did not understand a word of everything u just said

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: rect is not seen behind the other

    OpenGL doesn't do any depth testing without you saying it to do so. Depth test will enable GL to automatically 'avoid' the pixels that are more far from others. So, with this way, you'll see only what's visible.

    If you use glut, initialize glut with GLUT_DEPTH, then follow what's Aeluned said.

    If you still don't understand, I just can advise you to read some docs about GL (there are plenty on this website, or check Nehe's tuts or also buy a book).

  5. #5
    Senior Member Regular Contributor
    Join Date
    Jul 2005
    Location
    Berlin, Germany
    Posts
    188

    Re: rect is not seen behind the other

    You are using GL_LINE_LOOP, so you are not drawing the full rect, but only its border. If you want the rect to obscure things behind it, you have to draw a filled rect, using GL_QUADS for example.
    355/113 -- Not the famous irrational number PI, but an incredible simulation!

Similar Threads

  1. Add POINT and RECT functionality to GLM
    By Vasiliy73 in forum OpenGL: General
    Replies: 1
    Last Post: 07-09-2014, 11:30 AM
  2. how can i upload a sub rect of pbo to a texture?
    By wellbye in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-26-2011, 12:35 AM
  3. rect tex & np2 tex,which one does ATi & 3DLabs support
    By pango in forum OpenGL: Advanced Coding
    Replies: 22
    Last Post: 01-18-2007, 12:56 PM
  4. Degenerate scissor rect?
    By Pentagram in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 04-26-2003, 03:07 AM
  5. client rect
    By lee in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 04-24-2001, 09:44 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