Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

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
    Intern 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,655

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •