matus-chochlik / oglplus

OGLplus is a collection of open-source, cross-platform libraries which implement an object-oriented facade over the OpenGL® (version 3 and higher) and also OpenAL® (version 1.1) and EGL (version 1.4) C-language APIs. It provides wrappers which automate resource and object management and make the use of these libraries in C++ safer and more convenient.
http://oglplus.org/
Boost Software License 1.0
491 stars 72 forks source link

obj_mesh and negative indices #74

Closed regnirpsj closed 10 years ago

regnirpsj commented 10 years ago

looks like as if ObjMesh::_load_index does not support negative indices in .obj files. using the stanford dragon w/ 026_ssao i get the following run-time error:

# ./_build/example/oglplus/026_ssao 
Runtime error
'essage: 'Obj file loader: Error reading indices: f -435545//-438368 -435544//-438367 -435543//-438366

Exit 1

what would be the easiest way to fix this?

matus-chochlik commented 10 years ago

Right now negative or relative indices are not supported. A model that works with the loader can be found here: http://sourceforge.net/projects/oglplus/files/assets/stanford_dragon.zip/download

I'll put this on the TODO list.

matus-chochlik commented 10 years ago

Support for negative indices was added in commit a5e71eafa998891aa234523dd223fa281933de8d on the develop branch. Please, let me know if it works with the model you used originally.

regnirpsj commented 10 years ago

i tested the update but it seems like something else is going on. basically, i tested all of the models at http://graphics.cs.williams.edu/data/meshes.xml. most of them work now, thanks to supporting negative indices. however, the cube (http://graphics.cs.williams.edu/data/meshes/cube.zip) doesn't, bailing out with

'Obj file loader: Error reading indices: f -8/-4/-6 -7/-3/-6 -6/-2/-6'

i've opened the .obj file in several editors and checked the indices, but couldn't find any obvious problem. i had the suspicion that line endings might be a problem (e.g., "\r" only instead of "\n" or "\r\n") but that seems not to be the case.

matus-chochlik commented 10 years ago

OK, I'm going to have a look at that one.

matus-chochlik commented 10 years ago

Should be fixed now (since commit f8bc1a22e012b13f73f416a0e70d8d31d8a0ed1e on develop)

regnirpsj commented 10 years ago

confirmed. however, i still have some older (as well as proprietary) .obj models lying around that don't work. now, i'm not going to badger you to do something about it. my question would rather be if it would make (more?) sense to rather develop a connection to some external loader framework (e.g., [http://assimp.sourceforge.net/] but also home-grown stuff) and how would i go about it?

matus-chochlik commented 10 years ago

Well, the OGLplus' OBJ loader is there mostly because I didn't want to have another external dependency for the examples and when I'm doing some quick prototyping. If you want to do anything serious then there are better loaders (and better formats) for scene geometry. If you want to use some 3rd-party or your own loader, you just need to upload the vertex attribute data (and possibly indices) into appropriate buffers, create VAOs and and store some instructions for the GL drawing calls (like gl.DrawArrays, etc.) I don't know into how much detail should I go so right now I just say that there are some examples showing how to store external data in OGLplus Buffers, how to initialize the VAOs and how to use the draw calls. Also you can have a look at the shapes::ShapeWrapper class to see how it uses Buffers, VAOs and the draw calls.

regnirpsj commented 10 years ago

appreciated, i'll see that i can find the time to tinker with that (or find a student to actually figure it out :)