Advertisement

OpenGL sharing vertices?

Started by February 29, 2000 03:39 PM
2 comments, last by ECKILLER 24 years, 6 months ago
Hi, Can some tell me how i can reuse or share vertices. For example a cube only has 8 corners but i get a lot more vertices because i duplicate them with each face. Thanks ECKILLER
ECKILLER
Unfortunately, with the cube the vertices cannot be shared since they all have different normals and/or texture coordinates.

A vertex can only be shared among primitives if it has the same properties for all primitives: texture, normal, color etc.

(If you intend to do your own transform and lighting it is possible to share parts of the vertices for example the coordinate. I highly recommend that you don''t do your own transform and lighting as you would miss out on driver and hardware optimizations.)
Advertisement
Actually, that''s not quite correct. You can have the vertices share *some* information (like x/y/z/w coordinates and color), but information like normals and texture-coordinates need to be kept for each individual vertex (24 in the case of the cube).
In C/C++ one way of doing this is using structs, for instance something like this:

struct vector { float x, y, z; };
struct texel { float u, v; };
struct color { float r, g, b; }
struct vertex {
vector *position;
texel texcoord;
};

And then having an array of 8 vectors (one for each corner of the cube), and another array with 24 vertices, with the *position pointing to a vector in the vector-array.

This will f.ex. allow you to move one corner of the cube, and the coordinate-information will be updated for all of the 24 vertices that uses that vector for its corner.

If you''re using OpenGL''s vector-array you''ll have to do it differently though.

Neophyte.

- Death awaits you all with nasty, big, pointy teeth. -
Yup, he''s right. If you want to use vertex arrays you''ll have to duplicate any vertices at shared edges - thats just the way it goes I''m afraid.

Paul Groves.
http://home.clara.net/paulyg
OpenGL for Beginners
Paul Grovespauls opengl page

This topic is closed to new replies.

Advertisement