Go cross-platform OpenGL bindings.

gl Build Status GoDoc

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,

  • iOS and Android via OpenGL ES 2.0 backend,

  • Modern Browsers (desktop and mobile) via WebGL 1.0 backend.

This is a fork of golang.org/x/mobile/gl package with CL 8793 merged in and Windows support added. This package is fully functional, but may eventually become superceded by the new x/mobile/gl plan. It will exist and be fully supported until it can be safely replaced by a better package.

Installation

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

Usage

This OpenGL binding has a ContextWatcher, which implements glfw.ContextWatcher interface. Recommended usage is with github.com/goxjs/glfw package, which accepts a ContextWatcher in its Init, and takes on the responsibility of notifying it when context is made current or detached.

if err := glfw.Init(gl.ContextWatcher); err != nil {
	// Handle error.
}
defer glfw.Terminate()

If you're not using a ContextWatcher-aware glfw library, you must call methods of gl.ContextWatcher yourself whenever you make a context current or detached.

window.MakeContextCurrent()
gl.ContextWatcher.OnMakeCurrent(nil)

glfw.DetachCurrentContext()
gl.ContextWatcher.OnDetach()
Owner
Go cross-platform packages.
null
Comments
  • gl.Init called without a current context on Windows backend, and fails.

    gl.Init called without a current context on Windows backend, and fails.

    I gave the Windows build a try, and unfortunately we get a fatal error on start up initializing gl: gl.Init: glActiveTexture

    I believe the problem is that gl.Init must be called after MakeCurrentContext as wglGetProcAddress requires a bound context: When no current rendering context exists or the function fails, the return value is NULL.

    Originally reported in https://github.com/google/gxui/pull/86#issuecomment-107037914.

  • Unable to Get Current Frame Buffer In Webgl

    Unable to Get Current Frame Buffer In Webgl

    There are points where I need to get the current frame buffer, bind another, then bind the first one however right now it is not really possible to do that in web gl. Normally I would call gl.GetInteger(gl.FRAMEBUFFER_BINDING) but that always returns 0 and wont allow me to bind to it. According to this https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bindFramebuffer I would need to call getParameter on the context to get the current frame buffer. It is hard to name a solution to this since adding a GetCurrentFrameBuffer() method would change the whole api. Also I was thinking exposing the context so I can call any function on it but again that does not work for a uniform API.

    Let me know if I have missed a solution, that could be possible as well.

  • Suggestion: add basic examples.

    Suggestion: add basic examples.

    any chance on getting some basic examples, to have a base to work from ?

    i am quite excited about this project and eager to see how well opengl and webgl can work together.

  • JS TexImage2D produces TypeError

    JS TexImage2D produces TypeError

    TypeError: Argument 9 of WebGLRenderingContext.texImage2D does not implement interface ArrayBufferViewOrNull on Firefox 42.0 and Uncaught TypeError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': parameter 9 is not of type 'ArrayBufferView' on Chrome 48.0.2564.109.

    AFAIK the data parameter of gl.TexImage2D is a []byte which becomes a Uint8Array in GopherJS... which should satisfy the WebGL standard which calls for an ArrayBufferView.

    For comparison, gl.BufferData takes a []byte and works fine. The only difference I can see is that the WebGL spec for bufferData specifies a BufferDataSource? (which is defined as an ArrayBufferView or an ArrayBuffer in the spec) and not an ArrayBufferView? type for the data parameter.

  • Difference with webgl?

    Difference with webgl?

    Whats the difference between this library https://github.com/ajhager/webgl and yours it seems both support the same functionality and API, and both are cross platform and I see you made a commit there also

  • Supported OpenGL version

    Supported OpenGL version

    It seems odd that you are using OpenGL 2.1 for desktops but ES2 for mobile. Doesn't the ES2 spec basically match OpenGL 3.3? Is there more detail that I'm missing?

  • Can't get second attribute location

    Can't get second attribute location

    Hi, I took the triangle example and just added the lines bellow: ... attribute vec3 aVertexPosition; attribute vec3 aVertexPosition2; ... vertexPositionAttrib := gl.GetAttribLocation(program, "aVertexPosition") fmt.Printf("vertexPositionAttrib = %d", vertexPositionAttrib) vertexPositionAttrib2 := gl.GetAttribLocation(program, "aVertexPosition2") fmt.Printf("vertexPositionAttrib2 = %d", vertexPositionAttrib2) ...

    I build it with gopherjs and the value of vertexPositionAttrib2 is -1.

    Did I missed something?

    Regards,

    Marc

  • Wasm

    Wasm

    Update the wasm branch to work with more recent dependencies and try to reduce code difference for user of the package between the Gopherjs use and Wasm use.

  • Does anyone want Windows support?

    Does anyone want Windows support?

    Right now this package supports OS X, Linux, and browsers.

    Windows is currently not supported. I can add it very easily, it would take me an hour or so, but I wouldn't want to spend time on it unless people actually want/need it (I don't use Windows myself).

    If you're using this package (or considering it) and want Windows backend added, just leave a +1 here.

  • Adding in support for GetBoundBuffer

    Adding in support for GetBoundBuffer

    Adding in support for all platforms to resolve #20

    I tested the webgl and opengl wrappers however I cannot init my new install of gomobile because it keeps giving me an incorrect sha256 so can you please ensure that it builds. I am sure if it builds it will run.

  • WebGL GetIntegerv: not yet tested [Confirmed Functional]

    WebGL GetIntegerv: not yet tested [Confirmed Functional]

    Wanted to give some feedback that this seems to be functional. I will probably be confirming a few more of these over the next few days.

    gl.GetIntegerv(gl.VIEWPORT, viewport)
    

    returns [0 0 300 150] and I checked my context and it says WebGLRenderingContext {canvas: canvas, drawingBufferWidth: 300, drawingBufferHeight: 150}

  • Maintenance and Supersession

    Maintenance and Supersession

    This package is fully functional, but may eventually become superceded by the new x/mobile/gl plan.

    Yet, over 4 years after that sentence was written, I couldn't find any updates on WebGL support being added to the golang.org/x/mobile/gl package.

    Is there actually any work at all being done with that (and I just missed it), or is supersession by x/mobile/gl entirely a hypothetical?

    If it's the latter, it might be about time that the README sees another update to more accurately reflect the current state of this package..?

  • README: stop suggesting GOARCH=js go get since it no longer works

    README: stop suggesting GOARCH=js go get since it no longer works

    I am sorry, this may be very basic but I am trying to use this library and I try to run

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

    I get unsupported GOOS/GOARCH pair darwin/js I have tried a series of pairs like js/js or /js or js/darwin and I get the same message everytime.

    Am I doing something wrong? does the library need to be updated?

  • Update to newest

    Update to newest "golang.org/x/mobile/gl"

    I'm currently investigating my options for writing an OpenGL application for both desktop and web and this repository seems the be the best candidate - good work!

    It is a while since it was forked from "golang.org/x/mobile/gl" and it seems that there were quite some major changes - adding WebGL support wasn't one of them. One change I like particularly is the render-thread: Applications use a glctx-object that exposes the OpenGL functionality, but the calls to that context are only pushed into a channel and executed later by a dedicated render thread. This improves multithreading / go-routine support greatly.

    I'm not able to use "golang.org/x/mobile/gl" due to the lack of WebGL support (I don't need to support mobile). And I also don't like the fact that desktop applications require the ANGLE dlls instead of using the OpenGL bindings from go-gl - but I can live with that.

    Is it possible for goxjs to adapt those features or to be updated to the newest version of golang.org/x/mobile/gl? Which changes would be required to do so?

  • Add WebAssembly support.

    Add WebAssembly support.

    This change is a work in progress on adding support for WebAssembly to package gl, 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.

  • Attrib.Value is int for webgl and uint for opengl?

    Attrib.Value is int for webgl and uint for opengl?

    In attempting to cross-compile a program for both WebGL and Desktop OpenGL, I've noticed that the Attrib type is uint for the former, and int for the latter. This makes it a little hard to manipulate these in a portable way.

    Is there a technical reason why these are different, or could they be brought into alignment?

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

glfw Package glfw experimentally provides a glfw-like API with desktop (via glfw) and browser (via HTML5 canvas) backends. It is used for creating a G

Sep 27, 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
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
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
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
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
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
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
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
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 for audio capture and playback with ALSA and libasound

Go ALSA bindings These bindings allow capture and playback of audio via ALSA using the alsa-lib library. Installation go get github.com/cocoonlife/goa

Nov 26, 2022
naive go bindings to GnuPlot
naive go bindings to GnuPlot

go-gnuplot Simple-minded functions to work with gnuplot. go-gnuplot runs gnuplot as a subprocess and pushes commands via the STDIN of that subprocess.

Nov 8, 2021
go-gtk3 - GTK3 BINDINGS FOR GO

go-gtk3 - GTK3 BINDINGS FOR GO THIS IS: Hopefully GTK3 Bindings using gobject binding for Go. Goal is to have fairly complete gtk3 widgets with pango

May 25, 2021
Experimental OpenAL bindings for Go.

Experimental OpenAL bindings for Go. ==================================== Everything is evolving quickly and nothing is totally done. If you want to

Jul 24, 2022
Go bindings for OpenCV / 2.x API in gocv / 1.x API in opencv

Go OpenCV binding A Golang binding for OpenCV. OpenCV 1.x C API bindings through CGO, and OpenCV 2+ C++ API (GoCV) through SWIG. Disclaimer This is a

Dec 21, 2022
Go bindings for GStreamer (retired: currently I don't use/develop this package)

Retired. I don't use/develop this package anymore. Go bindings for GStreamer at a very early stage of maturity. This package is based on GLib bindings

Nov 10, 2022
Go bindings for libVLC and high-level media player interface
Go bindings for libVLC and high-level media player interface

Go bindings for libVLC 2.X/3.X/4.X and high-level media player interface. The package can be useful for adding multimedia capabilities to applications

Dec 31, 2022