GameMaker: you wrote;
Is it faster to just >duplicate a lot of it and just do >glDrawElement many times?
It is probably easist to illustrate with an example. heres a cube I made.
= static GLfloat vertex[]
=1.0 ,1.0,1.0,
-1.0, 1.0, -1.0,
-1.0, -1.0, -1.0,
-1.0, -1.0, 1.0,
1.0, 1.0, 1.0, 1.0, -1.0, 1.0,
1.0, -1.0, -1.0,
1.0, 1.0, -1.0,
1.0, 1.0, 1.0,
-1.0, 1.0, 1.0,
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
1.0, 1.0, -1.0,
-1.0, 1.0, -1.0,
-1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
1.0, 1.0, 1.0,
1.0, 1.0, -1.0,
-1.0, 1.0, -1.0,
-1.0, 1.0, 1.0,
1.0, -1.0, 1.0,
-1.0, -1.0, 1.0,
-1.0, -1.0, -1.0,
1.0, -1.0, -1.0 };
static GLfloat normal[] = {-1.0, 0.0, 0.0,
-1.0, 0.0, 0.0,
-1.0, 0.0, 0.0,
-1.0, 0.0, 0.0,
1.0, 0.0, 0.0,
1.0, 0.0, 0.0,
1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, -1.0,
0.0, 0.0, -1.0,
0.0, 0.0, -1.0,
0.0, 0.0, -1.0,
0.0, 1.0, 0.0,
0.0, 1.0, 0.0,
0.0, 1.0, 0.0,
0.0, 1.0, 0.0,
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
0.0, -1.0, 0.0};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer (3, GL_FLOAT, 0, vertex);
glNormalPointer (GL_FLOAT, 0, normal);
GLubyte redindices[] = {0, 1, 2, 3};
GLubyte grnindices[] = {4, 5, 6, 7};
GLubyte pnkindices[] = {8, 9, 10, 11};
GLubyte Lblindices[] = {12, 13, 14, 15};
GLubyte yindices[] = {16, 17, 18, 19};
GLubyte blindices[] = {20, 21, 22, 23};
glMaterialfv(GL_FRONT, GL_AMBIENT, rd_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, rd_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, rd_specular);
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, redindices);
and so on for the other faces.
(each face has a different colour but if all sides had the same colour or if you were using textures intead of material properties
then you could crunch those arrays of indices,(grnindices, redindices etc)
into one array and make only one call to
glDrawElements.
BUt ryo’s face sorting idea is good for if u r using material properties.
I fully recommend looking at the red book
on the web though for a more thorough explanation. just type ‘OpenGL programming guide’ or’ red book’into google ,which should give a bunch of sites that keep the red book online.
Woden.