Technical

GLEW with Code::Blocks for Windows 10 64-bit

The OpenGL Extension Wrangler Library in short popularly known as GLEW. The details about GLEW can be found on its home page [ link ]. On their home page, you can get the source code along with the precompiled binaries. Unfortunately, the precompiled versions for windows are only available. If you are a gcc fan, and most of the time using the code::blocks configured with gcc, then the precompiled binaries provided in the Glew home page may not work. In order to continue your work with code::blocks (gcc), one needs to build the GLEW binaries from source using gcc environment.

Prerequisites before starting the build process:

  • Make sure MinGW is installed in your window machine [ Recommended TDM-GCC, link ]
  • MSYS, which is a Bourne Shell command line interpreter system for the Windows environment. It is an alternative to cmd.exe of windows and compatible with MinGW in order to port many open source applications in the Windows environment. [ link ]
  • Finally, the OpenGL (gl, glu, and glut or freeglut) must have been configured with respect to your gcc compiler

Building the GLEW libraries form the Source

  1. Extract the GLEW source files. The name of the folder is in the form: glew-x.x.x
  2. If the lib and bin folders are not present inside the extracted source folder manually create them so that the folder tree structure will be: glew-x.x.x/bin and glew-x.x.x/lib
  3. Open MSYS terminal and navigate into the GLEW source folder
  4. While inside the source folder, run the following commands from MSYS terminal
 $ make
 $ make install
  • Check the glew-x.x.x/bin and glew-x.x.x/lib folder after running the above commands.
  • Copy the following stuffs to the MinGW installation directory from the GLEW source directory.
    • copy from glew-x.x.x/include/GL to MinGW_installation_dir/include/GL
    • copy from glew-x.x.x/include/lib/*.a to MinGW_installation_dir/lib
    • copy from glew-x.x.x/include/bin/glew32.dll to MinGW_installation_dir/bin
    • NB: Sometimes the glew32.dll can be found in glew-x.x.x/include/lib/  instead of  glew-x.x.x/include/bin/.  But whereever it may be, you need to transfer to the bin folder of  MinGW installation.

Setting GLEW with Code::Blocks (Version 16.01)

In order to set the code::blocks environment

  • Open code::blocks. Go to settings → compiler settings → linker settings 
  • Put glew32 under the linker settings tab as shown in the following figure.

GLEW_CodeBlocks

Testing a Sample GLEW program

Code Reference: [ link ]

#include 
#include 
#include 
int main(int argc, char** argv){
glutInit(&argc, argv);
glutCreateWindow("GLEW Test");
GLenum err = glewInit();
if (GLEW_OK != err)
{
/* Problem: glewInit failed, something is seriously wrong. */
fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
}
fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
return 0;
}

Sample Output

GLEW_test_output

If you are getting the output status with the GLEW version number, congratulations. You have successfully configured GLEW in code::blocks.

PS:

  • If you are following the above procedure to configure GLEW, I am not supposed to solve any error issues. In that case, Google is your friend.
  • On the other hand, if you are able to find any issue along with the solution, a big thank you from my side for informing me.

 

Leave a comment