In my scene I have a cube within a sphere. I would like to apply a RGB texture to a sphere and make it translucent. I can import the texture, apply it to the sphere and make it translucent but i am not getting the result I want.
My blend function is glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
My draw method is as follows:
def DrawGLScene():
rotation1 = 60
rotation2 = 60
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glEnable(GL_BLEND)
glLoadIdentity()
glTranslatef(0.0, 0.0, -8.0)
glRotatef(rotation1, 1.0, 0.0, 0.0)
glRotatef(rotation2, 0.0, 1.0, 0.0)
glColor4f(1.0,1.0,1.0,1.0)
glutSolidCube(2);
glEnable(GL_COLOR_MATERIAL)
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D,1)
glColor4f(1.0,1.0,1.0,0.3)
Q=gluNewQuadric()
gluQuadricNormals(Q, GL_SMOOTH)
gluQuadricTexture(Q, GL_TRUE)
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP)
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP)
gluSphere(Q, 2.35, 32, 16)
glDisable(GL_TEXTURE_2D)
glutSwapBuffers()
The result looks like this:
It seemed there were depth problems as I could only see the back side of the sphere in parts in the bottom right. I then set glDepthFunc(GL_LESS) for drawing the cube and glDepthFunc(GL_ALWAYS) for drawing the sphere which resulted in:
Now the back side of the sphere is showing through the cube.
I have tried multiple combinations of glDepthFunc() for the objects but to no avail. Is the problem to do with how I am handling depth, blending or something else?
EDIT:
Using glEnable(GL_CULL_FACE)
and glCullFace(GL_BACK)
in the first example gives me the following which is still not correct as now you cannot see the back of the sphere at all.