#opengl #loader #gl #glad

gl_loader

Simple OpenGL function pointer loader based on Glad

6 releases

0.1.2 Mar 19, 2019
0.1.1 Mar 19, 2019
0.0.4 Mar 18, 2019

#485 in Graphics APIs

Download history 521/week @ 2024-03-13 1884/week @ 2024-03-20 824/week @ 2024-03-27 673/week @ 2024-04-03 539/week @ 2024-04-10 373/week @ 2024-04-17 231/week @ 2024-04-24 229/week @ 2024-05-01 241/week @ 2024-05-08 200/week @ 2024-05-15 221/week @ 2024-05-22 212/week @ 2024-05-29 203/week @ 2024-06-05 207/week @ 2024-06-12 167/week @ 2024-06-19 160/week @ 2024-06-26

768 downloads per month
Used in 3 crates

CECILL-2.1

10KB
141 lines

gl_loader: an OpenGL function pointer loader based on Glad

This (small) package aim to do only one thing: Provide a get_proc_address function to load OpenGL function pointer.

It will not provide any form of window or OpenGL context creation. You will have to handle them by yourself.

The code is simply a binding to the pointer loading part of the glad library: glad

Explanation

When using the OpenGL's headers, the function are just declaration, empty shell. Trying to call them will result in whatever happen when you try to use a null pointer as a function.

To really be able to use those functions, you need to load their pointer. The OS will provide them for you by usually exposing a getProcAddress function (or equivalent) which take the OpenGL function name and output its pointer.

Therefor, this crate aim to provide a OS-independant way to load the OpenGL function pointer.

Why

The main idea is to be able to make a OpenGL-based engine that is complitely agnostic from the GUI/Windowing library used. Let's say for exemple that you want to make an editor that use libGUI-X and package your final application with libWindow-Y. Both these system should handle the window and context creation but might have a way to load function pointer which is uncompatible or require you to do dirty hacks in your engine to handle both case.

By deffering the function pointer loading to this small library, you should be able to make your engine complitely agnostic as long as a proper OpenGL-context has been created and made current on the same thread.

How to use

First you will need the following requirement: 1 - An OpenGL context has been created and made current 2 - You are calling the get_proc_address from the same thread has the one which owns the current context

Then, using the gl crate, you should be able to just do:

extern crate gl_loader;

fn load_gl_symbol() {
    gl_loader::init_gl();
    gl::load_with(|symbol| gl_loader::get_proc_address(symbol) as *const _);
}

Your function pointer should be loaded and you should be able to use OpenGL.

NOTE:

You need to call gl_loader::init_gl() before calling gl_loader::get_proc_address(...), init_gl() will make sure that the OpenGL Library/Framework are properly loaded.

Goal

Right now, some of the dependencies are relying on the std. The final goal is to make the package fully #![no_std] compatible.

Credit

glutin contributors: The original code was based on the glutin source code.

glad contributors: The current code is a binding to the specific part of Glad that handle function pointer loading.

Fizzer and Ferris: For giving me the idea and explaining some of the specific to me

Dependencies

~225KB