我仍在尝试掌握使用纹理,现在我正在尝试使用 glTexCoordPointer 为每个顶点赋予特定于其类的颜色。我做了一些检查,情况如下:
self.bufferVertices = glGenBuffersARB(1)
glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.bufferVertices)
glBufferDataARB(GL_ARRAY_BUFFER_ARB, ADT.arrayByteCount(vertices), ADT.voidDataPointer(vertices), GL_STATIC_DRAW_ARB)
self.vertices = vertices
self.bufferNormals = glGenBuffersARB(1)
glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.bufferNormals)
glBufferDataARB(GL_ARRAY_BUFFER_ARB, ADT.arrayByteCount(normals), ADT.voidDataPointer(normals), GL_STATIC_DRAW_ARB)
self.normals = normals
self.triangles = triangles
textureIndexes = []
for int in areas:
textureIndexes.append(float(int)/190.0)
print str(int) + " " + str(float(int)/190)
print str(len(self.vertices)) + str(len(textureIndexes))
self.bufferTextureIndex = glGenBuffersARB(1)
glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.bufferTextureIndex)
glBufferDataARB(GL_ARRAY_BUFFER_ARB, ADT.arrayByteCount(numpy.array(textureIndexes,dtype=numpy.float32)), ADT.voidDataPointer(numpy.array(textureIndexes,dtype=numpy.float32)), GL_STATIC_DRAW_ARB)
for color in textureArray:
print str(color)
self.texture = glGenTextures(1)
glBindTexture(GL_TEXTURE_1D, self.texture)
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT)
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_REPEAT)
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 190, 0, GL_RGB , GL_FLOAT, textureArray)
所以我为顶点、法线、三角形和纹理索引生成我的 VBO。现在我想检查我得到的纹理索引值,所有这些值都来自区间 [0..1] 和纹理索引的长度 = 长度(顶点)/3。
对于纹理,我生成一个 textureArray,它是一个包含 190 个 [x,x,x] rgb 值的向量。我什至把它分成6等份。所以前 1/6 条目是一种颜色,然后是另一种颜色,以此类推,只是为了简化我的测试。
现在画图:
glEnableClientState(GL_VERTEX_ARRAY)
glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.bufferVertices)
glVertexPointer(3, GL_FLOAT, 0, None)
glEnableClientState(GL_NORMAL_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.bufferNormals)
glNormalPointer(GL_FLOAT, 0, None)
glEnableClientState(GL_TEXTURE_COORD_ARRAY)
glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.bufferTextureIndex)
glTexCoordPointer(1, GL_FLOAT, 0, None);
glBindTexture(GL_TEXTURE_1D, self.texture)
glEnable(GL_TEXTURE_1D)
glClientActiveTexture(GL_TEXTURE0);
glDrawElements(GL_TRIANGLES, len(self.triangles) , GL_UNSIGNED_SHORT, ADT.voidDataPointer(self.triangles))
但是所有的点都变成了相同的颜色,对应于我纹理的前 1/6 部分的颜色。任何输入将不胜感激。