0

I am rendering a bush composed of two same images crossed as you can see on the image underneath : enter image description here

But when we turn around the bush, on of the two images has visibly big problems with it's depth test : enter image description here

I tried disabling the depth test but it was even worse(background bushes overlapping the front one). I simply use this code to render a bush (with m_tex and m_vertex the coordinates of a bush loaded in a file):

//Scene initialisation
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

//Then we render objects one per one
glBindTexture(GL_TEXTURE_2D, m_texture);
glBegin(GL_QUADS);
    glTexCoord2d(m_tex[0][0], m_tex[0][1]); glVertex3d(m_vertex[0][0] + coordinates[0], m_vertex[0][1] + coordinates[1], m_vertex[0][2] + coordinates[2]);
    glTexCoord2d(m_tex[1][0], m_tex[1][1]); glVertex3d(m_vertex[1][0] + coordinates[0], m_vertex[1][1] + coordinates[1], m_vertex[1][2] + coordinates[2]);
    glTexCoord2d(m_tex[2][0], m_tex[2][1]); glVertex3d(m_vertex[2][0] + coordinates[0], m_vertex[2][1] + coordinates[1], m_vertex[2][2] + coordinates[2]);
    glTexCoord2d(m_tex[3][0], m_tex[3][1]); glVertex3d(m_vertex[3][0] + coordinates[0], m_vertex[3][1] + coordinates[1], m_vertex[3][2] + coordinates[2]);
glEnd();

How can I manage to fix this bug and have a relevant depth test working with the two images?

4

1 回答 1

2

First of all, immediate mode (glBegin(), glEnd(), etc) is deprecated now, so I would suggest to avoid it, especially if you are learning OpenGL now (have a look at the documentation here).

Apart form that, you should post a complete example (have a look here), because there are several things that can cause the effects you describe (how your scene is initialised?, how you load the textures?, are they really RGBA?, etc).

于 2018-04-18T09:21:28.057 回答