tiny_gl/lib.rs
1#![no_std]
2
3#[cfg(feature = "alloc")]
4extern crate alloc;
5
6pub mod gl;
7pub(crate) mod types;
8pub(crate) mod utils;
9pub mod wgl;
10
11use core::ffi::{c_void, CStr};
12
13/// Load OpenGL and WGL functions, using the provided function to get the address of each function.
14/// This needs to be called before using any OpenGL or WGL functions.
15///
16/// # Example
17///
18/// ```ignore
19/// use windows_sys::Win32::Graphics::OpenGL::wglGetProcAddress;
20/// use windows_sys::Win32::System::LibraryLoader::{GetProcAddress, LoadLibraryA};
21///
22/// let opengl32 = LoadLibraryA(c"opengl32.dll".as_ptr() as _);
23///
24/// unsafe {
25/// tiny_gl::load(|name| {
26/// let addr = wglGetProcAddress(name.as_ptr() as _).map(|ptr| ptr as *const c_void).unwrap_or(core::ptr::null());
27/// if addr.is_null() {
28/// GetProcAddress(opengl32, name.as_ptr() as _).unwrap() as _
29/// } else {
30/// addr as _
31/// }
32/// });
33/// }
34/// ```
35pub unsafe fn load(get_proc_address: impl Fn(&CStr) -> *const c_void + Copy) {
36 gl::ffi::load(get_proc_address);
37 wgl::ffi::load(get_proc_address);
38}