OpenGL drawing w/ Arrays or not? [Archive] - C Board

PDA

View Full Version : OpenGL drawing w/ Arrays or not?


tegwin
01-14-2003, 11:51 AM
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:


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:

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...

MrWizard
01-14-2003, 03:23 PM
I'll give you a Performance FAQ from the OpenGL SDK. This will answer your questions.

Note: I bet a lot of people would find this useful? Sticky?

tegwin
01-14-2003, 03:31 PM
Yes that is very very useful.. just what I needed.. thnx mate.. good reference sheet..:D