Results 1 to 6 of 6

Thread: setting the near clip with gluPerspective

  1. #1
    Member Contributor
    Join Date
    Apr 2002
    Posts
    94

    setting the near clip with gluPerspective

    I want to change the setting of the near clip when drawing different parts of the scene so that certain parts of the scene are clipped and other parts are not clipped.

    I tried this...

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0, (GLfloat) 640 /(GLfloat) 480, nearPlaneDist, 100.0f);
    glMatrixMode(GL_MODELVIEW);

    but it isn't quite working correctly. My question is: Can I just call gluPerspective anywhere in my code? Or do I have to always call gluPerspective first, before doing any transformations? I guess I might need to do something like this...

    glGetFloatv(GL_MODELVIEW_MATRIX,savedMatrix);
    glLoadIdentity();

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0, (GLfloat) 640 /(GLfloat) 480, nearPlaneDist, 100.0f);
    glMatrixMode(GL_MODELVIEW);

    glMultMatrixf(savedMatrix);

    Is there an easier/better way to do this? Thanks in advance!
    P4 2Ghz, GEFORCE4, 512 Meg RAM, WIN2000, VStudio 6.0

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: setting the near clip with gluPerspective

    You can set the projetion matrix anywhere you like.

  3. #3
    Member Contributor
    Join Date
    Apr 2002
    Posts
    94

    Re: setting the near clip with gluPerspective

    Will changing the near plane affect the depth values at all?
    P4 2Ghz, GEFORCE4, 512 Meg RAM, WIN2000, VStudio 6.0

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: setting the near clip with gluPerspective

    If the far plane is far out compared to the near plane, changing the near plane will have a great impact on the precision of the depth buffer. You should always have the far plane as far out as you can possibly accept for best precision.

  5. #5
    Member Contributor
    Join Date
    Apr 2002
    Posts
    94

    Re: setting the near clip with gluPerspective

    Well, I have the near clip out at 13 and the far at 100 and render. Then I change the near to 0.1 and render again and it seems like the depths are not correct because the last and closer polys rendered are partially in back of the first. Maybe I should look into glDepthRange and partition it into two areas? Does that sound like a good way to go?
    P4 2Ghz, GEFORCE4, 512 Meg RAM, WIN2000, VStudio 6.0

  6. #6
    Member Contributor
    Join Date
    Apr 2002
    Posts
    94

    Re: setting the near clip with gluPerspective

    Used glDepthRange(0.1,1.0) and glDepthRange(0.0,0.09999)...that fixed it. Thanks!
    P4 2Ghz, GEFORCE4, 512 Meg RAM, WIN2000, VStudio 6.0

Similar Threads

  1. Setting up a camera using gluperspective
    By admiralfirelam in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-17-2009, 07:46 PM
  2. Clip R,G,B,S,T
    By IG in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 04-23-2006, 06:19 AM
  3. How can i clip this?
    By Hideki in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 04-13-2004, 12:17 PM
  4. how to clip ??
    By hellrage in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-31-2002, 09:57 PM
  5. To clip or not to clip ?
    By rIO in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 03-02-2001, 02:16 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