{"id":28961380,"url":"https://github.com/erlangsters/opengl-4.6","last_synced_at":"2026-05-08T10:34:50.436Z","repository":{"id":298924286,"uuid":"862471792","full_name":"erlangsters/opengl-4.6","owner":"erlangsters","description":"OpenGL 4.6 binding for the BEAM (Erlang and Elixir).","archived":false,"fork":false,"pushed_at":"2025-08-20T17:29:03.000Z","size":222,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-20T19:34:25.207Z","etag":null,"topics":["binding","elixir","erlang","erlangsters","gl4","opengl"],"latest_commit_sha":null,"homepage":"https://about.erlangsters.org","language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/erlangsters.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-09-24T16:50:31.000Z","updated_at":"2025-08-20T17:29:06.000Z","dependencies_parsed_at":"2025-06-13T16:58:12.973Z","dependency_job_id":"da84caa1-d476-405c-bdd6-541bbb1d3b39","html_url":"https://github.com/erlangsters/opengl-4.6","commit_stats":null,"previous_names":["erlangsters/opengl-4.6"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/erlangsters/opengl-4.6","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erlangsters%2Fopengl-4.6","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erlangsters%2Fopengl-4.6/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erlangsters%2Fopengl-4.6/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erlangsters%2Fopengl-4.6/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erlangsters","download_url":"https://codeload.github.com/erlangsters/opengl-4.6/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erlangsters%2Fopengl-4.6/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32776898,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T08:22:46.396Z","status":"ssl_error","status_checked_at":"2026-05-08T08:22:45.650Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binding","elixir","erlang","erlangsters","gl4","opengl"],"created_at":"2025-06-24T02:02:40.917Z","updated_at":"2026-05-08T10:34:50.428Z","avatar_url":"https://github.com/erlangsters.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OpenGL 4.6 binding for the BEAM\n\n[![Erlangsters Repository](https://img.shields.io/badge/erlangsters-opengl--4.6-%23a90432)](https://github.com/erlangsters/opengl-4.6)\n![Supported Erlang/OTP Versions](https://img.shields.io/badge/erlang%2Fotp-28-%23a90432)\n![Current Version](https://img.shields.io/badge/version-1.0.0-%23354052)\n![License](https://img.shields.io/github/license/erlangsters/opengl-4.6)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/erlangsters/opengl-4.6/workflow.yml)](https://github.com/erlangsters/opengl-4.6/actions/workflows/workflow.yml)\n[![Documentation Link](https://img.shields.io/badge/documentation-available-yellow)](http://erlangsters.github.io/opengl-4.6/)\n\n\u003e [!WARNING]\n\u003e It's still in development and a first beta version will be available shortly.\n\u003e The master branch will be rewound!\n\nThis repository hosts the generated OpenGL 4.6 binding for the Erlang and\nElixir programming language. Only the core profile functions are exposed and\nloading custom OpenGL functions is not supported.\n\n```erlang\n{ok, Version} = gl:get_string(version).\nio:format(\"OpenGL version: ~p~n\", [Version]).\n```\n```elixir\n{:ok, version} = :gl.get_string(:version)\nIO.puts(\"OpenGL version: #{version}\")\n```\n\nIt works exclusively with the [EGL binding](https://github.com/erlangsters/egl-1.5)\nwhich will provide you with an OpenGL context and OpenGL surfaces to work with.\nAdditionally, you might want to use the [GLFW binding](https://github.com/erlangsters/glfw)\nto provide you with a window.\n\n\u003e Bindings for other version of OpenGL and OpenGL ES are available. Visit the\n\u003e organization page of the Erlangsters community on Github to browse the list\n\u003e of [available bindings](https://github.com/orgs/erlangsters/repositories?type=all\u0026q=opengl-).\n\nGenerated by the Erlangsters [community](https://about.erlangsters.org/) and\nreleased under the MIT [license](https://opensource.org/license/mit).\n\n## Quick preview\n\nAll the bits put together (EGL, OpenGL and some optional GLFW because it's\nmore fun with a window), here is how it looks like.\n\n```erlang\nDisplay = egl:get_display(default_display).\n{ok, _} = egl:initialize(Display).\n\nConfigAttribs = [\n  {surface_type, [window_bit]},\n  {renderable_type, [opengl_bit]}\n].\n{ok, Configs} = egl:choose_config(Display, ConfigAttribs).\n\nContextAttribs = [\n  {context_major_version, 4},\n  {context_minor_version, 6}\n],\negl:bind_api(opengl_api).\n{ok, Context} = egl:create_context(Display, Config, no_context, ContextAttribs).\n\n{ok, Window} = glfw:create_window(640, 480, \"Hello World!\").\nWindowHandle = glfw:window_egl_handle(Window).\n{ok, Surface} = egl:create_window_surface(Display, Config, WindowHandle, []).\n\nok = egl:make_current(Display, Surface, Surface, Context).\n\n% Here goes your OpenGL initialization code...\nVertices = [\n   0.0,  0.5, 0.0, 1.0, 0.0, 0.0,\n  -0.5, -0.5, 0.0, 0.0, 1.0, 0.0,\n   0.5, -0.5, 0.0, 0.0, 0.0, 1.0\n].\n\n{ok, [Buffer]} = gl:gen_buffers(1),\ngl:bind_buffer(array_buffer, Buffer),\ngl:buffer_data(\n  array_buffer,\n  length(Vertices) * 4,\n  \u003c\u003c\u003c\u003cVertex:32/float-little\u003e\u003e || Vertex \u003c- Vertices\u003e\u003e,\n  static_draw\n),\n% ...\n\nloop_window(Display, Surface, Window).\n```\n\nHere is how the loop function looks like.\n\n```erlang\nloop_window(Display, Surface, Window) -\u003e\n  case glfw:window_should_close(Window) of\n    true -\u003e\n      ok;\n    false -\u003e\n      % Here goes your OpenGL rendering code...\n      gl:clear([color_buffer_bit]),\n      % ...\n\n      egl:swap_buffers(Display, Surface),\n      glfw:poll_events(Window),\n      handle_events(Window),\n\n      loop_window(Display, Surface, Window)\n  end.\n```\n\nHere is how the event handling function looks like.\n\n```erlang\nhandle_events(Window) -\u003e\n  receive\n    #glfw_window_size{size={Width, Height}} -\u003e\n      gl:viewport(0, 0, Width, Height),\n      handle_events(Window)\n  after 0 -\u003e\n    ok\n  end.\n```\n\nFore more examples, consult the OpenGL samples [repository](https://github.com/erlangsters/opengl-samples)\nwhich contains several mini-programs written in C, Erlang and Elixir.\n\n## Working with the binding\n\nTo work with the binding, you will need to first hear about the \"thread-safety\"\nimplications (coming from the underlying C language) and how the API is\nadjusted to match look and feel of the Erlang and Elixir languages.\n\n**Thread-safety**\n\nOpenGL is a C library that is not thread-safe -- each OpenGL function executes\nin a OpenGL contexts bound to a single OS thread at a time. However, the BEAM\nlayers on top of OS threads (to provide the BEAM process primitive) and does\nnot expose them.\n\nHow does it work then ?\n\nThe thread-safety problem is solved by the EGL binding (hence its strong\ndependency on it) and the solution is well-explained in its\n[documentation](https://github.com/erlangsters/egl-1.5) (which you should consult).\n\nHowever, here is a short version of the story: it works just like if a\nBEAM process is equal to an OS thread.\n\nIf you think like this, all OpenGL code will work exactly like its counter-part\nin C.\n\n\u003e Under the hood, the EGL binding executes the OpenGL calls in separate OS\n\u003e threads in a way that replicates the layout of the BEAM processes of your\n\u003e application.\n\n**API mapping**\n\nTo make a low-level C API available in a higher-level Erlang/Elixir API, some\ntransformations are unavoidable. To remain highly consistent, it strictly\nfollows a set of mapping rules that are formally explained in the\n[documentation](https://github.com/erlangsters/opengl-x.y-generator) of the\nOpenGL binding generator.\n\nMost of the time, you will be able to intuitively understand how a piece of\nOpenGL code translates into its Erlang/Elixir counter-part. If not, the [API\nreference](http://erlangsters.github.io/opengl-4.6/) from the generated\nin-source documentation will clarify the rest.\n\n## Using the binding in your project\n\nWith the **Rebar3** build system, add the following to the `rebar.config` file\nof your project.\n\n```\n{deps, [\n  {egl, {git, \"https://github.com/erlangsters/egl-1.5.git\", {tag, \"master\"}}},\n  {gl, {git, \"https://github.com/erlangsters/opengl-4.6.git\", {tag, \"master\"}}}\n]}.\n```\n\nIf you happen to use the **Erlang.mk** build system, then add the following to\nyour Makefile.\n\n```\nBUILD_DEPS = egl gl\ndep_egl = git https://github.com/erlangsters/egl-1.5 master\ndep_gl = git https://github.com/erlangsters/opengl-4.6 master\n```\n\nIn practice, you want to replace the branch \"master\" with a specific \"tag\" to\navoid breaking your project if incompatible changes are made.\n\n## Generating the binding yourself\n\nLike stated, this OpenGL binding is generated and the result is hosted in this\nrepo for convenience of use. However, you may want to be able to re-produce\nthe said result.\n\nNo problem, clone the\n[OpenGL binding generator](https://github.com/erlangsters/opengl-x.y-generator)\nrepository, compile the generator and generate the binding.\n\n```\nrebar3 escriptize\n./bin/opengl_gen gl 4.6\n```\n\nIt produces the `gl.erl`, `gl.hrl` and `gl.c` that can be directly included in\nyour project. (Note that you'll need to configure your build system to produce '\na NIF library out of `gl.c`, of course.)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferlangsters%2Fopengl-4.6","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferlangsters%2Fopengl-4.6","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferlangsters%2Fopengl-4.6/lists"}