Easiest to load with OpenGL blender export format

Started by
0 comments, last by VansFannel 13 years, 4 months ago
Hello.

I'm developing an OpenGL ES 2.0 application with C++.

I want to show my blender's models using OpenGL but I don't know which is the easiest format to load with OpenGL ES 2.0.

I've been trying with Wavefront obj format how to unpacked vertices and how to obtain vertices for glDrawElements' last parameter.

Doy you know an easiest format?

Thanks.
Advertisement
OBJ is more or less as simple as it can get, as far as the parsing is concerned. However, the aftermath is admittedly somewhat painful due to (2). If you don't really have to write your own, I'd suggest saving that trouble and using an already working OBJ loader, because it is really not much fun.

There are two important gotchas:
(1) indices start with 1, not with 0 as a normal thinking person would expect
(2) you must duplicate vertex data if vertices (edit, wrong wording) don't share normals or texcoords

(1) is truly stupid, there is no good reason why it should be like this. Alas, you just have to know (otherwise you will always wonder why your models look broken).

(2) is a kind of compression stragegy, but it is annoying insofar as all graphics APIs expect one vertex to have exactly one normal and exactly one texture coordinate pair (or more, but always a constant number). Which means that you have to manually generate unique vertices from the data.
In the easiest case, you will just generate one vertex from each combination of coordinates that you're given by the file. This will give you duplicates, but will work. If you don't want any duplicates, it gets a lot more work.

As for your question regarding indices (last param to glDrawElements), you get those for "free" when generating your unique vertices, by writing them into a std::vector and using the index position as the index value in your index buffer (instead of any values in the OBJ file).

[Edited by - samoth on December 8, 2010 3:04:16 AM]
I've found this one (http://code.google.com/p/libgdx/source/browse/trunk/gdx/src/com/badlogic/gdx/graphics/loaders/ObjLoader.java?r=250).

Instead using glDrawElements, it uses glDrawArray. Is there any important different? Maybe, perfomance, isn't it?
The previous may not be so easy to understand, so here's an illustration. If your model looks like this


Then the vertices marked as 0, 1, 2, 3 will have the indices 1, 2, 3, 4 in the OBJ file.
If you have smooth normals (not like in the screenshot, but like in most models) then the vertices marked 1 and 2 in the image will have exactly one normal. In the other case, the two triangles are drawn with the same vertex coordinates, but different normals. Which, in OpenGL means, different vertices.
So, in that case, OBJ will tell you "draw 1,2,3 with normals 1,2,3, then draw 2,3,4 with normals 5,6,4" but you have to transform that into "draw 0,1,2,3,4,5" where 0, 1, and 2 are OBJ's 1, 2, 3 with texture coordinates 1, 2, 3, and 3, 4, 5 are OBJ's 2, 3, 4, but 2 and 3 now have a different normal.
Quote:Original post by VansFannel
Instead using glDrawElements, it uses glDrawArray. Is there any important different? Maybe, perfomance, isn't it?
That works, it is the exact same thing, except that glDrawArrays does not have indices (obviously) which means that the post-transform cache on most GPUs won't be used, as it uses indices.

This topic is closed to new replies.

Advertisement