- Install dependencies and get the Collada DOM:
- sudo apt-get install \
- subversion build-essential nvidia-cg-toolkit libgl1-mesa-dev libglu1-mesa-dev glutg3-dev cmake libboost-filesystem-dev libxml2-dev zlib1g-dev libpcre3-dev
- mkdir ~/svn
- cd ~/svn
- svn co https://collada-dom.svn.sourceforge.net/svnroot/collada-dom/tags/2.2.1 collada-dom
- Download bullet version 2.73:
- mkdir ~/src
- cd ~/src
- wget http://bullet.googlecode.com/files/bullet-2.73-final.tgz
- Unpack and compile bullet:
- tar zxvf bullet-2.73-final.tgz
- cd bullet-2.73
- cmake . -G "Unix Makefiles"
If you see "OPENGL NOT FOUND" you might need to add a missing symlink like I had to. If not, just skip to the make command below. Here's what I did to fix the error:
- cd /usr/lib
- sudo ln -s libGL.so.1 libGL.so
- cd ~/src/bullet-2.73
Then run the cmake command again, and if it says OPENGL FOUND, move on.
- make
- sudo make install
- Backup Collada DOM default bullet libs (which don't work):
- cd ~/svn/collada-dom/rt/external-libs/bullet/lib/linux
- mv libbulletcollision.a libbulletcollision.a.bak
- mv libbulletdynamics.a libbulletdynamics.a.bak
- mv libbulletmath.a libbulletmath.a.bak
- mv libbulletopenglsupport.a libbulletopenglsupport.a.bak
- mv libbulletsoftbody.a libbulletsoftbody.a.bak
- Copy new bullet libs to Collada DOM include folder, and fix lib names so Collada DOM will compile:
- cp -a ~/src/bullet-2.73/src/BulletCollision/libBulletCollision.a ~/svn/collada-dom/rt/external-libs/bullet/lib/linux/libbulletcollision.a
- cp -a ~/src/bullet-2.73/src/BulletDynamics/libBulletDynamics.a ~/svn/collada-dom/rt/external-libs/bullet/lib/linux/libbulletdynamics.a
- cp -a ~/src/bullet-2.73/src/LinearMath/libLinearMath.a ~/svn/collada-dom/rt/external-libs/bullet/lib/linux/libbulletmath.a
- cp -a ~/src/bullet-2.73/Demos/OpenGL/libOpenGLSupport.a ~/svn/collada-dom/rt/external-libs/bullet/lib/linux/libbulletopenglsupport.a
- cp -a ~/src/bullet-2.73/src/BulletSoftBody/libBulletSoftBody.a ~/svn/collada-dom/rt/external-libs/bullet/lib/linux/libbulletsoftbody.a
- Back up old bullet headers and copy new ones to Collada DOM include folder:
- cd ~/svn/collada-dom/rt/external-libs/bullet
- mv include include.bak
- mkdir include
- cd /usr/local/include
- cp -a btBulletCollisionCommon.h ~/svn/collada-dom/rt/external-libs/bullet/include/
- cp -a btBulletDynamicsCommon.h ~/svn/collada-dom/rt/external-libs/bullet/include/
- cp -a Bullet-C-Api.h ~/svn/collada-dom/rt/external-libs/bullet/include/
- cp -a BulletCollision ~/svn/collada-dom/rt/external-libs/bullet/include/
- cp -a BulletDynamics ~/svn/collada-dom/rt/external-libs/bullet/include/
- cp -a BulletSoftBody ~/svn/collada-dom/rt/external-libs/bullet/include/
- cp -a LinearMath ~/svn/collada-dom/rt/external-libs/bullet/include/
- Compile Collada DOM:
- cd ~/svn/collada-dom
- make -f Makefile.linux
- Install Code::Blocks IDE if you don't already have it:
- sudo vi /etc/apt/sources.list
Add the following to the bottom of the file:
# Code::Blocks
deb http://apt.jenslody.de/ any main
deb-src http://apt.jenslody.de/ any main
deb http://apt.wxwidgets.org/ lenny-wx main
Save the file and exit.
- wget -q http://apt.wxwidgets.org/key.asc -O- | sudo apt-key add -
- sudo apt-get update (ignore the error)
- sudo apt-get install jens-lody-debian-keyring (install without verification)
- sudo apt-get update (there shouldn't be any errors now)
- sudo apt-get install codeblocks
- Make a Code::Blocks project for the viewer application:
Make a new empty project in Code::Blocks, then create a new C++ source file.
Copy the contents of ~/svn/collada-dom/viewer/projects/linux/main.cpp into your new file.
Click "Project --> Build options...".
In the new window, on the upper left corner, click the name of your project (above the word Debug).
Click the "Linker settings" tab. Under "Other linker options:" enter the following (substituting your_username for your actual username):
-lxml2
-L/home/your_username/svn/collada-dom/dom/external-libs/tinyxml/lib/linux/libtinyxml.a
-lpcre
-lpcrecpp
-lboost_filesystem
-L/home/your_username/svn/collada-dom/dom/build/linux-1.4/
-lcollada14dom
-lminizip
-lz
-L/home/your_username/svn/collada-dom/rt/build/linux-1.4/
-lcollada14rt
-L/home/your_username/svn/collada-dom/fx/build/linux-1.4/
-lcollada14fx
-L/home/your_username/svn/collada-dom/rt/external-libs/bullet/lib/linux/
-lbulletopenglsupport
-lbulletdynamics
-lbulletcollision
-lbulletmath
-lGL
-lGLU
-lglut
-lCg
-lCgGL
-lpthread
- Click the "Search directories" tab. Add the following entries under the "Compiler" tab:
/usr/include/libxml2
/home/your_username/svn/collada-dom/dom/external-libs/tinyxml
/home/your_username/svn/collada-dom/dom/external-libs/minizip/include
/home/your_username/svn/collada-dom/dom/include
/home/your_username/svn/collada-dom/dom/include/dae
/home/your_username/svn/collada-dom/dom/include/1.4
/home/your_username/svn/collada-dom/fx/include
/home/your_username/svn/collada-dom/rt/include
/home/your_username/svn/collada-dom/rt/external-libs/bullet/include
/home/your_username/svn/collada-dom/rt/external-libs/bullet
/usr/include/GL
/usr/include/Cg
Make sure to substitute "your_username" for your actual username, like you did before.
- Click the "Linker" tab (not "Linker settings"). Add the following entries:
/home/your_username/svn/collada-dom/dom/build/linux-1.4
/home/your_username/svn/collada-dom/rt/build/linux-1.4
/home/your_username/svn/collada-dom/fx/build/linux-1.4
Click OK. Click "File --> Save project".
Hit F9 to build and run the project and it will take you to an error in the file cfxPlatform.h.
You need to change #include CFX_PLATFORM_INCLUDE to read:
#include "/home/your_username/svn/collada-dom/fx/include/cfxLinux.h"
Now click "File --> Save Everything".
- Before building, copy some files to your project directory so your new program runs properly:
- cd ~/svn/collada-dom/viewer/bin
- unzip samples.zip
- cp -a ~/svn/collada-dom/viewer/bin/bamboo.tga ~/cpp-projects/your_project_name/
- cp -a ~/svn/collada-dom/viewer/bin/banana.tga ~/cpp-projects/your_project_name/
- cp -a ~/svn/collada-dom/viewer/bin/ties.tga ~/cpp-projects/your_project_name/
- cp -a ~/svn/collada-dom/viewer/bin/wooden_boards.tga ~/cpp-projects/your_project_name/
- cp -a ~/svn/collada-dom/viewer/bin/cage.dae ~/cpp-projects/your_project_name/
- cp -a ~/svn/collada-dom/viewer/bin/bamboo.tga ~/cpp-projects/your_project_name/bin/Debug/
- cp -a ~/svn/collada-dom/viewer/bin/banana.tga ~/cpp-projects/your_project_name/bin/Debug/
- cp -a ~/svn/collada-dom/viewer/bin/ties.tga ~/cpp-projects/your_project_name/bin/Debug/
- cp -a ~/svn/collada-dom/viewer/bin/wooden_boards.tga ~/cpp-projects/your_project_name/bin/Debug/
- cp -a ~/svn/collada-dom/viewer/bin/cage.dae ~/cpp-projects/your_project_name/bin/Debug/
- Now build and run your Code::Blocks project. If all went according to plan, the program should build successfully,
and you should see it in action displaying the cage demo file.
- For some strange reason, the program can't find libcollada14fx.so even when it's in the same directory as the binary, so you
need to write a simple wrapper script (a.k.a. launcher) which sets the global variable LD_LIBRARY_PATH to the directory
where the shared library lives. Seeing as we're already setting LD_LIBRARY_PATH for the wrong reasons, until there is a fix for this, we may as well set it for
all the Collada DOM libs. That way we don't have to copy them anywhere special. Create a new file in the Code::Blocks build directory:
- cd ~/cpp-projects/your_project_name/bin/Debug/
- vi run_your_opengl_program
- Enter the following into the new file:
#!/bin/bash
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/your_username/svn/collada-dom/dom/build/linux-1.4/:/home/your_username/svn/collada-dom/fx/build/linux-1.4/:/home/your_username/svn/collada-dom/rt/build/linux-1.4/
./your_program_bin $@
Make sure you substitute "your_username" for your system username, and "your_program_bin" for the filename
of the output bin from your Code::Blocks project.
- Save the script and make it executable:
- chmod 755 run_your_opengl_program
- Now you can run the Collada DOM viewer program from the command line by running your wrapper script:
- ./run_your_opengl_program
You can load your Collada 3D models by dropping your Collada .dae and other associated files (exported from your 3D modeling application) into
the same directory as the binary and wrapper, and run your wrapper with the .dae file as its argument:
- ./run_your_opengl_program mushroom.dae
For some reason, when exporting Collada models in Blender, you have to "Disable Physics", which is an option in the export menu. Some sample Collada files
that come with the DOM don't seem to work in the viewer program. Whether these caveats are due to an incompatible build of bullet or something else I
did wrong, I do not know, but it seems this setup offers a lot of potential. My goal is to use the idea behind the viewer program, but rewrite it
using SDL instead of GLUT. C++ is still very new to me, so it might be a while before I figure it out, but when I do, I'll make a new tutorial.
Congratulations, now you can make 3D models in a modeling program, and load them into OpenGL using Collada files, the Collada DOM, and C++!
Now you have an IDE project which you can modify and expand upon to make a full-scale 3D program or game! If anyone can figure out how to avoid having to
set LD_LIBRARY_PATH, please let me know.
Comments
2011-06-28 02:41:19 EST
Subject: Great report
Comment:
Thanks for taking the time to write this up.
The little things can
really snag someone trying something outside of their comfort zone, and an
article like this can really help a lot.
2011-06-30 07:57:56 EST
Subject: Re: Great report
Comment:
Hi hal,
I'm glad someone finally found this useful. Collada seems
to be the industry standard for 3D model data, so I have no idea why it's
so difficult and counter-intuitive to set up the Collada DOM. I hope
someone fixes it in the near future.
2011-08-12 03:01:00 EST
Subject: Very useful Comment
Comment:
That's useful comment because of the simplicity and straightforward to
start.
Thanks.