PDA

View Full Version : Help Setting up Vertex Arrays

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

glVertexPointer(3,GL_FLOAT,0,Vertices);
glNormalPointer(GL_FLOAT,0,Normals);
glTexCoordPointer(2,GL_FLOAT,0,TexCoords);

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;
}VEC;

typedef struct // for Tex
{
Glfloat u;
GLfloat v;
}TEX;

Can I create an array of these types :

VEC vecArray[MAXVERTS];

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]

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)

Regards

Hlz
09-12-2005, 08:08 PM
http://pyopengl.sourceforge.net/documentation/manual/glDrawElements.3G.html

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.