dhpoware logo
home products source demos contact us
navbar navbar
box top left corner box top right corner
OpenGL OBJ Viewer Demo.

This Windows demo shows you how to import Alias|Wavefront OBJ and MTL files into your OpenGL applications. The OBJ file format is one of the most widely supported 3D file formats. All of the most popular 3D content creation packages includes support for this file format either natively or through third party plugins.

Models are rendered using either the fixed function pipeline or the programmable pipeline. The fixed function pipeline is used on hardware that only supports OpenGL 1.x. The programmable pipeline is used on hardware that supports OpenGL 2.0 and higher. The supported GLSL shaders are per fragment Blinn-Phong and normal Mapping. Both support only a single fixed directional light source shining down the OpenGL default negative z-axis.

Most of the time the per fragment Blinn-Phong shader will be used. The normal mapping shader will be used only when the OBJ model's MTL file includes a material that has a bump map (specified using the 'map_bump' command). This demo assumes that any bump map associated with a material will be a normal map. All other bump map formats are not supported.

When the MTL file contains a material with a normal map this demo will generate smooth tangent vectors for the OBJ model. The smooth tangent vectors are generated by summing the triangle face tangent vectors of adjacent triangle faces and then normalizing the resulting tangent vector. The bitangent vectors are not generated here. They are calculated in the normal mapping shader's vertex shader.

A minimal file menu is provided to enable OBJ files to be loaded at runtime. The demo includes drag and drop support for OBJ files. Drop an OBJ file onto the demo's window and the OBJ file will be loaded. Alternatively drop the OBJ file onto the demo's EXE file. The demo will launch and load the OBJ file.

This demo is completely self contained. The two GLSL shaders are embedded into the demo's EXE file as resources.

Left click and drag using the mouse to translate the model.
Middle click and drag using the mouse to zoom in and out of the model.
Right click and drag using the mouse to rotate the model.

To learn more about per fragment Blinn-Phong shading in OpenGL check out the OpenGL 2.0 Shading Language Fragment Lighting demo.
To learn more about normal mapping in OpenGL check out the OpenGL 2.0 Shading Language Normal Mapping demo.

1. OpenGL 2.0 hardware is required for shader support. This demo will use the legacy fixed function pipeline when run on OpenGL 1.x hardware.
2. This demo requires the Visual C++ 2010 Library Runtimes. Download instructions can be found here.


zip file Download executable, source, and Visual C++ 2010 solution files.

Change History:

10 July 2010.
Added missing .vcxproj.filters file to the project.

13 June 2010.
Updated solution to Microsoft Visual Studio 2010.

2 February 2008.
Updated solution to Microsoft Visual Studio 2008.

29 October 2007.
model_obj.h: Updated Vertex structure to include a bitangent member. Changed the tangent Vertex structure member from a three element array of floats to a four element array of floats. The extra float now stores the handedness of the local tangent space coordinate system.

model_obj.cpp: Updated generateTangents() to calculate the handedness of the local tangent space coordinate system at each vertex in the model. This will allow triangle faces that contains mirrored texture mappings. The Vertex structure now contains the bitangent vector. This is the correct bitangent vector with the handedness already applied.

normal_mapping.glsl: Updated to include the handedness when calculating the bitangent vector.

cube.obj: The -z face now contains a mirrored texture projection of the +z face. This will verify the correctness of the handedness updates to the tangent vector calculations.

box bottom left corner content box box bottom right corner
logo logo