Jump to content
  • Advertisement
Sign in to follow this  
Geometrian

OpenGL Drawing Indexed Vertices, Normals, TexCoords, Tangents

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

Share this post


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

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: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,

Share this post


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

Share this post


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

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!