Jump to content
  • Advertisement
Sign in to follow this  
VansFannel

vertex, normal and texcoordinate indices

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

Hello.

I have a question about glDrawElements and vertex, normal and texcoordinate indices.

If I have geometric vertex, vertex normals and texture vertices, each with its own indices.

Which of those indices may I use?

If I have this code:

glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &teapotVertices[0]);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &teapotNormals[0]);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &teapotTexCoords[0]);

glEnableVertexAttribArray(vertexHandle);
glEnableVertexAttribArray(normalHandle);
glEnableVertexAttribArray(textureCoordHandle);

glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
(GLfloat*)&modelViewProjection.data[0] );
glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
(const GLvoid*) &teapotIndices[0]);

What should hold teapotIndices?

Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Quote:

If I have geometric vertex, vertex normals and texture vertices, each with its own indices.

Which of those indices may I use?


You can't use any of them as is.

You have to generate a new set of data and indices such that vertices, vertex normals, and texture vertices all have the same index. It's not a trivial operation.

If you search here for VBO and OBJ, you'll find that this exact question has been answered and discussed hundreds of times before. Or just use ASSIMP if you don't want to do it yourself.

Share this post


Link to post
Share on other sites
Quote:
Original post by VansFannel
Thanks for your answer but, what should I do?


Quote:
Original post by karwosts
If you search here for VBO and OBJ, you'll find that this exact question has been answered and discussed hundreds of times before.


Search for "vbo obj" returns:

OBJ to indexed VBO - GameDev.Net Discussion Forums
VBO - Vertices, Indices, UVs in one VBO and their indices in ...
Rendering .OBJ Meshes using VBOs - GameDev.Net Discussion Forums
[solved]wavefront obj and vbo/ibo - GameDev.Net Discussion Forums
VBO Loading/Drawing C++ - GameDev.Net Discussion Forums
Opengl going immediate mode to buffered drawing - GameDev.Net ...

and that's just from the first 10 results.

Share this post


Link to post
Share on other sites

I am stupid, but I can't find what I'm looking for.

I'm very very very new on OpenGL ES 2.0 development.

I only want to know if I have to order them.

If have this:

f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3

I must use the following array:

v1/v2/v3 vt1/vt2/vt3 vn1/vn2/vn3

I want to use glDrawElements, so I need indices for its third parameter.

Thanks.

Share this post


Link to post
Share on other sites
The point is that while OBJ files relate to the glBegin/End way, they can't EVER work with newer methods.

Like I posted in the other two threads in this page (sigh...), you must "flatten" them to linear data.
You don't have to do it all the way if you don't need to, of course, since having indices helps the GPU work better with caching, but you need to fix shared data.

A 3D box is an excellent example of a model that must be flattened all the way.
With glBegin/End it could have 8 vertices, texcoords, and normals.
With anything newer it must have 24 of each.

The main difference between, say, the above cube and an actual model is that an actual model is continuous, while a box isn't. A real model usually wont have these "edges", it would be all roundish and in one piece.

This is why while the indices may be different, it is usually just to spare on file size by compacting many values into one.
An example to this would be a big 2D grid, where you might have 1000x1000 vertices and texcoords, but can get along just fine with 1 normal if you didn't edit normals.
In this case, you can just "add" the missing data and fix the indices. This way you will still have at the end a full list of indices, and a working model.

It's easier, however, to just go all the way and completely turn the model into linear data, so I suggest you to do that unless your world is very detailed and actually needs to be efficient.
You can always make it more efficient if you notice this is a bottleneck (remember, optimize when you NEED to, not when you WANT to).

Share this post


Link to post
Share on other sites
A vertex that is at the same location is different if any of its attributes are different, they must be split. It isn't too hard to figure out if you can use one of those vertices, or you need to duplicate and give it new texcoords/normal.

Share this post


Link to post
Share on other sites
Quote:
Original post by VansFannel
Sorry, I've forgotten to metion that I'm working with OpenGL ES 2.0 for Android.


The actual problem (linearizing the data) has nothing to do with this. Do you actually read the comments in this thread? I guess not...

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!