Drawing Indexed Vertices, Normals, TexCoords, Tangents

Started by
3 comments, last by Geometrian 13 years, 2 months ago
Hi,

I'm trying to get OpenGL to draw some data. There is a list of vertices (3), normals (3), texcoords (2), and tangents (4). I also have a list of vertex indices, normal indices, texcoord indices, and tangent indices--that don't necessarily coincide with each other.

The issue is getting GL to draw these. glDrawArrays simply draws the bound arrays, which doesn't work because the data isn't really ordered, and in any case there aren't duplicates. Using glDrawElements works for vertices, but the normals, texcoords, and tangents are incorrect, because their indices are different. So, what can I do? I don't really want to make completely new arrays; this should be possible. I'm looking for something like:glDrawElements(GL_TRIANGLES,num_indices,GL_UNSIGNED_INT,vert_indices,norm_indices,tex_indices,tan_indices);Which, of course, doesn't exist. Anyway, perhaps someone can tell me an alternate solution?

Thanks!
Ian

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Advertisement
You absolutely cannot do what you're asking.

You must create new arrays, no way around it. All elements must share a single index, that's just how GPU works. Same situation in both DirectX and OpenGL.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Okay, thanks.

Changing the subject to a (related) note:

Getting some NULL pointer-exception type problems with the following draw code:glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, meshes[mesh_index]->vbo_vertices);
glVertexPointer(3,GL_FLOAT,0,NULL);

glEnableClientState(GL_NORMAL_ARRAY);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, meshes[mesh_index]->vbo_normals);
glNormalPointer(GL_FLOAT,0,NULL);

glDrawArrays( meshes[mesh_index]->face_type, 0, meshes[mesh_index]->verts_per_face*meshes[mesh_index]->numof_faces );
Blows up on the last line. [Edit: the glDrawArrays line; problem also occurs when the normal VBO is removed entirely.]

The VBOs were both created with the following function:void make_vbo(GLuint* handle, GLfloat* data, unsigned long data_length) {
glGenBuffers(1,handle);
glBindBuffer(GL_ARRAY_BUFFER,*handle);

glBufferData( GL_ARRAY_BUFFER, sizeof(GLfloat)*data_length, data, GL_STATIC_DRAW );
}


Ideas? Thanks,

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

You're binding vbo_vertices and vbo_normals to GL_ELEMENT_ARRAY_BUFFER, should be just GL_ARRAY_BUFFER (GL_ELEMENT_ARRAY_BUFFER is for indices only, not vertex data).
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
You're binding vbo_vertices and vbo_normals to GL_ELEMENT_ARRAY_BUFFER, should be just GL_ARRAY_BUFFER (GL_ELEMENT_ARRAY_BUFFER is for indices only, not vertex data).
Okay, wow, that was stupid. Sometimes one just doesn't see things after a time . . .

Thanks--everything's working now!

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

This topic is closed to new replies.

Advertisement