Results 1 to 3 of 3

Thread: depth problem caused by changing gluperspective

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2009
    Posts
    1

    depth problem caused by changing gluperspective

    in some project we tried to do something like this:

    Code :
     
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	gluPerspective(60.0, 1.33, 1.0, 120000.0);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    	gluLookAt(500, 200+playerTeam->teamAvatar->pos.y*0.1, 500, 0, 0+playerTeam->teamAvatar->pos.y*0.1, 0, 1.0, 1.0, 1.0);
    	glRotatef(this->angle, 0.0f, 1.0f, 0.0f);
    	glTranslatef(-pos2[0],-pos2[1],-pos2[2]); 
     
    // Draw some objects 
     
    	glEnable(GL_LIGHTING);
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	gluPerspective(60.0, 1.33, 500.0, 120000.0);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    	gluLookAt(500, 200+playerTeam->teamAvatar->pos.y*0.1, 500, 0, 0+playerTeam->teamAvatar->pos.y*0.1, 0, 1.0, 1.0, 1.0);
    	glRotatef(this->angle, 0.0f, 1.0f, 0.0f);
    	glTranslatef(-pos2[0],-pos2[1],-pos2[2]); 
     
     
     
    // draw some other objects
     
    	glDisable(GL_LIGHTING);

    to get the effect of trimming objects between viewer and main character (its a third-person-view game). Of course it works fine, until we realise that there are problems with z-buffer testing (caused by changing zNear value) sothat trees on other side of hill are visible instead of the hill itself.

    Is there a possibility to block affecting z-buffer values while re-setting gluPerspective's zNear value?

  2. #2
    Member Newbie
    Join Date
    Apr 2006
    Posts
    41

    Re: depth problem caused by changing gluperspective

    not sure but i think the preferred way to do this in a game is to trace a ray from the player to the desired camera location, say within a bounding sphere radius of intersection with the world. then you're home free, without any modification to any matrices.

    depth range hacks can be used to prevent first person weapons etc. from disappearing into walls, but that doesn't sound like what you are going for.

  3. #3
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: depth problem caused by changing gluperspective

    Either follow earthquad advice, or to stay within image-space algorithm you may want to try something even simpler like

    draw 1.0-120000.0 range without player
    clear zbuffer (and not color)
    draw player

Similar Threads

  1. ? Clipping Planes and Depth Buffers with gluPerspective() ?
    By Z-Knight in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-23-2016, 07:37 AM
  2. Removing object outline caused by lighting / changing shade color
    By kapitanSurge in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-14-2016, 01:03 AM
  3. Replies: 0
    Last Post: 06-27-2012, 03:19 PM
  4. depth buffer and gluPerspective ratio
    By line72 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-07-2003, 09:11 AM
  5. sky and gluPerspective depth
    By JacekPoplawski in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 08-09-2002, 12:13 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