Setting up Glut / FreeImage

By Robert Flack. Revised by Kelly Moylan, Mehran Maghoumi, Stephen Tkachuk, Eric Chen, Tennyson Demchuk, and Tom Wallace.

This document describes how to setup Glut / FreeImage for compiling your applications for COSC 3P98. For the following tutorial you need the Load.c example program, a sample image in tiff format named img.tif. Download these files and jump to the category applicable to your setup.

Note that you may use Glut or FreeGlut (a version of Glut that is being maintained here). You will need to change the names of the DLL's and Header files according to which version you use.

Note: For your convenience, we have preconfigured a Visual Studio solution that automatically takes care of all the dependencies. This will be your best option as it enables you to quickly get up and running with Glut and FreeImage. Nevertheless, it is also a good idea to become familiar with configuring the libraries manually in case something goes wrong.

The preconfigured Visual Studio solution

Windows Visual Studio setup

Linux setup

The preconfigured Visual Studio solution

Download the zip archive 3P98-C-Template.zip (C) (or 3P98-2021-Template.zip (C++)) and extract the contents of the archive. This solution was created using Visual Studio 2021, but will work with Visual Studio 2022. If opening using Visual Studio 2022, a popup will appear asking you to retarget the project; simply click "OK" using the options already selected. Just open the solution file (3P98-2021-Template.sln) and write your code in the file "Source.c". Don't forget to include the necessary header files (eg. freeglut.h, freeimage.h, etc.). Hit F5 and the project should build and run automatically.

Some common errors result from changing the directory structure upon extracting the .zip file, or from opening the folder as a VS project instead of opening the solution file directly. If you are running Visual Studio on a personal computer, ensure that the C++ workload is installed. If Visual Studio 2022 is already installed, this can be done or checked by reopening the Visual Studio Installer, and clicking "Modify" on the 2022 installation. In the "Workloads" tab, if the workload titled "Desktop development with C++" is checked, no changes are necessary. If not, select it and click "Modify" in the bottom right to install C++ compatability.

Setting up Glut / FreeImage in Microsoft Visual Studio

Since glut and freeimage are not installed in the COSC labs, it is preferable to use the preconfigured Visual Studio solution above for your assignments, so that you will be able to run them on lab computers. The old instructions for installing the libraries and setting up a project to use them is included on a separate page here.

Setting up Glut / FreeImage in Linux

In the lab (MCJ 310), glut and freeimage are already installed and hence you can skip to step 2. If you're installing on your own computer start with step 1.

Step 1 - Installing the libraries

Depending on your distribution this part of the installation may vary. It is usually best to use your distribution's package manager if it has the libraries in it rather than downloading the libraries from their web sites. The following steps are tailored to Ubuntu (or any other Debian-based) Linux but will likely just need slight modifications to work in other distributions.

Ubuntu (Or any Debian based) Linux

Run the following command to download and install the FreeImage and Glut libraries.

sudo apt-get install libglut3-dev libfreeimage-dev

For more recent versions of Debian-based distros, you might want to use freeglut instead of libglut. The command bellow will install freeglut3

sudo apt-get install freeglut3-dev libfreeimage-dev

After this, the libraries (and any dependencies) will be installed to the appropriate locations.

Step 2 - Compiling your program

When you are compiling your application, you must tell the compiler that you are using OpenGL, Glut, FreeImage, etc. This is done using the -l (lowercase "L") flag in most compilers. For example, if you wanted to compile Load.c you would run the following:

On Ubuntu:

gcc Load.c -o load -lglut -lfreeimage

If you installed freeglut use this command:

gcc Load.c -o load -lfreeglut -lfreeimage

On the lab computers:

gcc Load.c -o load -lGL -lGLU -lglut -lfreeimage -lX11

After it compiles you can then run the program by typing:

./load

To run the Load.c example program you need to place or create img.tif in the current directory.

Back to COSC 3P98