Skip to content

Instantly share code, notes, and snippets.

@cirosantilli
Last active November 1, 2018 14:22
Show Gist options
  • Save cirosantilli/8614364 to your computer and use it in GitHub Desktop.
Save cirosantilli/8614364 to your computer and use it in GitHub Desktop.
Tutorial to compile and run OpenGL on Linux for complete Linux newbs

Tested on Ubuntu 12.04.

Should work on any recent Ubuntu, and on any distro with minor modifications.

Open up a terminal

There are many ways you can do this, the best in my opinion is Krusader's terminal emulator, but we will just use the gnome terminal emulator that comes with Ubuntu. To access it:

  • hit Super key (Windows key)

  • type "terminal"

  • choose the Terminal application (actually it is the GNOME terminal since there are many other similar ones, but Ubuntu keeps hiding real names... sigh)

Ubuntu 12.04 also has the shortcut Ctrl+Alt+T.

Install and run tests

On the terminal run:

# Install libraries. This depends on your Linux distribution.
sudo apt-get update
sudo apt-get install -y build-essential
sudo apt-get install -y freeglut3-dev

Download the examples at http://www.lps.usp.br/~hae/psi2652/materiais/freeglut_hae100.zip

With the terminal go to your download directory in the terminal (cd ~/Downloads by default) and run:

# download, compile and run tests
unzip -d freeglut_hae100 freeglut_hae100.zip
cd freeglut_hae100/samples
# get the makefile
wget https://raw2.github.com/cirosantilli/cpp/1b9987324a57b264217875c1e9aa429850ab0760/opengl/bouncing_balls/makefile
# hack the makefile because files are not very ANSI C compliant
sed -i '1 s/.*/CC\t:= g++ -fpermissive/' makefile
make
cd _out/
./01hello

If you see the hello example, it works.

Usage

Whenever you start a new project, just go to the project's directory (directory where the .cpp are), and get the makefile with:

wget https://raw2.github.com/cirosantilli/cpp/1b9987324a57b264217875c1e9aa429850ab0760/opengl/bouncing_balls/makefile

To compile and run use:

make
cd _out/
./basename_no_extension

Don't use -fpermissive in your project's makefile: we only used it because the examples were not very compliant with the most recent C standards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment