Home

Awesome

OpenGLAda – OpenGL binding for Ada

Overview

OpenGLAda is a thick OpenGL binding for the Ada 2005 programming language. Unlike other, thin, bindings (see the project's homepage for a list), OpenGLAda enriches the original API with concepts and features provided by Ada, like object orientation, type safety and generics.

OpenGLAda provides the following libraries:

Library nameAlire crate nameDescription
openglopengladaThe OpenGL binding itself
opengl-glfwopenglada_glfwGLFW binding
opengl-textopenglada_textText rendering library
opengl-imagesopenglada_imagesImage loading library

The library name is what you want to with in your .gpr file, e.g. with "opengl-glfw";. The Alire crate is how you refer to the library if you're using Alire, e.g. alr with openglada.

The GLFW binding requires the GLFW library. The Text rendering library requires the FreeType library. The Image loading library uses GID.

The GLFW and FreeType dependencies will be fetched automatically by Alire on Windows, Debian, Ubuntu and Arch Linux. On other systems, you need to make them available to the linker yourself.

OpenGLAda supports macOS, Windows and X11-based systems. API documentation can be found on the project's homepage.

Migrating from C

Compared to C, OpenGLAda provides the features of the following C libraries:

Installation

OpenGLAda is designed to be used with the Alire package manager. You can instead install the projects via gprbuild + gprinstall. This needs to be done for each project you want to use.

Scenario Variables

OpenGLAda defines a number of scenario variables. Some are set automatically by Alire, others need to be changed manually with the -X command line parameter (either through alr or grpbuild).

The available variables are:

A typical Windows installation would be

$ cd opengl
$ gprbuild -p -XWindowing_System=windows -Xmode=release opengl.gpr
$ gprinstall -XWindowing_System=windows -Xmode=release opengl.gpr

Tests

The tests in this repository are small programs that are mainly used to check if the basic system is working. You can build them with

$ env GPR_PROJECT_PATH=opengl:opengl-glfw:opengl-images:opengl-text \
      alr build

The tests use Alire for fetching the dependencies, but do not use the Alire projects of the libraries. The Alire workspace for the tests is not meant to be published.

Examples

Examples are available in this repository.

Developer Documentation

I have written an article about the development of OpenGLAda on AdaCore's blog:

Binding Generation

OpenGL implementations do not necessarily provide the newest OpenGL version, but possibly some older one with some functionality of the newer versions provided as extensions. For OpenGLAda, this means that most OpenGL functionality cannot be linked against via the library loader, since loading the library would immediately fail if any function is not available, even if the user never calls it. Most notoriously, Windows does not provide any OpenGL functionality newer than 1.1 via library loading.

The remedy for this is that function pointers of newer OpenGL functions must be queried at runtime. This is a tedious process and similar for each function. For this reason, OpenGLAda uses a code generator to autogenerate the function pointer types and the code loading each function, as well as the code importing OpenGL 1.1 functions via library loading.

The code generator can be found in opengl/src/generator. It processes the files found in opengl/src/specs and creates the files found in opengl/src/generated. The generator is a tool used at compile-time for building OpenGLAda and of no interest to the general user. The generated files are checked in to version control. The generator also generates the markdown file which is the base for the function mapping list on the website.

The process of wrapping a new OpenGL function is:

The *.spec files use a syntax similar to Ada.

License

OpenGLAda, as well as the Ada dependencies FreeTypeAda and GID, are distributed under the terms of the MIT License.

The Ada 2012 logo that is used in the images tests is distributed under the terms of the CC BY-ND 3.0 license, the original author is AdaCore.