Hi,
I rediscovered a weird problem and I don't know how to fix it. A cubemap is
created:
texture = glGenTextures(1)
glBindTexture(GL_TEXTURE_CUBE_MAP,texture)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,GL_RGB,512,512,0,GL_RGB,GL_UNSIGNED_BYTE,None)
glTexParameterf(paramtype,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexParameterf(paramtype,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0,GL_RGB,512,512,0,GL_RGB,GL_UNSIGNED_BYTE,None)
glTexParameterf(paramtype,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexParameterf(paramtype,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0,GL_RGB,512,512,0,GL_RGB,GL_UNSIGNED_BYTE,None)
glTexParameterf(paramtype,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexParameterf(paramtype,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,0,GL_RGB,512,512,0,GL_RGB,GL_UNSIGNED_BYTE,None)
glTexParameterf(paramtype,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexParameterf(paramtype,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0,GL_RGB,512,512,0,GL_RGB,GL_UNSIGNED_BYTE,None)
glTexParameterf(paramtype,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexParameterf(paramtype,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0,GL_RGB,512,512,0,GL_RGB,GL_UNSIGNED_BYTE,None)
glTexParameterf(paramtype,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexParameterf(paramtype,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
Later, it is updated:
x,y,z=pos
update = [1,2,3,4,5,6]
faces = [GL_TEXTURE_CUBE_MAP_POSITIVE_X,GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,GL_TEXTURE_CUBE_MAP_NEGATIVE_Z]
for i in update:
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
cubemapview.set_view()
if i == 1: gluLookAt(x,y,z, x+1, y, z, 0,-1, 0)
elif i == 2: gluLookAt(x,y,z, x-1, y, z, 0,-1, 0)
elif i == 3: gluLookAt(x,y,z, x,y+1, z, 0, 0, 1)
elif i == 4: gluLookAt(x,y,z, x,y-1, z, 0, 0,-1)
elif i == 5: gluLookAt(x,y,z, x, y,z+1, 0,-1, 0)
elif i == 6: gluLookAt(x,y,z, x, y,z-1, 0,-1, 0)
drawreflectees()
glCopyTexImage2D(faces[i-1],0,GL_RGBA,0,0,512,512,0)
When it is time to draw an object, the cubemap is passed to the shader as
active texture 1:
glActiveTexture(num)
active_texture = glGetIntegerv(GL_ACTIVE_TEXTURE) - GL_TEXTURE0
glBindTexture(GL_TEXTURE_CUBE_MAP,texturecube)
glUniform1i(glGetUniformLocation(program,name),active_texture)
glLibActiveTexture(0)
...drawing with that object crashes with an invalid operation! Two things
will fix it. If the cubemap is not updated before (specifically, no call to
glCopyTexImage2D), the problem does not happen. If another texture (a 2D
one) is passed to active texture 2:
glActiveTexture(num)
active_texture = glGetIntegerv(GL_ACTIVE_TEXTURE) - GL_TEXTURE0
glBindTexture(GL_TEXTURE_2D,texture2d)
glUniform1i(glGetUniformLocation(program,name),active_texture)
glLibActiveTexture(0)
...the problem also goes away.
My question is, why is it doing this? Help?
Thanks,
Ian
|