Wednesday, April 22, 2009

OpenGL Programming under LINUX

First of all for all those folks who have no idea of what is OpenGl, please visit this link
OpenGL Website

Ok hoping that you have read the website and got some info, now I teach you to configure OpenGL onto your LINUX system.

The things that you need to work on are:
1. Eclipse - for Eclipse you need Sun Java or OpenJDK configured.
Download openJDK from Open JDK Site

With LINUXs like Debian, Ubuntu and many more, you would already have been provided with OpenJDK. Open your Package Manager and do a search for the same and then configuring it would be pretty simple.

Check if your /etc/jvm file has the JVM version mentioned in your LINUX system. If its present, then, download Eclipse Latest version Ganymede from this site - Eclipse Home

2. Eclipse CDT - C/C++ Developement Kit
Note while you download, it would be fair if you can download the Eclipse CDT rather than the basic Java Eclipse. But note that you would still be requiring Java to run Eclipse.

If you have an OS like Fedora, Ubuntu or my fav Debian, then you can configure CDT from the package managers itself.

3. OpenGL Tool Kit
Update your repos and finally install the following - OpenGL Took Kit, libgl, libglut, libglu, mesa, freeglut3. The package names mentioned here above are present in Debian Repos. You may have to figure out as to how to get them for your box.

Note that all the above lib files are not required to run your OpenGL programs. If you have freeglut3 along with libglut - that is more than sufficient.

Finally the code configuration

Open CDT, choose your workspace and then create a new Managed C++ project.

Search for some OpenGL helloworld code from Google. But if you are really interested to learn OpenGL, I suggest the following book - OpenGL SuperBible 4th Edition by Richard S Wright and co.

Copy paste the code to the program - dont forget to name your file as main.cpp or as if you have your whole code inside main method of C/C++. Recalling C/C++???? Great...!

Configuring the Library

Right Click on your project, go to properties, click on C/C++ Build --> Libraries --> Add your Library as "glut" --> If prompted enter the path for Glut Library which is usually /usr/lib/opengl or /usr/lib/glut

After all these steps -- If your code is correct, then you would have run your first C/C++ program. [To Run --> Right click your code and select Run as Local C/C++ Application]

If you have any issues do mail me.

For advanced users there are many more things to learn -- Check out SDL Language, Mesa and many more. Happy coding!!!!

Ananth Gouri

No comments:

Post a Comment