Coder Social home page Coder Social logo

masterq32 / zig-opengl Goto Github PK

View Code? Open in Web Editor NEW
95.0 7.0 14.0 821 KB

OpenGL binding generator based on the opengl registry

License: European Union Public License 1.2

Makefile 6.01% Zig 2.47% C# 90.07% Shell 1.45%
zig gamedev opengl-loader zig-package ziglang opengl opengl-es

zig-opengl's Introduction

Zig OpenGL Binding

This is a pragmatic binding to different OpenGL versions.

It uses the official OpenGL Registry by Khronos to generate the Zig code.

Right now, it does minimal adjustments like removing the gl prefix from functions or the GL_ prefix from constants. Everything else is the same as the C API.

There is a single non-OpenGL function exported:

pub fn load(load_ctx: anytype, get_proc_address: fn(@TypeOf(load_ctx), [:0]const u8) ?*FunctionPointer) !void {

This function will load all OpenGL entry points with the help of get_proc_address. It receives the load_ctx as well as the function name.

NOTE: Please do not reference zig-opengl as a submodule or a package. Generate a binding and copy the output of that into your repository and update the file on demand. The OpenGL Registry is just too huge to be used conveniently.

Cloning submodules is required, so use --recursive:

git clone --recursive https://github.com/MasterQ32/zig-opengl.git

Example

This example uses ZWL by @Aransentin.

const zwl = @import("zwl");

const Platform = zwl.Platform(…);

pub fn initAndDraw(window: Platform.Window) !void {
  try gl.load(window.platform, Platform.getOpenGlProcAddress);

  while(true) {
    gl.clearColor(1, 0, 1, 1);
    gl.clear(gl.COLOR_BUFFER_BIT);

    try window.present();
  }
}

Usage with mach-glfw

There is an example of mach-glfw + zig-opengl usage available here: https://github.com/hexops/mach-glfw-opengl-example

Pregenerated Loaders

This repository contains pre-generated bindings for all extension-free OpenGL versions.

Generating your own loader

From source

To generate your own loader, you have to clone this repository and build the generator with dotnet:

user@machine:~/zig-opengl$ dotnet run
Usage: generator <registry> <result> <api_version> [<extension>] [<extension>] ...
user@machine:~/zig-opengl$ dotnet run OpenGL-Registry/xml/gl.xml gl3v3.zig GL_VERSION_3_3
Final API has 344 commands and 818 enums types.
user@machine:~/zig-opengl$
dotnet run \
  OpenGL-Registry/xml/gl.xml \ # path to the opengl registry
  my_binding.zig             \ # path to the generated file
  GL_VERSION_3_3             \ # feature level, options listed below
  …                            # Add your extensions here, each as a single arg. Or let them out, you don't need extensions

Possible feature levels (at the time of writing) are:

  • GL_VERSION_1_0
  • GL_VERSION_1_1
  • GL_VERSION_1_2
  • GL_VERSION_1_3
  • GL_VERSION_1_4
  • GL_VERSION_1_5
  • GL_VERSION_2_0
  • GL_VERSION_2_1
  • GL_VERSION_3_0
  • GL_VERSION_3_1
  • GL_VERSION_3_2
  • GL_VERSION_3_3
  • GL_VERSION_4_0
  • GL_VERSION_4_1
  • GL_VERSION_4_2
  • GL_VERSION_4_3
  • GL_VERSION_4_4
  • GL_VERSION_4_5
  • GL_VERSION_4_6
  • GL_VERSION_ES_CM_1_0
  • GL_ES_VERSION_2_0
  • GL_ES_VERSION_3_0
  • GL_ES_VERSION_3_1
  • GL_ES_VERSION_3_2
  • GL_SC_VERSION_2_0

Contribution

This library uses a small C# script that generates the Zig bindings. It is located in src/Generator.cs

What is missing right now?

  • Option to specify core or compatibility profile.

zig-opengl's People

Contributors

artemisx64 avatar astral-shining avatar bratishkaerik avatar gaarco avatar game4all avatar ikskuh avatar mohamedmoussa89 avatar nathany avatar slimsag avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

zig-opengl's Issues

Clarify license for generated code

Does the EUPL apply to generated bindings, or just the generator program? glad for example licenses the generator under The MIT License, but generated code as "any of Public Domain, WTFPL or CC0." I think it would be helpful to either make the same distinction for zig-opengl, or explicitly state that generated bindings are also covered under EUPL.

Type is Used as a Parameter Name

type is used as a parameter name in a couple of functions, which prevents the bindings from compiling without modification. Presumably the code that generates the bindings could automatically rename these to something like gltype to make everything work out of the box.

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.