在“readu texture()`中,生成纹理名称后,不绑定它。所以呢
随后与纹理相关的调用将转到默认纹理,而不是
新创建的纹理。
texture_id = glGenTextures(1)glBindTexture(GL_TEXTURE_2D, texture_id) # This is what's missing
因为你的图片是PNG图片。然后
list(img.getdata获取数据())将是一个
包含
(R,G,B,A)‘的元组列表。所以打电话给“glTexImage2D”时
需要告诉您的数据是“GLu RGBA”而不是“GLu RGB”。
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img.size[0], img.size[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, img_data)
You can also automate it.
format = GL_RGB if img.mode == "RGB" else GL_RGBAglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img.size[0], img.size[1], 0, format, GL_UNSIGNED_BYTE, img_data)
You can also convert it to not have an alpha channel.
img = img.convert("RGB")当然,在打电话之前需要做些什么img.getdata获取数据()
.
也是一个重要的注意事项。您正在“drawu sphere()”中调用“readu texture()”。
这意味着每次调用“drawu sphere()”时,都会加载图像并
将创建新纹理。你真的不想那么做。而不是以前
调用
glutMainLoop()call
readu texture()并将结果存储为
全局名称。



