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值,所有值都来自区间[0..1]和textureIndexes的长度= length(vertices)/3。
对于纹理,我生成一个textureArray,它是一个向量190 个 [x,x,x] RGB 值。我什至把它分成了六等份。因此,前 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 部分的颜色。任何意见将不胜感激。
I'm still trying to get a grasp of using textures and now I'm trying to use glTexCoordPointer in order to give each vertex a color specific to it's class. I've made some checks and here is the situation:
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)
So I generate my VBO's for vertices, normals, triangles and textureIndexes. Now I wanted to check the value I'm getting for textureIndexes, all are from the interval [0..1] and the length of textureIndexes = length ( vertices ) / 3.
For the texture, I generate a textureArray which is a vector of 190 [x,x,x] rgb values. I've even split it in 6 equal parts. So the first 1/6 entries are one color the next another and so on just to simplify my testing.
Now for the drawing:
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))
But all the points are turning out the same color, corresponding to the color of the first 1/6 part of my texture. Any input would be really appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很惊讶它居然能画出任何东西。下面一行有一个错误:
OpenGL 规范要求纹理的大小是 2 的幂。如果用 256 或 64 替换 190,可能会得到更好的结果。
I'm surprised it is drawing anything at all. On the following line there is a mistake:
The OpenGL spec requires that the size of the texture is a power of two. If you replace the 190 with a 256 or a 64, you may get better results.