{"id":15051618,"url":"https://github.com/arnkoen/tfx","last_synced_at":"2025-06-19T03:04:17.932Z","repository":{"id":257603330,"uuid":"858770755","full_name":"arnkov/tfx","owner":"arnkov","description":"small opengl3.3/gles3.0 renderer in a single header","archived":false,"fork":false,"pushed_at":"2024-12-21T15:37:54.000Z","size":1105,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T16:55:05.920Z","etag":null,"topics":["gles","graphics","opengl","rendering","single-header"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arnkov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-09-17T14:02:20.000Z","updated_at":"2024-12-21T15:37:57.000Z","dependencies_parsed_at":"2024-11-19T19:46:02.675Z","dependency_job_id":"2e3e6ef1-a330-478a-b492-f3c670a92bf7","html_url":"https://github.com/arnkov/tfx","commit_stats":{"total_commits":26,"total_committers":1,"mean_commits":26.0,"dds":0.0,"last_synced_commit":"be4733f3331cad20b794e7289e8afb5045243826"},"previous_names":["arnkov/tfx"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnkov%2Ftfx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnkov%2Ftfx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnkov%2Ftfx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnkov%2Ftfx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arnkov","download_url":"https://codeload.github.com/arnkov/tfx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248643043,"owners_count":21138353,"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","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":["gles","graphics","opengl","rendering","single-header"],"created_at":"2024-09-24T21:36:40.713Z","updated_at":"2025-06-19T03:04:11.713Z","avatar_url":"https://github.com/arnkov.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tfx\nTfx is an easy to use toy single header WIP graphics abstraction for OpenGL 3.3 and OpenGLes 3.0.\nIt embeds glad for OpenGL function loading and tries, to enable painless graphics prototyping.\nIt is meant mainly as a personal learning project and propably won't ever be ready for production. \n\nIt aims, to make OpenGL a bit less of a struggle: When to unbind the index buffer? What is the active depth compare function? And why is everything an int?!\nThe style leans a bit towards modern graphics apis, but tfx doesn't hide opengl away. You could just use it, to load it and then write plain gl code.\n\nIf you are looking for something more mature, have a look at sokol_gfx.h or bgfx.\nRight now it compiles as C and c++ on windows and linux. Other platforms should work, but are not tested.\n\nTo use it, just drop the header file into your project, include it and define TFX_IMPL and the backend (TFX_GLCORE/TFX_GLES2) in *one* C/C++ file. Optional defines are TFX_NO_STBI and TFX_EXTERNAL_STBI in case you already included stb_image.h somewhere else in your project and/or want to define the implementation at some other point. You can find the header linked below.\n\nThe different licenses are included in the header file, which are WTFPL OR CC0-1.0 AND Apache-2.0 for the glad-headers and the uLicense for the actual code of tfx.\n\nCredits:\nDavid Herberth - [glad](https://github.com/Dav1dde/glad) \\\nSean Barrett - [stb_image](https://github.com/nothings/stb) \\\nr-lyeh - [uLicense](https://github.com/r-lyeh/uLicense) \\\nkgabis - [join.py](https://github.com/kgabis/ape) \n\n# limitations \u0026 caveats\n- tfxRenderTarget only supports two attachments (color \u0026 depth)\n- for now, the only supported vertex format is TFX_VERTEXFORMAT_F32\n- pixel formats are limited to TFX_PIXELFORMAT_U8 / F32\n- tfxPipeline does not check the current draw state, but just tosses its commands at the gpu, also maybe it should be called tfxDrawState or tfxStyle, since it does not have much in common with modern graphics api's pipeline objects\n- tfxShader is currently limited to vertex and fragment shaders\n- ...and most likely some more I don't know about yet.\n\n## triangle example using glfw for windowing\n```c\n#define TFX_IMPL\n#define TFX_NO_STBI // stb_image.h is not needed here\n#define TFX_GLCORE // Can also be TFX_GLES2\n#include \"tfx.h\"\n#define GLFW_INCLUDE_NONE\n#include \u003cGLFW/glfw3.h\u003e\n\n\nint main() {\n    if (!glfwInit()) {\n        fprintf(stderr, \"Failed to initialize GLFW\\n\");\n        exit(EXIT_FAILURE);\n    }\n\n    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);\n    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);\n    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);\n    glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);\n\n    GLFWwindow* window = glfwCreateWindow(640, 480, \"Triangle\", NULL, NULL);\n    if (!window) {\n        fprintf(stderr, \"Failed to create GLFW window\\n\");\n        glfwTerminate();\n        exit(EXIT_FAILURE);\n    }\n\n    glfwMakeContextCurrent(window);\n    glfwSwapInterval(1);\n\n    // Initialize tfx\n    if (!tfxInit(glfwGetProcAddress)) {\n        fprintf(stderr, \"Failed to initialize tfx\\n\");\n        glfwTerminate();\n        exit(EXIT_FAILURE);\n    }\n\n    // Define the vertices of the triangle (X, Y, Z)\n    static const float triangleVertices[] = {\n        0.0f,  0.5f, 0.0f,\n       -0.5f, -0.5f, 0.0f,\n        0.5f, -0.5f, 0.0f\n    };\n\n    // Create a buffer for triangle vertices\n    tfxBuffer vertexBuffer = (tfxBuffer){\n        .stride = 3 * sizeof(float),\n        .usage = TFX_USAGE_IMMUTABLE,\n        .data = TFX_MEMORY(triangleVertices),\n        .type = TFX_BUFFERTYPE_VERTEXBUFFER\n    };\n\n    tfxShader shader = tfxLoadShader(\"triangle.vert\", \"triangle.frag\");\n\n    // Define the mesh with the vertex buffer and layout\n    // here the actual opengl ressources are initialized\n    tfxMeshDesc meshDesc = {\n        .vbuf[0] = \u0026vertexBuffer,\n        .layout = {\n            [0] = {\n                .size = 3,\n                .offset = 0,\n                .bufferIndex = 0\n            }\n        }\n    };\n    tfxMesh triangleMesh = tfxMakeMesh(\u0026meshDesc);\n\n    // Render loop\n    while (!glfwWindowShouldClose(window)) {\n        // Clear the screen\n        tfxBeginPass(\u0026(tfxPass) {\n            .clearFlags = TFX_CLEAR_COLOR | TFX_CLEAR_DEPTH,\n            .clearValue = (tfxColor){0.1f, 0.1f, 0.1f, 1.0f},\n            .framebuffer = {0}\n        });\n\n        // Set the pipeline and shader\n        tfxSetPipeline(\u0026(tfxPipeline){}); // Actually not nescessary here.\n        tfxSetShader(\u0026shader);\n\n        // Set the mesh (triangle) and draw it\n        tfxSetMesh(\u0026triangleMesh);\n        tfxDraw(TFX_PRIMITIVTYPE_TRIANGLES, 3);\n\n        // End the pass\n        tfxEndPass(); // Actually not nescessary here, binds the default/0th framebuffer.\n\n        glfwSwapBuffers(window);\n        glfwPollEvents();\n    }\n\n    // Cleanup\n    tfxReleaseBuffer(\u0026vertexBuffer);\n    tfxReleaseShader(\u0026shader);\n    tfxReleaseMesh(\u0026triangleMesh);\n    glfwDestroyWindow(window);\n    glfwTerminate();\n    return 0;\n}\n\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnkoen%2Ftfx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farnkoen%2Ftfx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnkoen%2Ftfx/lists"}