View Full Version : Help Setting up Vertex Arrays

09-12-2005, 12:30 PM
I'm calling:


But keep getting segfaults. The sizes for all the arrays have to be the same don't they ? So if I have a 4X4 grid that means 16 verts 16 Normals (Vert Norms) and 16 Tex Coords - one for each vert ? I have a struct for each aray:

typedef struct // for Verts and Norms and tris
Glfloat x;
GLfloat y;
GLfloat z;

typedef struct // for Tex
Glfloat u;
GLfloat v;

Can I create an array of these types :


and put my values in there? or are you not to use User defined types and just put the vert x,y,z into a normal 1D array sequentially

float vecArray[MAXVERTS]

What about drawing Triangles ?

glDrawElements(GL_TRIANGLES,numTriangles,GL_FLOAT, Triangles);

If I fill my triangle array, does numTriangles become 18 for a 4x4 vert grid ? or numverts * 3 (Which I've seen done..if numverts is 16)


09-12-2005, 08:08 PM

For starters, you need to pass the number of elements, not primitives, and GL_FLOAT isn't a valid enum (try GL_UNSIGNED_SHORT) :-)

Yeah, the array sizes need to be the same, since you'll be indexing them with the same indices. Make sure your indices are in range.

For 4x4 QUADS, you'll need 5x5 vertices. Use triangle strips if possible, for speed.