Web Design,Programming,Mobile,iOS/Android,GameDev,IT Businness,eCommerce,Social Media


Monday, 21 January 2013

Opengl Mesh Loader OBJ


OpenGL as we know is a low level API for manipulating computer graphics. It is very powerful and cross platform which means all operating systems support it. This is the main reason i want to develop apps with opengl. I dont want to stick with Windows only, rather as a lover of Ubuntu i like to create small programs for this platform also.

OpenGL is powerful but when it comes to create big 3D worlds and meshes it can be very very hard nearly impossible to do this all by code. So you cant just create small games with OpenGL only. You need to create your 3D assets on other 3D modelling software and to export them and after that to create functions or classes in C++ that will read those exported files and parse them into your final program. In the code below you have a class that loads OBJ files and displays them onto the screen. OBJ is powerful file format and is very easy to implement parser for those files.

The downside of OBJ file formats is that they dont support animation, just static mesh. However it can be useful for static assets like houses or interiors. To fully understand the code create a box on some modelling software ( like blender which is free but professional ) and export it on OBJ format and then open that file with some text editor and you will see how vertices and faces are exported and easy to read even for us humans. This loader is separated in two files. objloader.h which contains the main class and the objloader.cpp which contains the actual implementation of the base class.

You can download the source code here and if you dont understand please follow this channel on youtube. There you have tutorials on OpenGl SDL and C++ from the very beginning. This loader was also created following these tutorials. Feel free to use modify and distribute the code given. Licence is GPL obviously.

There is a sample program given in the archive which demonstrates this obj loader. Notice however that this project used SDL library for windowing platform. If you want to learn more about SDL in this blog post i show you how to setup SDL with Visual Studio and in this post i show you how to create your first window.

Written by

Thank you for taking your time to browse through our blog. We try to build as much rich content base as we can. We focus in modern technologies, computer science design and business.


Post a Comment


© 2013 smartnoob . All rights resevered. Designed by Templateism