Jump to content
  • Advertisement
Sign in to follow this  
amigocz

OpenGL VBO and Vertex format

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

Hi, I'm quite new to OpenGL but I have some experience with Direct3D. Right now I'm working with VBO and I would like to know If there is some way how to define the vertex format similiary as in Direct3D (using Vertex declaration or Flexible vertex format). I want to have all data in one structure (position, color, ...) and I don't really like the way I saw doing it ( glInterleavedArrays(GL_C3F_V3F, 0, intertwined); ). I need something more flexible.

Share this post


Link to post
Share on other sites
Advertisement
OpenGL has no equivalent structure to Direct3D's vertex declarations right off the bat but you can manually mimic the behavior with glVertexPointer, glColorPointer, glNormalPointer and glTexCoordPointer set of APIs and their stride parameter which let you specify the byte offset between consecutive array elements to implicitly define the vertex format. So the answer is yes, it's possible, but it's done differently.

Share this post


Link to post
Share on other sites
glInterleavedArrays is not used by most applications and can be considered obsolete. Do what Ashkan says.

Share this post


Link to post
Share on other sites
Here's an example:

struct Vertex
{
float x, y, z, nx, ny, nx, tx, ty;
};

struct Vertex verticies[] = ...;

glTexCoordPointer(2, GL_FLOAT, sizeof(struct Vertex), &verticies[0].tx);
glNormalPointer(GL_FLOAT, sizeof(struct Vertex), &verticies[0].nx);
glVertexPointer(3, GL_FLOAT, sizeof(struct Vertex), &verticies[0].x);

Regards
elFarto

Share this post


Link to post
Share on other sites
I created my own VertexBuffer class that uses a description similar to D3D FVF. You can use a set of flags that define the vertex structure and the VertexBuffer takes care of the rest. The only limitation is the order of the components which is fixed.

Behind the scenes the FVF is decompiled and the vertex size as well as the offset of each component is calculated. When the buffer is bound the corresponding glXxxxPointer() calls are issued.

Share this post


Link to post
Share on other sites
Thanks for replies. I designed my own vertex declaration and created own Vertex buffer class. Creating vertex buffer and including data seems to be working but I have some difficulties with rendering.

If I want to draw one single triangle using function glDrawArrays do I have to pass 1 or 3 as the third parameter? If I pass 1 I can't see anything and if I pass 3 this function crashes (reading location 0x000..)

glDrawArrays(GL_TRIANGLES, 0, 1);

It also crashes if I trie to draw points this way instead of triangles.
Mapping and unmapping the buffer seems to be working.

Share this post


Link to post
Share on other sites
I figured it out. I had enabled more client states (glEnableClientState) than I was using so that caused crashes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!