{"id":15879956,"url":"https://github.com/vallentin/gl-headless","last_synced_at":"2025-09-02T08:40:54.240Z","repository":{"id":171047383,"uuid":"647392668","full_name":"vallentin/gl-headless","owner":"vallentin","description":null,"archived":false,"fork":false,"pushed_at":"2023-06-01T02:51:51.000Z","size":23,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-15T08:13:03.253Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/vallentin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2023-05-30T17:23:19.000Z","updated_at":"2024-08-26T15:59:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"5a3244ef-dfe6-4558-8785-0da8108ec8f0","html_url":"https://github.com/vallentin/gl-headless","commit_stats":null,"previous_names":["vallentin/gl-headless"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vallentin/gl-headless","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vallentin%2Fgl-headless","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vallentin%2Fgl-headless/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vallentin%2Fgl-headless/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vallentin%2Fgl-headless/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vallentin","download_url":"https://codeload.github.com/vallentin/gl-headless/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vallentin%2Fgl-headless/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273257453,"owners_count":25073530,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-10-06T03:06:38.432Z","updated_at":"2025-09-02T08:40:53.367Z","avatar_url":"https://github.com/vallentin.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gl-headless\n\n[![Latest Version](https://img.shields.io/crates/v/gl-headless.svg)](https://crates.io/crates/gl-headless)\n[![Docs](https://docs.rs/gl-headless/badge.svg)](https://docs.rs/gl-headless)\n[![License](https://img.shields.io/github/license/vallentin/gl-headless.svg)](https://github.com/vallentin/gl-headless)\n\nEasiest way to create a headless OpenGL context.\n\nSimply add \u003ccode\u003e#[[gl_headless]]\u003c/code\u003e to any function (even `main`), then call that function as you otherwise would. Within the scope of the function, an OpenGL context will be available.\n\nSee all available options in the documentation for\n\u003ccode\u003e#[[gl_headless]]\u003c/code\u003e.\n\n## Simple Example\n\n```toml\n[dependencies]\ngl = \"0.14\"\ngl-headless = \"0.2\"\n```\n\n```rust\nuse gl_headless::gl_headless;\n\n#[gl_headless]\nunsafe fn main() {\n    let (mut major, mut minor) = (0, 0);\n    gl::GetIntegerv(gl::MAJOR_VERSION, \u0026mut major);\n    gl::GetIntegerv(gl::MINOR_VERSION, \u0026mut minor);\n    println!(\"OpenGL {major}.{minor}\");\n}\n```\n\n## Specify OpenGL Version\n\nBy default \u003ccode\u003e#[[gl_headless]]\u003c/code\u003e attempts to create an OpenGL 4.6 context. To use a specific version add, e.g. `version = \"3.3\"`:\n\n```rust\nuse gl_headless::gl_headless;\n\n#[gl_headless(version = \"3.3\")]\nunsafe fn main() {\n    let (mut major, mut minor) = (0, 0);\n    gl::GetIntegerv(gl::MAJOR_VERSION, \u0026mut major);\n    gl::GetIntegerv(gl::MINOR_VERSION, \u0026mut minor);\n    println!(\"OpenGL {major}.{minor}\");\n}\n```\n\n## Parameters \u0026 Return Type\n\nSpecify function parameters and return type as you otherwise would:\n\n```rust\nuse gl_headless::gl_headless;\n\nfn main() {\n    let version = get_version(\"OpenGL\");\n    println!(\"{version}\");\n}\n\n#[gl_headless]\nfn get_version(prefix: \u0026str) -\u003e String {\n    let (mut major, mut minor) = (0, 0);\n    unsafe {\n        gl::GetIntegerv(gl::MAJOR_VERSION, \u0026mut major);\n        gl::GetIntegerv(gl::MINOR_VERSION, \u0026mut minor);\n    }\n    format!(\"{prefix} {major}.{minor}\")\n}\n```\n\n## Multiple Functions\n\nMultiple functions can use \u003ccode\u003e#[[gl_headless]]\u003c/code\u003e:\n\n```rust\nuse gl_headless::gl_headless;\n\nfn main() {\n    unsafe {\n        example1();\n        example2();\n    }\n}\n\n#[gl_headless(version = \"3.3\")]\nunsafe fn example1() {\n    let (mut major, mut minor) = (0, 0);\n    gl::GetIntegerv(gl::MAJOR_VERSION, \u0026mut major);\n    gl::GetIntegerv(gl::MINOR_VERSION, \u0026mut minor);\n    println!(\"OpenGL {major}.{minor}\");\n}\n\n#[gl_headless]\nunsafe fn example2() {\n    let mut handle = 0;\n    gl::CreateBuffers(1, \u0026mut handle);\n\n    let data: [f32; 5] = [1.0, 2.0, 3.0, 4.0, 5.0];\n    gl::NamedBufferData(\n        handle,\n        std::mem::size_of_val(\u0026data) as _,\n        data.as_ptr() as *const _,\n        gl::STATIC_DRAW,\n    );\n\n    let mut byte_size = 0;\n    gl::GetNamedBufferParameteriv(handle, gl::BUFFER_SIZE, \u0026mut byte_size);\n    let float_count = (byte_size as usize) / std::mem::size_of::\u003cf32\u003e() as usize;\n\n    let mut floats = vec![0.0_f32; float_count];\n    gl::GetNamedBufferSubData(\n        handle,\n        0,\n        std::mem::size_of_val(floats.as_slice()) as _,\n        floats.as_mut_ptr() as *mut _,\n    );\n\n    println!(\"Write: {:?}\", data);\n    println!(\"Read:  {:?}\", floats);\n\n    assert_eq!(data, floats.as_slice());\n}\n```\n\n[gl_headless]: https://docs.rs/gl-headless/*/gl_headless/attr.gl_headless.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvallentin%2Fgl-headless","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvallentin%2Fgl-headless","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvallentin%2Fgl-headless/lists"}