Hi,
I have a 3D matrix of floating point intensity values that I want to map on a cube in order to render them on my screen, and apply rotations, translations, using MIP projection. From what I have seen in tutorials, I got the following code (in Python):
def LoadGLTextures(fname):
# Load Texture
image1 = loadImage(fname)
# Create Textures
texture = glGenTextures(1)
# Linear interpolation
glBindTexture(GL_TEXTURE_3D, texture)
#glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE )
glTexParameterf( GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE )
glTexParameterf( GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE )
glTexParameterf( GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE )
glTexParameterf( GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR )
glTexParameterf( GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR )
glTexImage3D(GL_TEXTURE_3D,0,GL_LUMINANCE,image1.sizeX,image1.sizeY,image1.sizeZ,0, GL_LUMINANCE,GL_FLOAT,image1.data)
return texture
def DrawGLScene(self):
#With resize, we already are in MODELVIEW mode
#Clear the buffers we will write into
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
#Reinitialize all the transformations (previous are cancelled)
glLoadIdentity()
#Defines which one of the textures we are going to use
glBindTexture(GL_TEXTURE_3D, self.textures)
#My object is defined by the coordinates [-1,1;-1,1;-1,1]
#Zero is the center, and I am in orhographic projection, so no in depth
#translation needed
glTranslatef(0.0,0.0,0.0)
#Rotate the volume
glRotatef(self.yzrotation,1.0,0.0,0.0)
glRotatef(self.xzrotation,0.0,1.0,0.0)
glRotatef(self.xyrotation,0.0,0.0,1.0)
#My "cube" is defined by 6 independent faces, that I assemble like a
#cube.
glBegin(GL_QUADS)
glNormal3f(0.0,0.0,1.0)
glTexCoord3f(0.99,0.99,0.99)
glVertex3f(0.99,0.99,0.99)
glTexCoord3f(-0.99,0.99,0.99)
glVertex3f(-0.99,0.99,0.99)
glTexCoord3f(-0.99,-0.99,0.99)
glVertex3f(-0.99,-0.99,0.99)
glTexCoord3f(0.99,-0.99,0.99)
glVertex3f(0.99,-0.99,0.99)
glNormal3f(0.0,0.0,-1.0)
glTexCoord3f(0.99,0.99,-0.99)
glVertex3f(0.99,0.99,-0.99)
glTexCoord3f(-0.99,0.99,-0.99)
glVertex3f(-0.99,0.99,-0.99)
glTexCoord3f(-0.99,-0.99,-0.99)
glVertex3f(-0.99,-0.99,-0.99)
glTexCoord3f(0.99,-0.99,-0.99)
glVertex3f(0.99,-0.99,-0.99)
glNormal3f(0.0,1.0,0.0)
glTexCoord3f(0.99,0.99,0.99)
glVertex3f(0.99,0.99,0.99)
glTexCoord3f(-0.99,0.99,0.99)
glVertex3f(-0.99,0.99,0.99)
glTexCoord3f(-0.99,0.99,-0.99)
glVertex3f(-0.99,0.99,-0.99)
glTexCoord3f(0.99,0.99,-0.99)
glVertex3f(0.99,0.99,-0.99)
glNormal3f(0.0,-1.0,0.0)
glTexCoord3f(0.99,-0.99,0.99)
glVertex3f(0.99,-0.99,0.99)
glTexCoord3f(-0.99,-0.99,0.99)
glVertex3f(-0.99,-0.99,0.99)
glTexCoord3f(-0.99,-0.99,-0.99)
glVertex3f(-0.99,-0.99,-0.99)
glTexCoord3f(0.99,-0.99,-0.99)
glVertex3f(0.99,-0.99,-0.99)
glNormal3f(1.0,0.0,0.0)
glTexCoord3f(0.99,0.99,0.99)
glVertex3f(0.99,0.99,0.99)
glTexCoord3f(0.99,-0.99,0.99)
glVertex3f(0.99,-0.99,0.99)
glTexCoord3f(0.99,-0.99,-0.99)
glVertex3f(0.99,-0.99,-0.99)
glTexCoord3f(0.99,0.99,-0.99)
glVertex3f(0.99,0.99,-0.99)
glNormal3f(-1.0,0.0,0.0)
glTexCoord3f(-0.99,0.99,0.99)
glVertex3f(-0.99,0.99,0.99)
glTexCoord3f(-0.99,-0.99,0.99)
glVertex3f(-0.99,-0.99,0.99)
glTexCoord3f(-0.99,-0.99,-0.99)
glVertex3f(-0.99,-0.99,-0.99)
glTexCoord3f(-0.99,0.99,-0.99)
glVertex3f(-0.99,0.99,-0.99)
glEnd()
My problem is that the texture is represented 4 times when rendered : Dropbox - Error, and I don’t understand why.
Could you help me with this?
Thanks!