Code c++ :
enum {
vertex = 0,
INDEX = 1,
TEXCOORD = 2
};
GLsizeiptr VertSz = 8 * 3 * sizeof(GLfloat);
GLfloat VertData[] = {
-1.0f,-1.0f, 1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
1.0f,-1.0f, 1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f,-1.0f,
1.0f, 1.0f, 1.0f,};
GLsizeiptr IndexSz = 6 * 6 * sizeof(GLubyte);
GLubyte IndexData[] = {
1,0,2,
3,2,0,
5,6,4,
7,4,6,
7,3,4,
0,4,3,
6,1,2,
5,1,6,
3,7,2,
6,2,7,
1,5,0,
4,0,5,};
GLsizeiptr CoordsSz = 8 * 2 * sizeof(GLfloat);
GLfloat CoordsData[] = {
0.0f,0.0f, 1.0f,0.0f, 1.0f,1.0f, 0.0f,1.0f,
1.0f,0.0f, 0.0f,0.0f, 0.0f,1.0f, 1.0f,1.0f,
1.0f,0.0f, 0.0f,1.0f, 1.0f,0.0f, 1.0f,0.0f,
0.0f,0.0f, 0.0f,1.0f, 1.0f,1.0f, 1.0f,0.0f,};
int BufferSz = 3;
GLuint BuffersId[BufferSz];
GLsizei VertexCount = 8;
GLsizei IndexCount = 36;
void End() {
glDeleteBuffers(BufferSz, BufferName);
}
void Render(Vec3f *pos, Vec3f *rot) {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
glRotatef(rot->x, 1,0,0);
glRotatef(rot->y, 0,1,0);
glRotatef(rot->z, 0,0,1);
glTranslatef(pos->x, pos->y, pos->z);
glBindBufferARB(GL_ARRAY_BUFFER, BuffersId[vertex]);
glBufferDataARB(GL_ARRAY_BUFFER, VertexSz, VertexData, GL_STREAM_DRAW);
glVertexPointer(3, GL_FLOAT, 0, 0);
glBindBufferARB(GL_ARRAY_BUFFER, BuffersId[INDEX]);
glBufferDataARB(GL_ARRAY_BUFFER, IndexSz, IndexData, GL_STREAM_DRAW);
glIndexPointer(GL_UNSIGNED_BYTE, 0, 0);
glBindBufferARB(GL_ARRAY_BUFFER, BuffersId[TEXCOORD]);
glBufferDataARB(GL_ARRAY_BUFFER, CoordsSz, CoordsData, GL_STREAM_DRAW);
glTexCoordPointer(2, GL_FLOAT, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_INDEX_ARRAY);
glDrawElements(GL_TRIANGLES, IndexCount, GL_UNSIGNED_BYTE, IndexData);
glDisableClientState(GL_INDEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
}