Git Product home page Git Product logo

gl_loader's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.