Go cross-platform glfw library for creating an OpenGL context and receiving events.

glfw

Build Status GoDoc

Package glfw experimentally provides a glfw-like API with desktop (via glfw) and browser (via HTML5 canvas) backends.

It is used for creating a GL context and receiving events.

Note: This package is currently in development. The API is incomplete and may change.

Installation

go get -u github.com/goxjs/glfw
GOARCH=js go get -u -d github.com/goxjs/glfw

Directories

Path Synopsis
test/events events hooks every available callback and outputs their arguments.

License

Owner
Go cross-platform packages.
null
Comments
  • Open() unused?

    Open() unused?

    It appears that Open is unused by the package. I'm guessing you added it for font loading before they were embedded? If it isn't required, removing it would also kill the dependency on "honnef.co/go/js/xhr".

  • Implement SetSize

    Implement SetSize

    Move existing code for setting canvas size to SetSize(). Maintains existing behavior of filling the browser window by default.

    I'm not sure how to test this besides running it with a demo. It works for a tetris demo: https://github.com/Omustardo/tetris/tree/master/webgl-tetris

  • Handle WebGL context creation in browser.

    Handle WebGL context creation in browser.

    • Create ContextSwitcher interface.
    • Require ContextSwitcher in Init.
    • Allow use of arbitrary gl bindings by removing coupling with github.com/shurcooL/gogl.

    Depends on https://go-review.googlesource.com/8793.

  • Rename and move package.

    Rename and move package.

    I've named it goglfw because I couldn't use the glfw name under my github username namespace, and I wanted to indicate that it's somehow different from normal glfw (i.e. it's a cross-platform package that works on desktop and in browser). However, despite the import path having base goglfw, the package is typically renamed glfw (import glfw ".../goglfw"), which makes things confusing.

    Move it under https://github.com/goxjs namespace and rename it to glfw. So the new import path will be:

    import "github.com/goxjs/glfw"
    

    That'll solve both problems.

  • error when building with gollvm

    error when building with gollvm

    c_glfw-logs.zip $ go get -u github.com/goxjs/glfw

    github.com/go-gl/glfw/v3.3/glfw

    fatal error: error in backend: Segmented stacks do not support vararg functions. PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script. Stack dump: 0. Program arguments: /usr/bin/clang -I ../../go/src/github.com/go-gl/glfw/v3.3/glfw -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build507152346/b002=/tmp/go-build -gno-record-gcc-switches -funwind-tables -I $WORK/b002/ -g -O2 -D_GLFW_X11 -D_GNU_SOURCE -fsplit-stack -o $WORK/b002/_x003.o -c c_glfw.cgo2.c

    1. parser at end of file
    2. Code generation
    3. Running pass 'Function Pass Manager' on module 'c_glfw.cgo2.c'.
    4. Running pass 'Prologue/Epilogue Insertion & Frame Finalization' on function '@_glfwInputError' #0 0x00000000022bcf54 PrintStackTraceSignalHandler(void*) (/usr/bin/clang+0x22bcf54) #1 0x00000000022bacde llvm::sys::RunSignalHandlers() (/usr/bin/clang+0x22bacde) #2 0x00000000022bc1fd llvm::sys::CleanupOnSignal(unsigned long) (/usr/bin/clang+0x22bc1fd) #3 0x000000000224db9a (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) (/usr/bin/clang+0x224db9a) #4 0x000000000224db3b (/usr/bin/clang+0x224db3b) #5 0x00000000022b748e (/usr/bin/clang+0x22b748e) #6 0x00000000009baf32 (/usr/bin/clang+0x9baf32) #7 0x000000000225133f llvm::report_fatal_error(llvm::Twine const&, bool) (/usr/bin/clang+0x225133f) #8 0x0000000002251218 (/usr/bin/clang+0x2251218) #9 0x00000000014e3357 llvm::X86FrameLowering::adjustForSegmentedStacks(llvm::MachineFunction&, llvm::MachineBasicBlock&) const (/usr/bin/clang+0x14e3357) #10 0x0000000001ac4043 (anonymous namespace)::PEI::runOnMachineFunction(llvm::MachineFunction&) (/usr/bin/clang+0x1ac4043) #11 0x00000000019f571e llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/usr/bin/clang+0x19f571e) #12 0x0000000001cf8d39 llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/bin/clang+0x1cf8d39) #13 0x0000000001cfe6d3 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/bin/clang+0x1cfe6d3) #14 0x0000000001cf94eb llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/bin/clang+0x1cf94eb) #15 0x000000000247cd19 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_deletellvm::raw_pwrite_stream >) (/usr/bin/clang+0x247cd19) #16 0x0000000002f3db46 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/usr/bin/clang+0x2f3db46) #17 0x0000000003930133 clang::ParseAST(clang::Sema&, bool, bool) (/usr/bin/clang+0x3930133) #18 0x00000000029c4727 clang::FrontendAction::Execute() (/usr/bin/clang+0x29c4727) #19 0x00000000029607c1 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/bin/clang+0x29607c1) #20 0x0000000002a5d12a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/bin/clang+0x2a5d12a) #21 0x00000000009babc7 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/bin/clang+0x9babc7) #22 0x00000000009b8eb1 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) (/usr/bin/clang+0x9b8eb1) #23 0x00000000028395a2 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optionalllvm::StringRef >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool) const::$_1>(long) (/usr/bin/clang+0x28395a2) #24 0x000000000224db1d llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/usr/bin/clang+0x224db1d) #25 0x0000000002838abf clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optionalllvm::StringRef >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool) const (/usr/bin/clang+0x2838abf) #26 0x000000000280b32e clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/usr/bin/clang+0x280b32e) #27 0x000000000280b4d7 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/usr/bin/clang+0x280b4d7) #28 0x0000000002821a08 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/usr/bin/clang+0x2821a08) #29 0x00000000009b893c main (/usr/bin/clang+0x9b893c) #30 0x00007f0a9d4130b3 __libc_start_main /build/glibc-ZN95T4/glibc-2.31/csu/../csu/libc-start.c:342:3 #31 0x00000000009b5f4e _start (/usr/bin/clang+0x9b5f4e) clang-11: error: clang frontend command failed with exit code 70 (use -v to see invocation) clang version 11.0.0 (https://github.com/llvm/llvm-project.git 0160ad802e899c2922bc9b29564080c22eb0908c) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /usr/bin clang-11: note: diagnostic msg:

    PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang-11: note: diagnostic msg: /tmp/c_glfw-fa465c.c clang-11: note: diagnostic msg: /tmp/c_glfw-fa465c.sh

    clang-11: note: diagnostic msg:


    Hello. Caught this bug, while building your project:

    c_glfw-logs.zip

  • Add WebAssembly support.

    Add WebAssembly support.

    This change is a work in progress on adding support for WebAssembly to package glfw, while maintaining GopherJS support.

    It's done by differentiating code for WebAssembly (which uses syscall/js API) from existing code for GopherJS (which uses github.com/gopherjs/gopherjs/js API) with the following build constraints:

    _js.go

    // +build js,!wasm
    
    ... GopherJS code ...
    

    _wasm.go

    // +build js,wasm
    
    ... WebAssembly code ...
    

    It has been developed and tested primarily with the Hover and eX0-go projects.

  • Implement close callback

    Implement close callback

    This PR implements the close callback via the browser's beforeunload event, which is fired just prior to the page being unloaded.

    Note: We should mention there are some limitations on what the callback handler can do with the DOM depending on the browser. In some, opening a dialog is not allowed (to prevent annoying pop-ups).

  • Implement focus callback

    Implement focus callback

    Resolves #12.

    This uses the browser's focus and blur events to implement the focus callback, which is informed when the browser window is in focus (active window) or not.

    Depending on whether or not we want to consider multiple tabs as "all focused" or if each is focused individually, we may need to change the listener to attach to the document instead of the window. I have not explored browser functionality related to that.

  • Implement focus callback for browser

    Implement focus callback for browser

    Modern browsers implement the Page Visibility API which emits an event visibilitychange when a browser page is either hidden or made visible. The current visibility of a page can be found via document.hidden.

    This can be used to implement the focus callback in the browser:

    document.addEventListener('visibilitychange', (e) => focusCB(!document.hidden));
    
  • OS/Browser Specific Mouse Wheel Events

    OS/Browser Specific Mouse Wheel Events

    In comparison to the high level discussion of handling mouse wheel events in https://github.com/goxjs/glfw/issues/10 this issue is to look into specific instances of wheel event behavior.

    The basic issue is that mouse "wheel" events provide extremely different delta values on different systems. At minimum browser, OS, and hardware are likely to play a role. For example, on Chrome+Win10, each step of a mouse scroll wheel results in a wheel event with delta value 120. On Firefox+Win10 the delta is 3.

    The values goxjs/glfw is getting can be found manually for your system in the web console of: https://dmitri.shuralyov.com/projects/touch/scroll.html To see the base values that the system is sending to the browser, use gopherjs serve and navigate to: http://localhost:8080/github.com/goxjs/glfw/test/events/

    A list of some values can be found here: http://stackoverflow.com/q/5527601/3184079

Related tags
Go cross-platform OpenGL bindings.

gl Package gl is a Go cross-platform binding for OpenGL, with an OpenGL ES 2-like API. It supports: macOS, Linux and Windows via OpenGL 2.1 backend, i

Nov 21, 2022
Go bindings for GLFW 3

GLFW 3.3 for Go Installation GLFW C library source is included and built automatically as part of the Go package. But you need to make sure you have d

Jan 8, 2023
Go bindings for GLFW 3

GLFW 3.3 for Go Installation GLFW C library source is included and built automatically as part of the Go package. But you need to make sure you have d

Dec 25, 2022
Go bindings to OpenGL Utility Library

GLU This package offers minimal bindings for GLU functions. Usage go get github.com/go-gl-legacy/glu License Copyright 2012 The go-gl Authors. All ri

Aug 18, 2018
Canvas is a Go drawing library based on OpenGL or using software rendering that is very similar to the HTML5 canvas API
Canvas is a Go drawing library based on OpenGL or using software rendering that is very similar to the HTML5 canvas API

Go canvas Canvas is a pure Go library that provides drawing functionality as similar as possible to the HTML5 canvas API. It has nothing to do with HT

Jan 3, 2023
Quake 2 Level Renderer written in Go and OpenGL
Quake 2 Level Renderer written in Go and OpenGL

go-quake2 Quake 2 Map Renderer written in Go and OpenGL. Features Loads any BSP file from Quake 2 Free roam around the environment Renders only a smal

Jan 4, 2023
A Pong clone made from scratch with Go and C using OpenGL 3.3

Go-Pong A Pong video game clone made with Go lang and OpenGL 3.3 using C. Gameplay Offline Key bindings are 'w' and 's' for the left player and 'up ar

Feb 10, 2022
golang OpenGL helper functions

glh: golang OpenGL helpers This package contains a number of functions useful for applications using OpenGL. Code Reference Features Textures and Text

Apr 8, 2022
Go bindings for OpenGL (generated via glow)

gl This repository holds Go bindings to various OpenGL versions. They are auto-generated using Glow. Features: Go functions that mirror the C specific

Dec 12, 2022
OpenGL binding generator for Go

GoGL GoGL is an OpenGL binding generator for Go. No external dependencies like GLEW are needed. Install the OpenGL bindings For example, OpenGL 2.1 bi

Dec 25, 2022
OpenGL renderer

oglr About oglr is a package for Go to load OpenGL functions and render graphics. It is published on https://github.com/vbsw/oglr. Copyright Copyright

Jun 21, 2022
A cross-platform tool to convert images into ascii art and print them on the console
A cross-platform tool to convert images into ascii art and print them on the console

A cross-platform tool to convert images into ascii art and print them on the console

Dec 30, 2022
HTML Canvas 2D Context API for mobile, desktop and web

canvas HTML Canvas 2D Context API for mobile, desktop and web Context2D API https://www.w3.org/TR/2dcontext/ native code implement https://github.com/

Apr 22, 2022
A go library for reading and creating ISO9660 images

iso9660 A package for reading and creating ISO9660, forked from https://github.com/kdomanski/iso9660. Requires Go 1.13 or newer. Joliet and Rock Ridge

Mar 4, 2021
Paprika is a toolbox for creating short clips from multiple png files.
Paprika is a toolbox for creating short clips from multiple png files.

Paprika Paprika is a toolbox for creating short clips from multiple png files. Requirements This program is mainly a wrapper around ffmpeg. As such, y

Feb 16, 2022
Code for creating GIF replays of games played on Woogles.io.

woogles-game-gifs Code for creating GIF replays of games played on Woogles.io. Requirements Go is required to run the gif generator. To install, refer

Jan 31, 2022
The android-go project provides a platform for writing native Android apps in Go programming language.
The android-go project provides a platform for writing native Android apps in Go programming language.

android-go The android-go project aims to provide a platform (namely an SDK) for writing native Android apps in Go programming language. All things he

Jan 5, 2023
This is old and unmaintained code, ignore it. starfish is a simple, SDL based, 2D graphics and user input library for Go. If you intend to work on it, please fork from the 'devel' branch, not 'master'. Current release: 0.12.0

What is starfish? What starfish is: starfish is a simple 2D graphics and user input library for Go built on SDL. What starfish is not: While it is bui

Jun 4, 2019
General purpose library for reading, writing and working with OpenStreetMap data

osm This package is a general purpose library for reading, writing and working with OpenStreetMap data in Go (golang). It has the ability to read OSM

Dec 30, 2022