Wednesday, January 14, 2015

Installation of freeglut, devc++, glew step-by-step for opengl programming in C++

I found it very tedious to install and get started with opengl programming in C++ on windows machine. I came across multiple issues, some were answered some not. To make it simple for others I'm noting it down here.
Let's get started,

Listing out configs which worked for me:
  • Windows 7 64bit
  • DevC++ IDE with MinGW GCC (v5.8.3)
  • freeglut 2.8.1-1.mp for MSVC
  • glew-1.11.0
Installation step-by-step:
  1. Download and install DevC++ IDE with MinGW GCC for Windows 64bit machine (Sourceforge.net link)
  2. Go to Tools->Check for Packages and choose one the mirror sites and click Check for updates
  3. Check freeglut among the list and install it, with this while creating new project, you'll find freeglut project option under Multimedia tab
  4. If mirror sites not working then download the DevPak for freeglut and install it using Tool->Package Manager
  5. Now, download freeglut for MSVC (from here) as we need import (_not static) lib and header files to copy in devcpp
  6. Copy header files at freeglut\include\GL\ to <DevCpp Installation directory in C drive Program files>\MinGW\include\GL\
  7. Copy library files at freeglut\lib\x64\ to <devCpp>\MinGW\lib\
  8. Also, copy freeglut.dll in bin folder in %systemroot% (C:\Windows)
  9. Get latest glew from here, http://sourceforge.net/projects/glew/files/glew/
  10. Extract it from zip and copy the contents of \include\GL\ to <DevCpp Installation directory in C drive Program files>\MinGW\include\GL\
  11. Similarly, copy the contents of glew\lib\Release\x64 to <Devcpp>\MinGW\lib\
  12. Also copy glew\bin\Release\x64\glew32.dll to %systemroot% (C:\Windows\)
  13. Restart devc++ IDE
Project setting:
  1. Create new freeglut project, you'll find it under File->New->Project->Multimedia tab
  2. While including header files, use freeglut.h and glut.h
  3. Include glew.h before than including any other header file
  4. In Project->Project Options->Parameters tab, remove -DFREEGLUT_STATIC for C++
You should now be good to get started!

Comment for any linking errors.

P.S.: If any "undefined reference to xxx" error is displayed, that's a linking error, some lib might be missing. To find which lib, search the xxx here, http://msdn.microsoft.com/en-us/library/windows/desktop/ms646940(v=vs.85).aspx