开发者

glTexCoordPointer seems to have no effect

开发者 https://www.devze.com 2023-03-10 03:38 出处:网络
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 specifi开发者_StackOverflow中文版c to it\'s class. I\'ve made some

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 specifi开发者_StackOverflow中文版c 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.


I'm surprised it is drawing anything at all. On the following line there is a mistake:

    glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 190, 0, GL_RGB , GL_FLOAT, textureArray)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号