I'm having trouble getting more than one texture to load. I'm now completely mystified, since I've searched right left and centre and I'm not seeing the behviour I am told I should.
If I load two textures (code below) then anything that is drawn with GL_TEXTURE_2D enabled gets the second of the two textures. If I call glBindTexture AT ALL, then neither texture works and I get flat coloured triangles. I'm using PyOpenGL on windows XP.
OpenGL setup stuff:
map(glEnable,(GL_DEPTH_TEST, GL_NORMALIZE,
GL_BLEND))
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
self.ID = self.loadImage("test.png")
#self.ID2 = self.loadImage("texture.png")
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
lghtamb=[0.1,0.1,0.1,1.0]
lghtdif= [1.0,1.0,1.0,1.0]
lpos =[ 1.0, 1.0, 0.0, 1.0 ]
glLightfv(GL_LIGHT1, GL_AMBIENT, lghtamb)
glLightfv(GL_LIGHT1, GL_DIFFUSE, lghtdif)
glLightfv(GL_LIGHT1, GL_POSITION,lpos)
glEnable(GL_LIGHT1)
glEnable(GL_LIGHTING)
glPointSize(5.0)
On of the loadImages is commented out, to make the first one work. Uncommenting it seems to overwrite the first one.
loadImage function:
def loadImage(self,imageName):
im = open(imageName)
try:
ix, iy, image = im.size[0],
im.size[1],
im.tostring("raw", "RGBA", 0, -1)
except SystemError:
ix, iy, image = im.size[0],
im.size[1],
im.tostring("raw", "RGBX", 0, -1)
ID = glGenTextures(1)
print "Allocated texture %d"%ID
glPixelStorei(GL_UNPACK_ALIGNMENT,1)
glTexImage2D(GL_TEXTURE_2D, 0, 4,
ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
return ID
(I can confirm that this works fine for a single texture load, with no call to glBindTexture.)
glEnable(GL_TEXTURE_2D)
# glBindTexture(GL_TEXTURE_2D,self.overlay)
glDisable(GL_DEPTH_TEST)
glDepthMask(GL_FALSE)
glBegin(GL_QUADS)
glTexCoord2f(0.0,0.0)
glp((a[0]-12,a[1]-12,0))
glTexCoord2f(1.0,0.0)
glp((a[0]+12,a[1]-12,0))
glTexCoord2f(1.0,1.0)
glp((a[0]+12,a[1]+12,0))
glTexCoord2f(0.0,1.0)
glp((a[0]-12,a[1]+12,0))
glEnd()
glDepthMask(GL_TRUE)
glEnable(GL_DEPTH_TEST)
glDisable(GL_TEXTURE_2D)
One place where I want to use the texture. self.overlay takes the value of ID from the texture load. I have checked this. If I uncomment the glBindTexture, then neither texture works at all.
I thought glBindTexture was supposed to tell OpenGL which texture to use, not switch it off!!? Can anyone see where I've gone wrong here?