Archived

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

Custom Vertex Class and Vertex Buffers (glDrawElelemebts)...

This topic is 5751 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

OK, now don''t turn this into flame whether I should name my vertex class vector or vertex Lets say I have a class vertex, which has 3 private members of type float respectively x, y, z. The class also contains color info and few member functions for math etc... Now I also have a class called terrain. This class has an array of type vertex. Of course this array contains all the vertexex of the terrain... I have a draw function, which loops through the vertex array, retrieves the x , y, z values using get methods, stores the values into a float array, then the newly created array is passed to glDrawElements... Is there an overhead when calling this get methods or should I just store the data at load time directly into a float array...

Share this post


Link to post
Share on other sites
I do it the Direct3D way so I can avoid confusing myself when switching between API's. I usually make everything in the vertex a vector and stick it all in one interleaved structure called vertex. The vertex array is then part of a base mesh class from which all other meshes inherit. Use gl*Pointer or glInterleavedArrays to specify the corrext offsets for glDrawElements -- no need to copy into a float array.


struct vector3
{
float x,y,z;
...
};
struct vector2
{
union {
struct {
float u, v;
};
struct {
float x, y;
};
};
...
};
struct vertex {
vector2 texture;
vector3 normal;
vector3 position;
};

class baseMesh {
vertex *vb;
...
};


[edited by - invective on March 18, 2002 4:10:45 PM]

Share this post


Link to post
Share on other sites