Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am learning to use pyglet and learning about applying 2D textures to planes in pyglet. When I apply the 2D texture to the plane it works fine. When I make multiple objects with the same texture , one in front of the other, i have a problem.

The texture behind the first texture draws through it. And the texture behind that has the same property.

I would like to disable this so the front texture is shown and obscures the back textures.

In my resize function I called

glClearDepth(1.0)
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LEQUAL)
glShadeModel(GL_SMOOTH)

and in my on_draw function i call

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glEnable(GL_TEXTURE_2D)

I am using a perspective camera with

gluLookAt(velx,0,vely,velx,0,vely-10,0,1,0);

where velx is the x position for the camera and vely is the z position for the camera

Am I processing the texture incorrectly causing this? What should I do to change this?

The images positions are in order on the z axis -10,-20,-40, and -60.

[EDIT] Here is a screenshot of what I was saying enter image description here The GreenBox is in the front and the Red box is behind it

This is the drawing function that i am using. I believe that it is clearing the depth buffer.

@window.event

def on_draw():

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

for x in range(0,4):
    for y in range(0,4):
        glPushMatrix()
        if x % 2== 0 and y % 2==0:
            glBindTexture(texture.target,texture.id)
        else:
            glBindTexture(texture2.target,texture2.id)   
        glTranslatef(x*4.0,0,y*-10.0)
        glBegin(GL_QUADS)

        glTexCoord2f(0.0, 0.0)
        glVertex3f(-1,-1,-10)
        glTexCoord2f(0.0, 1.0)
        glVertex3f(-1,1,-10)
        glTexCoord2f(1.0, 1.0) 
        glVertex3f(1,1,-10)
        glTexCoord2f(1.0, 0.0)
        glVertex3f(1,-1,-10)

        glEnd()

        glPopMatrix() 
share|improve this question
1  
You might consider adding a screenshot –  rraallvv Jan 8 '13 at 5:18
    
What is your projection matrix? You may have a Z computation issue; as a quick test you can try to use a clear depth of -1.0 and GL_GEQUAL instead. –  Sam Hocevar Jan 8 '13 at 9:51
    
I have updated the original question with a screenshot. I have tried a clear depth of -1.0 and GL_GEQUAL and it yields similar results. –  user700508 Jan 8 '13 at 23:56
    
@user700508 When do you actually clear the depth buffer? Do you do it once, or everytime that you render a square? Looks liks you are loosing depth information at some point... Maybe more code could help us in finding the error –  Dan Jan 9 '13 at 0:09
    
Sorry for the lack of code for where it references the clear function. I have added the draw function to show where I am calling glClear and what I am clearing and what I am drawing. Maybe I am doing something fundamentally wrong there. –  user700508 Jan 9 '13 at 0:16
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.