Sunday, February 8, 2015

Setting up an OpenGL C++ with eclipse IDE

I'm currently using Linux 3.13.0-24-generic x86_64 kernel version of linux mint with OpenGL version of 2.1 Mesa 10.1.0 follow this link to check OpenGL version [link]

You need to go through only three steps
  1. Download OpenGL C++ libraries.
  2. Setup and install eclipse CDT bundle.
  3. Configure the eclipse libraries [simple].
  4. Test OpenGL application.

Download OpenGL C++ dependencies
  • In terminal use sudo apt-get install libglu1-mesa-dev freeglut3-dev

Setup and install eclipse CDT bundle

  • In eclipse Help > Install New Software
  • Add new cdt installation path
  • Tick CDT Main Features hit next and finish the process and restart the eclipse

Configure the eclipse libraries [simple]

  • In eclipse choose New > C++ Project

  • Right click the project > Properties
  • Select C/C++ Build > Settings > GCC C++ Linker > Libraries > +
  • Add glut, GL, GLU libraries
  • Time to test a OpenGL app

Test OpenGL application

  • Download this sample source code [link] 
  • Right click on project New > File create new c or cpp file and paste the code
  • Its best practice to always clean and build the cpp project to do that right click Clean Project, right click Build Project / ctrl+B
  • Right click on project Run As > Local C/C++ program
  • It should show a red 3d cube like this
  • Fun [HACK] make the cube rotate 
    • Replace this code snippet inside void display(void) function
    •  while (true) {  
            glRotatef(1.0f, 1.0f, 1.0f, 1.0f);