• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# OGL Vertex Arrays

## Recommended Posts

ZubZorro    122
I''m trying to use those vertex arrays, but they wont work, and I cant seem to figure out what i am doing wrong: i have my vertex struct where i store my vertices in, my triangle class which has the indices: i store all my vertices in a vertex array "vertices" and all my triangles in a "triangles":
struct vertex{
float values[3];
};

class triangle{
public:
unsigned short indices[3];
};

vertex* vertices;
triangle* triangles;

now i try to create a vertex array with the following code:
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,sizeof(vertex),vertices[0].values);

and when i try to draw with the "glArrayElement" command:
glBegin(GL_TRIANGLES);
for(int i = 0;i < noOfTriangles;i++){
glArrayElement(triangles.indices[0]);
glArrayElement(triangles[i].indices[1]);
glArrayElement(triangles[i].indices[2]);
}
glEnd();

i End up with nothing! what is wrong? i''ve been staring at this code too long, hope someone will enlighten me Jonas

##### Share on other sites
WhatEver    125
Try changing this:
glVertexPointer(3,GL_FLOAT,sizeof(vertex),vertices[0].values);

to this:
glVertexPointer(3,GL_FLOAT,0,vertices[0].values);

Where the zero is is the stride. You''re not using interlived arrays so you don''t need to bother with that.

##### Share on other sites
WhatEver    125
Whoa! One other thing:

for(int i = 0;i < noOfTriangles;i++){
glArrayElement(triangles.indices[0]);
glArrayElement(triangles.indices[1]);
glArrayElement(triangles[i].indices[2]);
}

You didn''t place ''[i]'' on the first triangle.

##### Share on other sites
ZubZorro    122
Ehm i solved the problem.

It was a mistake by my fault, i was enabling the vertex arrays before i actually created the GL window...
if i create it after all my initialization it works fine.

sorry, and thanks anyways

Jonas