Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we get Indices for glDrawElements()?

I'm trying to use the Assimp library to import models to a rudimentary OpenGL application with VBO use.

If I understand it correctly glDrawElements is one of the ideal modern ways to draw things.

But how do we get that information from a generic import library?

If you have specific Assimp library knowledge it's appreciated.

--

What is generally the process to generate these?

like image 784
j riv Avatar asked Aug 27 '10 17:08

j riv


People also ask

What is indices in OpenGL?

Indices is defined as a GLubyte array of 48 elements; GLubyte is the OpenGL data type for an unsigned byte ( unsigned char ). You could use any of the following unsigned integral OpenGL data types: GLubyte , GLushort , and GLuint , since indices are never negative (signed) or fractional (float/double).

What is the difference between glDrawArrays() and glDrawElements()?

What's the difference between glDrawArrays and glDrawElements ? Can anyone help me? glDrawArrays submits the vertices in linear order, as they are stored in the vertex arrays. With glDrawElements you have to supply an index buffer.

What is glDrawElements?

When glDrawElements is called, it uses count sequential elements from an enabled array, starting at indices to construct a sequence of geometric primitives. mode specifies what kind of primitives are constructed and how the array elements construct these primitives. If more than one array is enabled, each is used.

What is an index Buffer?

An index buffer is essentially an array of pointers into the vertex buffer. It allows you to reorder the vertex data, and reuse existing data for multiple vertices.


1 Answers

Collect all indices from aiMesh::mFaces in a single buffer. Make sure to pass aiProcess_Triangulate to Assimp as postprocessing flag (amongst aiProcess_JoinVertices and whatever seems useful to you), and skip over points and lines or handle them separately.

The various data streams in aiMesh - such as aiMesh::mVertices and aiMesh::mNormals need to be set as GL input data streams (glVertexPointer, ...).

like image 161
Alexander Gessler Avatar answered Oct 01 '22 03:10

Alexander Gessler