Sign in to follow this  
Geometrian

OpenGL Drawing Indexed Vertices, Normals, TexCoords, Tangents

Recommended Posts

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:[code]glDrawElements(GL_TRIANGLES,num_indices,GL_UNSIGNED_INT,vert_indices,norm_indices,tex_indices,tan_indices);[/code]Which, of course, doesn't exist. Anyway, perhaps someone can tell me an alternate solution?

Thanks!
Ian

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Okay, thanks.

Changing the subject to a (related) note:

Getting some NULL pointer-exception type problems with the following draw code:[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 );[/code]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:[code]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 );
}[/code]

Ideas? Thanks,

Share this post


Link to post
Share on other sites
You're binding vbo_vertices and vbo_normals to GL[b]_ELEMENT[/b]_ARRAY_BUFFER, should be just GL_ARRAY_BUFFER (GL_ELEMENT_ARRAY_BUFFER is for indices only, not vertex data).

Share this post


Link to post
Share on other sites
[quote name='karwosts' timestamp='1298091129' post='4776208']You're binding vbo_vertices and vbo_normals to GL[b]_ELEMENT[/b]_ARRAY_BUFFER, should be just GL_ARRAY_BUFFER (GL_ELEMENT_ARRAY_BUFFER is for indices only, not vertex data).[/quote]Okay, wow, that was stupid. Sometimes one just doesn't see things after a time . . .

Thanks--everything's working now!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this