Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
79 lines (44 sloc) 3.25 KB


This example demonstrates how to get started using OpenGL with biicode. Freeglut is an open source alternative to the OpenGL Utility Toolkit (GLUT) library. It allows you to create and manage windows containing OpenGL contexts on a wide range of platforms, and dealing with user input from mouse, keyboard and joystick devices. You can visit the following pages to learn more about OpenGL and GLUT (and hence freeglut):

  1. The Official Guide to Learning OpenGL v1.1
  2. List of OpenGL methods
  3. The Free OpenGL Utility Toolkit
  4. List of GLUT methods

1. Create a new project

First, create a new project as described in the :ref:`hello world example <cpp_getting_started>`, using the following options:

~$ cd cpp_freeglut_project
~/cpp_freeglut_project$ bii new anonymous/cpp_freeglut --hello=cpp

2. Creating reusable code

This is some example code that makes use of GLUT functions. Note that you must include a reference to a biicode GLUT wrapper library. This is the only information biicode needs to fetch the required files when needed, taking into account your actual development platform. We'll see how this happens in the next step.

Now, simply put the following code into your cpp_freeglut block folder (you can also download these files here: :download:` </_static/code/cpp/examples/freeglut/>`, unzip and copy them into your block folder):


.. literalinclude:: /_static/code/cpp/examples/freeglut/sphere.h
   :language: cpp
   :emphasize-lines: 2


.. literalinclude:: /_static/code/cpp/examples/freeglut/sphere.cpp
   :language: cpp


.. literalinclude:: /_static/code/cpp/examples/freeglut/main.cpp
   :language: cpp

3. Find dependencies

Now is when the biicode magic takes place. The previous code needs to link with some library implementing the drawing functions being used. You can resolve all missing dependencies for your platform using the bii find command. From your project's folder location execute:

$ bii find

This will find and retrieve all missing files from the biicode servers to your local filesystem, under the deps folder of your project. You should see a success message confirming that all dependencies have been resolved.

4. Build and run

Now it is time to see the result of the previous steps. You can build your main file with the bii cpp:run command and and run the executable inside the bin folder.

$ bii build
$ cd bin
$ #run your executable

That's it! You should see a new window named "My World", containing a single white sphere in its center. Just like this!:


If you experience any difficulties during the coding process, or get any errors during the program execution, visit our forum and feel free to ask any questions.