Crates.io | gl_loader |
lib.rs | gl_loader |
version | 0.1.2 |
source | src |
created_at | 2019-03-15 16:10:26.097529 |
updated_at | 2019-03-19 10:28:43.928665 |
description | Simple OpenGL function pointer loader based on Glad. |
homepage | |
repository | https://github.com/maeln/gl_loader |
max_upload_size | |
id | 121059 |
size | 10,274 |
gl_loader
: an OpenGL function pointer loader based on GladThis (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
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.
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.
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.
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.
Right now, some of the dependencies are relying on the std.
The final goal is to make the package fully #![no_std]
compatible.
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