我需要从浮点矩阵([0..1])创建纹理。纹理应该显示一个灰色方块,但只显示一个白色矩形:(
我有这个代码:
def _generate_image(self):
i_len = len(self._data)*Config().get_pixels_per_tile()
j_len = len(self._data[0])*Config().get_pixels_per_tile()
data = ''.join([ chr(int(c*255)) for f in self._data for c in f for _ in range(3*Config().get_pixels_per_tile()) ])
print data
return ImageFromData(data, j_len, i_len, GL_RGB, GL_UNSIGNED_BYTE)
class ImageFromData(object):
def __init__(self, data, width, height, colors, type_):
self.w = width
self.h = height
self.image = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, self.image)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexImage2D( GL_TEXTURE_2D, 0, colors, width, height, 0, colors, type_, data )
谢谢!