vertex, normal and texcoordinate indices

Started by
13 comments, last by VansFannel 13 years, 4 months ago
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.
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.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Thanks for your answer but, what should I do? I must order them for each vertex, texcoord and normal...
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.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game

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.
The indices should be the same for all 3 parameters. Maybe you could use interleaved data.
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).
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.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Sorry, I've forgotten to metion that I'm working with OpenGL ES 2.0 for Android.
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...

This topic is closed to new replies.

Advertisement