Tuesday, February 22, 2011

Setup GLUT (OpenGL) in Codeblocks


GLUT (OpenGL Utility Toolkit) is a toolkit to write OpenGL programs. It makes learning OpenGL programming very easy and simple. However, it is very old and unsupported for the last 20 years or more and it does not support modern requirements. I personally do not recommend this library and I request to choose one of the alternate libraries such as GLFW, freeglut, and SDL.

If you still need to setup this library to execute old code downloaded from the internet written in GLUT then follow the steps provided below:

Download the glut library from the website http://code.google.com/p/rawvideoplayer/downloads/detail?name=glut-3.7.6-bin.zip&can=2&q= for windows.

Steps to create GLUT project in Code::block.
Step 1: Extract the downloaded zip file.

Step 2: Browse extracted files. Copy the glut.h file and paste it into the directory "C:\ProgramFiles(x86)\CodeBlocks\MinGW\include\GL". Copy glut.lib file and paste it into the directory "C:\Program Files(x86)\CodeBlocks\MinGW\lib". Also, copy the glut.dll and paste it into
the directory "C:\Windows\System32".


Step 3: Open the Code::block and click on create a new project from the Start page or go to File-> New-> Project from the menu bar.
Step 4: Click on the GLUT project as shown in image below and click Go button.
Enter the necessary details and click Next button.

Step 5: Now provide path "C:\Program Files(x86)\CodeBlocks\MinGW" for glut location and click Next button.



Click Finish button.
Step 6:



Finally, the project is created and you will get the default main.cpp file and don't forget to include   "#include<windows.h>" header file otherwise you will get an error while building a project. After including windows.h library built and run it will see the window as below.


If program execution failed showing glut32.dll not found then copy glut32.dll file in the same directory
side by side with a program execution file.

Please watch the video below for a detailed explanation.


18 comments:

  1. Hi, do you have tutorial on setting up GLEW/GLFW/FreeGLUT, all three including the linking in Code::Blocks? I am having hard time setting it up. I found this good tutorial: http://www.arcsynthesis.org/gltut/index.html. I am getting this error when running the program (the aforementioned tutorial has source code tutorials and I had to use premake4.exe to generate the Codeblocks .cpb (no problem here).

    Anyways, error I get:
    cannot find -lframework (for Release of build)
    cannot find -lframeworkD (for Debug of build)

    ReplyDelete
  2. Thanks very much, your illustration really help me.

    ReplyDelete
  3. i didn't found bin folder nor the glut.dll...??

    ReplyDelete
  4. it doesn't work for me btw..., something wrong with the glut header , help !

    ReplyDelete
  5. Where is the .bin folder?

    ReplyDelete
  6. when i try to build my project then divert to glut.h. plz help

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. include window.h at the top of the source file or include gl.h and glu.h

      Delete
  7. "cannot find -lglut32 " what does this mean??

    ReplyDelete
  8. am not able to open main.c file which is under source

    ReplyDelete
  9. D:\CG PROJECTS\car Race\car.cpp|118|error: name lookup of 'y' changed for ISO 'for' scoping [-fpermissive]|

    guys i get this error for every grphics program i compile???!!! :(

    ReplyDelete
  10. I am getting error in glut.h header file.what should i do?

    ReplyDelete
  11. How to install OpenGL in Codeblocks in Ubuntu 14.04 ?

    ReplyDelete
  12. Can we modify the shapes? Can we use this technique to create softwares like faceworx or blender?

    ReplyDelete
  13. i am getting error
    C:\Program Files (x86)\CodeBlocks\MinGW\include\GL\freeglut_std.h|639|undefined reference to `_imp____glutCreateWindowWithExit@8'|

    ReplyDelete
    Replies
    1. ye saare mil ke humein chutiya bana rahe hai, gand fatti ke bhadwe madarchod

      Delete