我正在尝试更改网格的颜色,但它不起作用。请看下面的代码。
typedef struct{
GLubyte red, green, blue, alpha;
} MTcolor;
typedef struct{
GLfloat x, y, z;
} MTvertex;
typedef struct{
MTvertex verts;
MTcolor colors;
} MTmesh;
GLuint vbo;
GLuint ibo;
static const MTmesh mesh[] = {
{ {0, 0, 0}, {0, 0, 255, 255} },
{ {1, 1, 0}, {0, 0, 255, 255} },
{ {2, 0, 0}, {0, 0, 255, 255} }
};
static const GLushort indices[] = {
0, 1, 2
};
制作缓冲区
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(mesh), mesh, GL_STREAM_DRAW);
glGenBuffers(1, &ibo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
使成为
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexPointer(3, GL_FLOAT, sizeof(MTmesh), (void*)offsetof(MTmesh, verts));
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(MTmesh), (void*)offsetof(MTmesh, colors));
我想改变颜色,但它不起作用。有任何想法吗?
MTcolor col[] = {
255, 0, 0, 255,
255, 0, 0, 255,
255, 0, 0, 255
};
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(col), col);
//绑定索引并绘制