• Stars
    star
    95
  • Rank 354,083 (Top 7 %)
  • Language
    Ada
  • License
    MIT License
  • Created almost 13 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Thick Ada binding for OpenGL and GLFW

OpenGLAda – OpenGL binding for Ada

Project Status: I do not have the time and energy to maintain this project anymore. Both this project and the corresponding Alire crates are unmaintained. I would be okay with someone taking over the project, feel free to contact me about it.

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 name Alire crate name Description
opengl openglada The OpenGL binding itself
opengl-glfw openglada_glfw GLFW binding
opengl-text openglada_text Text rendering library
opengl-images openglada_images Image 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:

  • OpenGL

  • GLEW: OpenGLAda loads all post-OpenGL 1.1 subroutines dynamically via pointers, so that available features may be queried at runtime.

  • GLUT: Long deprecated, yet still referenced from articles about OpenGL. OpenGLAda provides an optional wrapper for the GLFW library that provides functionality similar to GLUT.

    Text rendering functionality superior to what GLUT provides are supplied by opengl-text.gpr with the help of the FreeType library.

  • Image loading: OpenGLAda includes the GID library for image loading.

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:

  • Auto_Exceptions: Configures exception handling:

    • enabled (default): After each call to OpenGL, OpenGLAda checks whether OpenGL has set an error flag and if it had, raises the corresponding exception.
    • disabled: The user has to query the error flag on their own.
  • mode: May take one of the following values:

    • debug (default): Compile the project with debugging symbols and without optimization.
    • release: Compile the project for a release environment.
  • Windowing_System: Automatically set by Alire. Sets the backend windowing system. Used for GLFW and also for system-dependent parts of the API (GLX, WGL, CGL):

    • x11: X Windowing System (Linux, BSD, etc)
    • windows: Microsoft Windows
    • quartz: Quartz Compositor (macOS)
  • GLFW_Linker_Param: Relevant for the GFLW binding. Define how you will link to GLFW. Default is -lglfw everywhere but on Windows with GLFW 3, in which case it is -lglfw3. No need to change this if the GLFW library is loaded via Alire.

  • FreeType_Linker_Param: Automatically set by Alire. Relevant for the text rendering library. Define how you will link to FreeType. Default is -lfreetype.

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:

  • Build the generator using gprbuild generator.gpr in the opengl directory.
  • Add the function specification to one of the *.spec files in opengl/src/specs.
  • Run ./generator in the opengl directory (or generator.exe on Windows), which runs the generator on the specs and generates the Ada code.
  • Check in the newly generated code along with the changed spec.

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.

More Repositories

1

NimYAML

YAML implementation for Nim
Nim
186
star
2

emerald

HTML5 templating engine for Nimrod
Nim
95
star
3

Zicross

Nix Flake for cross-compiling and packaging for foreign systems
Nix
55
star
4

OpenCLAda

An Ada binding for the OpenCL host API
Ada
15
star
5

DSA-LaTeX

LaTeX-Klasse und Dokumente für Das Schwarze Auge
TeX
14
star
6

DSA-4.1-Heldendokument

Konfigurierbares Heldendokument für DSA, basierend auf LuaLaTeX.
Lua
14
star
7

Nova-TeX-Suite

Nova support for TeX, LaTeX and ConTeXt
JavaScript
7
star
8

ParserTools

tools for writing lexers / parsers in Ada
Ada
6
star
9

libyaml_constructor

Code generator to load YAML into C types
C
6
star
10

ada-bundler

Library and tool for transparently handling data and configuration file access in an Ada application. Supports MacOSX, Linux and Windows.
Ada
5
star
11

gps-osx

Native GNAT Programming Studio for OSX
Ada
5
star
12

NovaZig

Zig support for the Nova editor
Scheme
4
star
13

nova-nix-suite

Nix extension for Nova.app
Scheme
4
star
14

OpenGLAda-examples

Examples for OpenGLAda
Ada
4
star
15

nix-flakes-go-plugins

Article about building Go applications that support plugins with Nix Flakes
Nix
4
star
16

zargo

2D OpenGL drawing lib for zig
C
2
star
17

askew

code generator & framework for single-page GopherJS/WASM apps
Go
2
star
18

js-audio-fiddle

Fiddling with the Web Audio API and stuff
JavaScript
1
star
19

DSA-Heldendokument-Generator

Java Bibliothek + GUI für plattformübergreifende DSA Heldendokumenterstellung
Java
1
star
20

Con-Checkliste

CSS
1
star
21

DSA-Liber-Reprints

Nix
1
star
22

soqualpoints

Punktemanagement für universitäre Übungsveranstaltungen
PHP
1
star
23

FreeTypeAda

FreeType binding for Ada 2012
Ada
1
star