Course list http://www.c-jump.com/bcc/
Prior to this lab, we used some very simplistic models, such as a single triangle or a combination of a few triangles. If we have to deal with a more complex 3D object, like a car or a rabbit, we are likely to import object's model from a file. In other words, we need to learn how to render already existing models:
Ultimately, we would like to take an approach such as
loader.load( "bunny.obj" ); myModel->set_geometry( loader.vertices, loader.num_vertices * 3 * sizeof( GLfloat ) );
to load the geometry for our model.
If you search the web for "3D models" or "3D objects", you'll find a lot of existing objects in stored in different file formats. A few of those popular formats are
.mb Maya binary
.ma Maya ASCII
.dxf AutoCAD in ASCII
.obj Really simple ASCII format, developed by Wavefront (***not to be confused with C++ compiler output files!***)
.fbx Autodesk binary format (commonly supported by DirectX and game engines)
.dae COLLADA in XML/ASCII
.blend Blender file
.3ds or .max 3DStudio/max file. Common for games.
See this wikipedia article for more information about Wavefront OBJ files. Here is an example of Wavefront OBJ file named cube5.obj (located under L262Labs\Models\Misc)
# cube.obj # g cube v 0.0 0.0 0.0 v 0.0 0.0 5.0 v 0.0 5.0 0.0 v 0.0 5.0 5.0 v 5.0 0.0 0.0 v 5.0 0.0 5.0 v 5.0 5.0 0.0 v 5.0 5.0 5.0 # 3_ _ _7 0.0 5.0 0.0 5.0 5.0 0.0 # /| /| # 4/_|_ 8/ | 0.0 5.0 5.0 5.0 5.0 5.0 # | 1|_ _|_|5 0.0 0.0 0.0 5.0 0.0 0.0 # | / | / # |/_ _ _|/ # 2 6 0.0 0.0 5.0 5.0 0.0 5.0 vn 0.0 0.0 1.0 vn 0.0 0.0 -1.0 vn 0.0 1.0 0.0 vn 0.0 -1.0 0.0 vn 1.0 0.0 0.0 vn -1.0 0.0 0.0 f 1//2 7//2 5//2 f 1//2 3//2 7//2 f 1//6 4//6 3//6 f 1//6 2//6 4//6 f 3//3 8//3 7//3 f 3//3 4//3 8//3 f 5//5 7//5 8//5 f 5//5 8//5 6//5 f 1//4 5//4 6//4 f 1//4 6//4 2//4 f 2//1 6//1 8//1 f 2//1 8//1 4//1
Here,
lines starting with # are comments
lines with v specify vertex coordinates
lines with vn specify vertex normals
lines starting with f describe faces (triangles in OpenGL)
There is another type of input in OBJ files - vt, which specify texture coordinates (to be discussed later.)
In cube5.obj face definitions have fromat
f 1//2 7//2 5//2 | | | normal_index | vertex_index
Each index is one-based: 1, 2, 3, ...
FBX is a proprietary, more complex binary format, originally designed to support the capturing of motion data with Filmbox software, which gave the FBX extension to this type of file. Internally, FBX supports more features, including animation. FBX files are widely adopted by gaming industry and can be previewed using QuickTime player. There is a free FBX file converter from autodesk.com, so you can convert FBX files you find on the Web to OBJ format.
In many of the upcoming labs we will use a simple OBJ file loader, included with the source code for this lab: c262_lab06.zip
As before, download the ZIP file unzip under the labs subdirectory. You should get the directory structure
C:\bcc\GL262Labs\labs\c262_lab06
Open Visual Studio project
C:\bcc\GL262Labs\labs\c262_lab06\c262_lab06.sln
and compile the executable:
Build -> Build Solution
(or simply press F7.)
In this lab, I want you to try loading different models by uncommenting lines at the beginning of the c262_lab06.cpp source file. Notice that in our lab the objects really don't look as good as this:
Instead, we see only a silhouette of an object, or a flat, grey-colored shadow:
To render realistic 3D objects, we need to start using lighting, which is going to be covered in our next lab.
There are no files to submit.
Demonstrate a working c262_lab06 program to your instructor.