c++ - OpenGL - Index buffers difficulties -


I have a custom file format that has all the necessary information for 3D mash (exported from 3ds max) Data for top indices and normals is extracted.

I pass OpenGL through top data, top index and normal data and I call glDrawElements (GL_TRIANGLES, ...)

to call Something looks fine but in general the problem is that there are different indices of normal and because OpenGL can only use an index buffer, it uses index buffer for both the corners and the normal.

If you tell me about this problem, I would be really grateful.

The important thing to note is that the top / normal data is "not sorted" and therefore I use the glDrawArrays (GL_TRIANGLES, ...) functionality I am unable to present T correctly?

Is there any way / algorithm that I can use to sort the data so that the mash is glDrawArrays (GL_TRIANGLES, ..) < Can be prepared correctly with / code>? But if there is also an algorithm, then there is another problem - I have to copy some corner (because there are unique corners in my top buffer - for example if you have a cube then only 8 verticals in my buffer) and believe me Do not have to do this.

The file type using different indices for the corners and normals does not match the OpenGL header Models are very straightforward as you have seen, OpenGL uses a single index.

What you need to do is create an OpenGL vertex for each unique (top index, normal index) pair in your input. It works a bit, but is not very difficult, especially if you use the available data structure as a STL map in the form of key (top index, normal index) pair, good for it Works the way I am not providing the full C ++ code, but I can sketch it.

Suppose that you have already read any of your angles in the array / vector data structure inVertices , where the index with vertexIdx Coordinates for inVertices [vertexIdx] are stored in. The only thing for Normals, where the index is stored in the normal vector inNormals [normalIdx] with the normal indices .

Now with each list of a triangle given by a list of your triangles, a vertexIdx and normalIdx We will create a new joint vectors array / vector with both top and normal coordinates, as well as a new joint index index list. Pseudo code:

  nextCombinedIdx = 0 indexMap = In the input file loop on the 3 corners of the triangle, Vertex reads the rectangle and normal id for the empty loop angle if indexMap.contains (Key (VertixIDx, normal) IDX)) then combined Idx = indexMap.get (Key (Vertix IDX, Normal IDX), and Combined IDX = Next Indexed IndexMap.ad (Key (Vertix IDX, General IDX), United IDX) Alley combinedIdx = Aglakanbeededaidaks + 1 Snyuktwartis.ad (Inwaritis [Warteksaidaks] Inrormals [General Aidaks] Finally ifIndices.add (combinedIdx) end loop end loop  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -