Coder Social home page Coder Social logo

zglfw's Introduction

zGLFW

A thin, idiomatic wrapper for GLFW. Written in Zig, for Zig!

Why write a wrapper?

While Zig is PERFECTLY capable of simply @cImporting glfw3.h and using it in your application, I think it lacks a lot of cleanliness and succinctness that can be expressed with Zig. I decided to write this wrapper to provide GLFW with a nicer interface, error handling options, and quality of life changes (for example []const u8 instead of [*c]const u8). It also uses nicely named constants in place of #defines.

zGLFW is NOT 100% tested. I am happy to fix any errors that may arise, and I will accept contributions! Errors that arise from GLFW will be printed to stderr.

Examples

const std = @import("std");
const glfw = @import("glfw");

pub fn main() !void {
    var major: i32 = 0;
    var minor: i32 = 0;
    var rev: i32 = 0;

    glfw.getVersion(&major, &minor, &rev);
    std.debug.print("GLFW {}.{}.{}\n", .{ major, minor, rev });

    //Example of something that fails with GLFW_NOT_INITIALIZED - but will continue with execution
    //var monitor: ?*glfw.Monitor = glfw.getPrimaryMonitor();

    try glfw.init();
    defer glfw.terminate();
    std.debug.print("GLFW Init Succeeded.\n", .{});

    var window: *glfw.Window = try glfw.createWindow(800, 640, "Hello World", null, null);
    defer glfw.destroyWindow(window);

    while (!glfw.windowShouldClose(window)) {
        if (glfw.getKey(window, glfw.KeyEscape) == glfw.Press) {
            glfw.setWindowShouldClose(window, true);
        }

        glfw.pollEvents();
    }
}

Documentation

I would suggest you look into the glfw.zig file themselves, as most of the changes are simple syntactically, but I have made some comments in cases where it may be different than you expect. Obviously GLFW's Documentation should cover most things that you want to know.

zglfw's People

Contributors

alichraghi avatar bluesillybeard avatar eriksik2 avatar exonorid avatar flecart avatar iridescentrose avatar rylmovuk avatar squamto avatar thehonesthare avatar wiktorjanecki avatar xtian 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

Watchers

 avatar  avatar  avatar  avatar

zglfw's Issues

Building issues

Hi, I am trying to use glfw in my program, however I'm having two problems :

I copy pasted the example from the readme and zig complains :

.\libs\zglfw\src\main.zig:193:5: error: enum tag value 348 already taken    Last              = 348,    ^.\libs\zglfw\src\main.zig:192:5: note: other occurrence here
    Menu              = 348,
    ^.\src\main.zig:14:40: note: referenced here        if(glfw.getKey(window, glfw.Key.Escape) == glfw.KeyState.Press){
                                       ^
Kizzle...The following command exited with error code 1:
D:\src\zig\zig.exe build-exe C:\Users\infrandomness\Documents\Dev\Zig\Kizzle\src\main.zig --cache-dir C:\Users\infrandomness\Documents\Dev\Zig\Kizzle\zig-cache --global-cache-dir C:\Users\infrandomness\AppData\Local\zig --name Kizzle --pkg-begin glfw C:\Users\infrandomness\Documents\Dev\Zig\Kizzle\libs\zglfw\src\main.zig --pkg-end --pkg-begin vulkan C:\Users\infrandomness\Documents\Dev\Zig\Kizzle\zig-cache\vk.zig --pkg-end --enable-cache   
error: the following build command failed with exit code 1:
C:\Users\infrandomness\Documents\Dev\Zig\Kizzle\zig-cache\o\61e4c8c9e63ef6ebb86c346b218b33e2\build.exe D:\src\zig\zig.exe C:\Users\infrandomness\Documents\Dev\Zig\Kizzle C:\Users\infrandomness\Documents\Dev\Zig\Kizzle\zig-cache C:\Users\infrandomness\AppData\Local\zig

The second problem is probably more my environment but I have no idea how to fix it :
I removed the whole example, only letting

try glfw.init();
defer glfw.terminate();

but my linker complains

lld-link: error: undefined symbol: glfwInit
>>> referenced by C:\Users\infrandomness\Documents\Dev\Zig\Kizzle\libs\zglfw\src\main.zig:485
>>>               C:\Users\infrandomness\Documents\Dev\Zig\Kizzle\zig-cache\o\ce1583ec703202b46e48b9e05c05eb23\Kizzle.obj:(.glfw.init)

lld-link: error: undefined symbol: glfwTerminate
>>> referenced by C:\Users\infrandomness\Documents\Dev\Zig\Kizzle\libs\zglfw\src\main.zig:520
>>>               C:\Users\infrandomness\Documents\Dev\Zig\Kizzle\zig-cache\o\ce1583ec703202b46e48b9e05c05eb23\Kizzle.obj:(.glfw.terminate)

This probably just mean I am missing a library or doing something wrong

Should `getProcAddress` return `?GLproc`?

glfw.getProcAddress("glAccumxOES") returns a nullptr because I'm not using OpenGLES, yet this is not accounted for in the type signature. Should it return ?GLproc instead of GLproc?

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.