Creating FPS in OpenGL: My gun is cropped again in a truncated area

I am creating a first-person shooter using OpenGL, and I am trying to make the gun model float in front of the camera. I tore the model from Fallout 3 using a resource decompiler (converted to .obj and loaded).

However, this is what the screen looks like:

Screen shot

Half of the gun's triangles are clipped to what seems truncated.

I put it in front of my camera as follows:

glPushMatrix();
    glLoadIdentity();

    glTranslatef(m_GunPos.x, m_GunPos.y, m_GunPos.z);
    glRotatef(m_GunRot.x, 1, 0, 0);
    glRotatef(m_GunRot.y, 0, 1, 0);
    glRotatef(m_GunRot.z, 0, 0, 1);
    glScalef(m_GunScale.x, m_GunScale.y, m_GunScale.z);

    m_Gun->Render(NULL);
glPopMatrix();

So, I save the original matrix GL_MODELVIEW, load the identification matrix, translate the gun a little to the right of the camera and visualize it. This is my rendering routine for SceneNode:

glPushMatrix();
    if (m_Model) { m_Model->Render(&final); }

    if (m_Children.size() > 0)
    {
        for (std::vector<SceneNode*>::iterator i = m_Children.begin(); i != m_Children.end(); ++i)
        {
            (*i)->Render(&final);
        }
    }
glPopMatrix();

Thus, it displays its own model and any child SceneNode. Finally, the actual rendering of the grid is as follows:

if (m_Material)
{
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, m_Material->m_TexDiffuse);
}

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);

glVertexPointer(3, GL_FLOAT, sizeof(Vec3), &m_Vertex[0]);
glNormalPointer(GL_FLOAT, sizeof(Vec3), &m_Normal[0]);
glTexCoordPointer(2, GL_FLOAT, 0, &m_UV[0]);

glDrawArrays(GL_TRIANGLES, 0, m_Vertex.size());

glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

? ?

.

+3
6

( ) OpenGL, - . , gluPerspective ( glFrustrum, ), znear , , (, , - ).

: , Z-. - , znear .

+2

.

znear, . . , z- .

+2

(.. )? , ? , , , ( ). , - , .. ..

- ? , , , ,

+2

, ?

0

, , . , , , glDepthRange. .

, /, z-.

0

"Layering" , , "". , , , . 2 :

  • ( ), .
  • glDepthRange.

, , , :

  • This prevents objects from intersecting from each other (near layers they will always be displayed on top of other layers - they never intersect). Sometimes this is what you want to achieve anyway with fps, where the gun is always on top of everything.
  • Your depth buffer will not be suitable for things like postfx (depth of field, etc.) or deferred rendering.
0
source

Source: https://habr.com/ru/post/1732348/


All Articles