Hi, I’ve been trying to create a sphere with texture mapping. The sphere seems to rotate, but texture does not rotate along. If there is a cube instead (with same texture settings), then the texture seems to rotate. I really with to rotate some spheres with textures
Below is my initialization and display code. Please let me know what i may be doing wrong, thanks.
# INITIALIZATION
# set viewing projection
glMatrixMode(GL_PROJECTION)
glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0)
# position viewer
glMatrixMode(GL_MODELVIEW)
glTranslatef(0.0, 0.0, -2.0)
# position object
glRotatef(self.y, 1.0, 0.0, 0.0)
glRotatef(self.x, 0.0, 1.0, 0.0)
glEnable(GL_DEPTH_TEST)
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
texture = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, texture)
#glBindTexture(GL_TEXTURE_3D, texture)
#glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
#glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, earth_img.size[0], earth_img.size[1], 0, GL_RGB, GL_UNSIGNED_BYTE, earth_img_data)
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glEnable(GL_TEXTURE_GEN_S)
glEnable(GL_TEXTURE_GEN_T)
glEnable(GL_TEXTURE_2D)
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
# DISPLAY CODE
# clear color and depth buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
#glutSolidCube(0.5)
if self.size is None:
self.size = self.GetClientSize()
w, h = self.size
w = max(w, 1.0)
h = max(h, 1.0)
xScale = 180.0 / w
yScale = 180.0 / h
glEnable(GL_TEXTURE_2D)
glTranslatef(0.0, 0.0, -2.0)
#glRotatef((self.y - self.lasty) * yScale, 1.0, 0.0, 0.0);
glRotatef((self.x - self.lastx) * xScale, 0.0, 1.0, 0.0);
glColor3f(1,1,1)
glutSolidSphere(0.4, 20, 20)
glDisable(GL_TEXTURE_2D)
#glRotatef(0.01, 1.0, 0.0, 0.0);
self.SwapBuffers()