我仍然試圖掌握使用紋理,現在我試圖使用glTexCoordPointer爲每個頂點賦予一個特定於它的類的顏色。我做了一些檢查,這裏的情況是: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對頂點,法線,三角形和textureIndexes。現在我想檢查我得到的textureIndexes的值,全部來自區間[0..1]和textureIndexes = length(vertices)/ 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的顏色。任何輸入將非常感激。
你剛剛重新啓動你的問題? – 2011-06-02 12:41:50
確切的重複:http://stackoverflow.com/questions/6185478/opengl-textures-beginner-question – 2011-06-02 12:43:05