Skip to content Skip to sidebar Skip to footer

Texture Wrapping An Entire Sphere In Pyopengl

I copied the corrected code here to apply my own texture from a solar imaging dataset onto an OpenGL sphere. In doing so I noticed that the texture does not wrap entirely around th

Solution 1:

To wrap a texture around a sphere you have to distribute the texture coordinates quadratic around the sphere. This is provided by gluNewQuadric, gluQuadricTexture and gluSphere:

class MyWnd:
    def __init__(self):
        self.texture_id = 0
        self.angle = 0

    def run_scene(self):
        glutInit()
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
        glutInitWindowSize(400, 400)
        glutCreateWindow(b'Minimal sphere OpenGL')
        self.lightning()
        self.texture_id = self.read_texture('data/worldmap1.jpg')
        glutDisplayFunc(self.draw_sphere)
        glMatrixMode(GL_PROJECTION)
        gluPerspective(40, 1, 1, 40)
        glutMainLoop()

    def draw_sphere(self):
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        gluLookAt(math.cos(self.angle)*4, math.sin(self.angle)*4, 0, 0, 0, 0, 0, 0, 1)
        self.angle = self.angle+0.04glEnable(GL_DEPTH_TEST)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glBindTexture(GL_TEXTURE_2D, self.texture_id)
    
        glEnable(GL_TEXTURE_2D)

        qobj = gluNewQuadric()
        gluQuadricTexture(qobj, GL_TRUE)
        gluSphere(qobj, 1, 50, 50)
        gluDeleteQuadric(qobj)

        glDisable(GL_TEXTURE_2D)
    
        glutSwapBuffers()
        glutPostRedisplay()        

See the preview:

See also Immediate mode and legacy OpenGL

Post a Comment for "Texture Wrapping An Entire Sphere In Pyopengl"