1
我試圖讓多通道紋理工作,爲我,但現在我可以簡單的紋理工作,有誰能夠斯波爾怎麼回事用下面的代碼擰乾。這個例子只是將poly表示爲白色,而不是紋理。爲什麼不會這個代碼顯示我的紋理pyopenGL
def loadTexture(name):
img = PIL.Image.open(name) # .jpg, .bmp, etc. also work
img_data = numpy.array(list(img.getdata()), numpy.int8)
id = glGenTextures(1)
glPixelStorei(GL_UNPACK_ALIGNMENT,1)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img.size[0], img.size[1], 0, GL_RGB, GL_UNSIGNED_BYTE, img_data)
return id
....
tex = loadTexture(/foobar.png)
....
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glTranslate(0.0, 0.0, -600)
glScale(50.0, 50.0, 50.0)
glRotate(90, 0.0, 0.0, 0.0)
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, tex)
glBegin(GL_TRIANGLES)
....
glEnd()
它以什麼方式不起作用?你期望看到什麼,你真正看到了什麼? – 2012-02-23 23:53:44
更新,希望這更有意義,謝謝 – 2012-02-23 23:55:11