Archived

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

OGL Vertex Arrays

This topic is 6165 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites