Pyglet OpenGL绑定纹理

时间:2017-05-20 00:28:42

标签: python opengl draw pyglet

我正在尝试将纹理绑定到Pyglet中的OpenGL。我无法在四边形上绘制纹理,它只是绘制一个白色四边形。我正在使用以下命令绑定id:

myimage = pyglet.image.load("filename.png").get_texture()
...
def on_draw(self):
    glEnable(GL_TEXTURE_2D)
    glBindTexture(GL_TEXTURE_2D, myimage.id)
    self.planet.draw()
    glBindTexture(GL_TEXTURE_2D, 0)
    glDisable(GL_TEXTURE_2D)

它将它绘制在没有纹理的正确位置。这是我的行星类,其顶点,纹理坐标和绘制函数:

class Planet():
 def __init__(self):
    self.planet_x = 100
    self.planet_z = 100
    self.sky_height = 300

    self.setPlanet([0,0,0])
    self.planet_texcoords = [(0,0,0), (1,0,0), (1,0,1), (0,0,1)]

 def setPlanet(self, ppos):
    self.planet_x = ppos[0] + 100
    self.planet_z = ppos[2] + 100
    self.planet_nx = ppos[0] - 100
    self.planet_nz = ppos[2] - 100
    self.sky_height = ppos[1] + 300

    self.planet_verticies = [(self.planet_nx,self.sky_height,self.planet_nz,), 
                            (self.planet_x,self.sky_height,self.planet_nz,),
                            (self.planet_x,self.sky_height,self.planet_z,),
                            (self.planet_nx,self.sky_height,self.planet_z)]
def draw(self):
    glBegin(GL_QUADS)
    glTexCoord3i(self.planet_texcoords[0][0], self.planet_texcoords[0][1], self.planet_texcoords[0][2])
    glVertex3f(self.planet_verticies[0][0], self.planet_verticies[0][1], self.planet_verticies[0][2])
    glTexCoord3i(self.planet_texcoords[1][0], self.planet_texcoords[1][1], self.planet_texcoords[1][2])
    glVertex3f(self.planet_verticies[1][0], self.planet_verticies[1][1], self.planet_verticies[1][2])
    glTexCoord3i(self.planet_texcoords[2][0], self.planet_texcoords[2][1], self.planet_texcoords[2][2])
    glVertex3f(self.planet_verticies[2][0], self.planet_verticies[2][1], self.planet_verticies[2][2])
    glTexCoord3i(self.planet_texcoords[3][0], self.planet_texcoords[3][1], self.planet_texcoords[3][2])
    glVertex3f(self.planet_verticies[3][0], self.planet_verticies[3][1], self.planet_verticies[3][2])
    glEnd()

0 个答案:

没有答案