Open GL beginner here.. i was just wondering if there is a preferred way to draw geometry.. I've been working through the first 12 or so tutorials at NeHe and the way that they say to draw geometry is by typing:
Code:
glBegin(GL_TRIANGLES);
glColor3ub(255, 0, 0);
glVertexf(-1.0, 0.0, 0.0);
glColor3ub(0, 255, 0);
glVertexf(1.0, 0.0, 0.0);
glColor3ub(0, 0, 255);
glVertexf(0.0, 1, 0.0);
glEnd();
However I have read somewhere that using arrays may speed up things because there is less function calls and it groups all data together?!? Though it just said it might speed up a little. Just wondering how everyone draws their geometry.. I don't want to learn bad habits by using the "wrong"/"slower" way..
Example of arrays:
Code:
static GLubyte colors[] = {255, 0, 0,
0, 255, 0,
0, 0, 255};
static GLfloat vertices[] = {-1.0, 0.0, 0.0,
1.0, 0.0, 0.0,
0.0, 1.0, 0.0};
glEnable(GL_VERTEX_ARRAYS);
glEnable(GL_COLOR_ARRAYS);
glColorPointer(3, GL_UNSIGNED_BYTES, 0, colors);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glDrawArrays(GL_TRIANGLES, 3, ?, ?) // Can't remember last 2 params off the top of my head.
glDisable(GL_VERTEX_ARRAYS);
glDisable(GL_COLOR_ARRAYS);
so which choice would be better/faster? also if arrays are better.. is it better to use separate arrays for colors/vertex/normals/etc.. or mash them into one large array(intertwined)?
thnx in advance for any help...