Forums.ATC.no
Teknisk => Generelt teknisk => Emne startet av: ATC på 27. ſeptember 2008, 18:24 pm
-
The OpenGL man page for glDrawElements() confused me greatly because it introduces a concept of "indices". Unfortunately, it leaves the reader with no clue as to what exactly is supposed to be indexed, and there is no example code illustrating the relationship between the various tables.
-
void example_DrawElements()
{
GLfloat vertices[] = {
0,0,0,1,
0,0,0,1,
0,0,0,1
};
GLfloat colors[] = {
0,0,0,1,
0,0,0,1,
0,0,0,1
};
GLfloat texcoords[] = {
0,0,0,1,
0,0,0,1,
0,0,0,1
};
GLfloat vertex_normals[] = {
0,0,0,
0,0,0,
0,0,0
};
GLushort faces[] = {
0,1,2
};
int triangles = 1;
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(4, GL_FLOAT, 0, vertices); // x,y,z,w
glColorPointer(4, GL_FLOAT, 0, colors); // r,g,b,a
glTexCoordPointer(4, GL_FLOAT, 0, texcoords); // t,s,r,q
glNormalPointer(GL_FLOAT, 0, vertex_normals); // x,y,z
glDrawElements(GL_TRIANGLES, triangles * 3, GL_UNSIGNED_SHORT, faces);
}