{"id":19338186,"url":"https://github.com/jserv/tinygl","last_synced_at":"2025-05-05T22:09:36.536Z","repository":{"id":38416988,"uuid":"498540314","full_name":"jserv/tinygl","owner":"jserv","description":"TinyGL: a Small, Free and Fast Subset of OpenGL","archived":false,"fork":false,"pushed_at":"2024-07-09T16:50:12.000Z","size":58510,"stargazers_count":75,"open_issues_count":0,"forks_count":7,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-05-05T22:09:19.632Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jserv.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":"2022-06-01T00:33:46.000Z","updated_at":"2025-05-05T19:08:12.000Z","dependencies_parsed_at":"2024-11-10T03:16:47.660Z","dependency_job_id":"acad7f88-ac9d-4c57-8b6d-8817f5b95017","html_url":"https://github.com/jserv/tinygl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jserv%2Ftinygl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jserv%2Ftinygl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jserv%2Ftinygl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jserv%2Ftinygl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jserv","download_url":"https://codeload.github.com/jserv/tinygl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252584329,"owners_count":21771945,"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":[],"created_at":"2024-11-10T03:16:34.966Z","updated_at":"2025-05-05T22:09:36.518Z","avatar_url":"https://github.com/jserv.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TinyGL fork\n\n![tgl logo](assets/tgl_minimal.png)\nA comprehensive overhaul of [TinyGL](https://bellard.org/TinyGL/) as a better software rasterizer.\nIt is a small, software-only and partial GL 1.1 implementation wth limited multithreading support.\n\nThe original project was by [Fabrice Bellard](https://bellard.org/). We have forked it. \n\n## Architecture\n\nTinyGL is made up 3 major modules:\n- Mathematical routines (zmath).\n- OpenGL-like emulation (zgl).\n- Z buffer and rasterisation (zbuffer).\n\n## Safety features\n\nTinyGL contains the following safety features:\n1. compiletime options for `glGetError()` functionality which obviously slows down speed but increases debugging capability.\n2. OpenGL 2.0 buffers, for easy memory management (Anything you put in a buffer using glBufferData will be free'd upon `glClose()`)\n3. Fully leak checked using Valgrind- The only leaks you'll see are from your system's SDL. the Raw demos have zero leaks.\n\n## Incredibly portable\n\nTinyGL is written in pure C99, and requires very few functions from the C standard library, it doesn't even require malloc and free\n(The calls are aliased to `gl_malloc()` and `gl_free()`, which you can replace with your own memory management model if you desire)\n\n## Portability\n\nYou can test compiling TinyGL by executing `make raw-examples`, which do not require ANYTHING Except the C standard library and stdio.\n\nThese are the C standard library includes used in the raw examples.\n```c\n#include \u003cmath.h\u003e\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \u003cstring.h\u003e\n#include \u003cstdarg.h\u003e\n```\n\nIf your system supports it, the library can also take advantage of `alignas` to get improved SIMD support,\nwhich can be disabled in zfeatures.\nThis adds a dependency to `\u003cstdalign.h\u003e` but greatly increases vertex processing speed.\n(This is disabled by default for maximum portability)\n\nIf you are unsure if your target platform can support TinyGL, compile it with the buildtime and runtime tests enabled (They are, by default)\n\nif you get a `TGL_BUILDT` error, then you've failed the buildtime test.\n\nif you try to initialize the library and you get a crash with a print to standard out `TINYGL_FAILED_RUNTIME_COMPAT_TEST` then you've failed the runtime test.\n\nThe SDL examples have been tested building on Debian 10 and Windows 10, while tinygl itself has been confirmed to compile on many more platforms.\n\n## Status\n\nThere are graphical artifacts visible in these gifs which have been corrected in this version of the library.\n\nWithout Polygon Stipple:\n![GIF Video of demo](assets/capture.gif)\n\nWith Polygon Stipple:\n![GIF Video of demo](assets/capture2.gif)\n\nHello World test:\n![model loading demo](assets/helloworld.gif)\n\nTexturing Test: \n![Screenshot of Texture test](assets/texture_test.png)\n\nModel loading tests:\n![model loading demo](assets/model2_lit.gif)\n![model loading demo](assets/model_lit.gif)\n\nWithout lighting: \n![model loading demo](assets/model2.gif)\n![model loading demo](assets/model.gif)\n\nThis is a demo of the `NO_DRAW_COLOR` feature. Notice that the object appears to have a hole in it.\n![model loading demo](assets/model_hole.gif)\n\nBlending:\n![model loading demo](assets/blend.gif)\n\nSpecular:\n![GIF Video of demo](assets/specular.gif)\n\nNotable changes:\n* Disabled 8, 15, and 24 bit rendering modes. 16 and 32 are the only supported rendering modes (Coincidentally, they are also the fastest)\n* Allowed the fixed texture size to be changed at compile time. It must be a power of 2, but that is the only limitation.\n* Removed the entire GLX/NanoGLX part of the library. Not portable and mostly useless.\n* Implemented new functions and some more of GL 1.1's prototypes including polygon stipple.\n* Triangles can now be lit and textured at the same time!\n* Removed unused functions which bloat binary size and lengthen compile times.\n* Added support for glDepthMask and glDisable(`GL_DEPTH_TEST`) as per-GL-spec\n* ADDED BLENDING SUPPORT!\n* Added glDrawPixels\n* Added glPixelZoom\n* Added glRasterPos2f,3f,4f,2fv,3fv,4fv\n* Added glGetString() for `GL_VENDOR`, `GL_RENDERER`, and `GL_VERSION`\n* Added comprehensive, usable glGetError() functionality for debugging.\n* Fixed clientside arrays\n* Tuned the triangle rasterizer to near-perfection.\n* Tuned the transformations to absolute perfection\n* Added glDrawArrays\n* Added Buffers (For memory management purposes)\n* Added glTexImage1D (... it just resizes it to 2D, but it works!)\n* Added glPixelSize (TODO is to implement distance scaling)\n* Fixed specular rendering\n* Added way more compile time options\n* Fixed all the memory leaks.\n* added Openmp multithreading and glPostProcess()\n* Line rendering now obeys glDepthMask and glDepthTest.\n* Implemented glRectf\n* Implemented compiletime toggles for `GL_SELECT` and `GL_FEEDBACK` which significantly boosts performance. Also, implemented `GL_FEEDBACK`.\n\nNote that this softrast **is not GL 1.1 compliant** and does not constitute a complete GL implementation.\n\nNotable limitations:\n* The only supported texture size and format is decided at compile time. you can set it in zfeatures.h\n* A lot of prototypes are missing.\n* glPolygonOffset doesn't change anything about how rendering occurs. It does nothing, at the moment. \nThe \"implementation specific multiplier\" is 0.\n* There is no stencil buffer.\n* Blending can't use alpha values. the rasterizer has no concept of alpha.\n* There is no mipmapping, antialiasing, or any form of texture filtering.\n* No edge clamping. S and T are wrapped.\n* Display lists can be infinitely nested and doing so will crash TinyGL.\n* Lit triangles will use the current material properties, even if they are textured.\n  - If the diffuse color is black, then your\ntextured triangles will appear black.\n* Textured triangles are affected by their vertex colors- the per-vertex color is used as a \"mask\" for the texture on triangles.\n  - It is recommended you call glColor3f(1,1,1); before rendering a textured object to get the expected result you only need to make this call once, and it can be before glBegin.\n* the X dimension of the rendering window with must be a multiple of 4.\n* Line rendering is not blended\n* The ARB extension for point sprite size attenuation is not enabled.\n* Point smoothing is not implemented, points are always squares of a solid color.\n* glCopyTexImage2D only works with the size of texture you decided at compile time.\n\n## Integrations\n\nTinyGL is not header only, it is a combination of C files, internal headers, and external headers.\nThe internal headers are only used while compiling the library,\nthe external headers (gl.h, zfeatures.h, zbuffer.h) are required to use the library.\nYou CAN compile the library along with your final program into a single compilation unit without separating out the library.\n\nThis is how you use TinyGL in a program:\n```c\n#include \u003cGL/gl.h\u003e\n#include \"zbuffer.h\"\n\n/* Next, open a framebuffer.\n * The \"0\" parameter is where you pass in a framebuffer pointer if you've already made one.\n */\nZBuffer *frameBuffer = ZB_open(winSizeX, winSizeY, mode, 0);\n\n/* Tell TinyGL to initialize on that framebuffer */\nglInit(frameBuffer);\n\n/* Begin making TinyGL calls! */\n\n/* Update framebuffer when you want to copy to your target screen\n * Pitch is the width of the target in bytes, or bytes per pixel times width;\n */\nZB_copyFrameBuffer(frameBuffer, screen-\u003epixels, screen-\u003epitch);\n\n/* At the end of your application, when you want to clean up. */\nZB_close(frameBuffer);\nglClose();\n```\n\nNote that while you... *can* invoke `ZB_Resize` to resize the framebuffer, you really shouldn't. It isn't tested.\n\n### Minimum requirements\n\nSDL2 is required to run most of the `sdl_examples`, but SDL is by no means required to compile or use this library.\nSDL is used as a reasonable means of displaying the output of TinyGL for testing.\n\nRequirements\n* A C99 compliant compiler\n* 32 bit signed and unsigned integer types\n* 32 bit binary float type (`STDC_IEC_559`)\n* Some floating point type at least as large as a 32 bit float\n* sin and cos functions in math.h\n* memcpy in string.h\n* assert in assert.h (for debugging only, it can be stubbed)\n* a minimal C stdlib\n* A memory allocator of some sort with some equivalents or replacements for malloc, calloc, and free.\n\nThere is no FILE* usage, or I/O outside of 'msghandling.c' so if you want to remove all stdio dependency, just stub out the calls there.\n\n### Multithreading support\n\nOpenMP is used on supported platforms to multithread certain operations.\nThese are the operations that are accelerated by multithreading:\n* glDrawPixels\n  - Every scanline is drawn by a separate thread.\n* glPostProcess\n  - Every call of the function pointer is run by a separate thread.\n* glCopyTexImage2D\n  - Every scan line is copied by a separate thread.\n* ZBCopyBuffer\n  - Every scan line is copied by a separate thread.\n\nCompile the library with `-fopenmp` to see them in action (default). They are used in the texture demo, make sure to add the argument `-pp`\n\nYou do not need a multithreaded processor to use TinyGL!\n\n## New functions\n\nThese are functions not in the GL 1.1 spec that we haved added to make this library more useful.\nThese functions cannot be added as opcodes to display lists unless specifically listed.\n\n### glDeleteList\nAn easier to use version of glDeleteLists. glDeleteLists is also implemented.\n\n### glSetEnableSpecular(int shouldenablespecular);\nThis function can be added to display lists.\n\nAllows you to configure specular rendering. Turn it off\nif you want to use GL_LIGHTING but don't plan on using\nspecular lighting. it will save cycles.\n\n### glGetTexturePixmap(int text, int level, int* xsize, int* ysize)\nAllows the user to retrieve the raw pixel data of a texture, for their own modification.\n\n### glDrawText(const unsigned char* text, int x, int y, unsigned int pixel)\nThis function can be added to display lists as glPlotPixel calls, the text is not saved in a display list.\n\nIs capable of rendering the entire 8 bit latin extended character set (7 bit ascii plus characters 0xa0 and onward...)\nYou can check how to embed non-standard characters in your strings in the gears demo.\nDraws a pre-made 8x8 font to the screen. You can change its displayed size with...\n\n### glTextSize(GLTEXTSIZE mode)\nThis function can be added to display lists.\n\nSet size of text drawn to the buffer in aforementioned function.\n\n### glPlotPixel(int x, int y, unsigned int pixel)\nThis function can be added to display lists.\n\nPlot pixel directly to the buffer.\n\n### glGenBuffers, glDeleteBuffers, glBindBuffer (valid target: `ARRAY_BUFFER`), glBindBufferAsArray\nServerside buffers! Makes it a bit easier to do clientside array stuff at the moment. \nmay be the site of future hardware acceleration.\n\nPlease look at the model.c demo to see how to use these functions. They function very similarly to their GL 2.0+ counterparts.\n\n### glPostProcess(GLuint (*postprocess)(GLint x, GLint y, GLuint pixel, GLushort z))\nFast, Multithreaded Postprocessing for TinyGL. \n\nYou simply send in a function pointer (The function's name) and glPostProcess does the heavy lifting\nThe return value is the pixel (ARGB or 5R6G5B depending on mode).\n\nx and y are the screen coordinataes.\n\npixel is the current color value of the pixel, ARGB or 5R6G5B depending on mode.\n\nz is TinyGL's internal Z buffer representation. Larger values are considered to be \"in front\" of smaller ones.\n\nThis function is multithreaded on supported platforms for maximum execution speed. It of course still works without multithreading, but\n\nit will not be as fast.\n\nNote that you may have to take special care to prevent race conditions when using multithreading with this function.\n\n### New glGet calls\nYou can query glGetIntegerV with these new definitions\n```c\n\tGL_POLYGON_MAX_VERTEX = 0xf001,\n\tGL_MAX_BUFFERS = 0xf002,\n\tGL_TEXTURE_HASH_TABLE_SIZE = 0xf003,\n\tGL_MAX_TEXTURE_LEVELS = 0xf004,\n\tGL_MAX_SPECULAR_BUFFERS = 0xf005,\n\tGL_MAX_DISPLAY_LISTS = 0xf006,\n\tGL_ERROR_CHECK_LEVEL = 0xf007,\n\tGL_IS_SPECULAR_ENABLED = 0xf008,\n```\n\nto query the configuration of TinyGL.\n\n## Configurable build-time features\n\nSee `include/zfeatures.h`\n\nThis changes too often to maintain documentation here.\n\nThe compiletime test is now disabled by default since it may not be \"liked\" by some obscure compilers...\nyou can enable it in `\u003cGL/gl.h\u003e`\n\n```c\n/* at the top of include/GL/gl.ha */\n#define COMPILETIME_TINYGL_COMPAT_TEST 1\n```\n\n## Fully compatible with RGBA\n\nThe library is now able to be configured properly for RGBA rendering. Note that the output *is actually ARGB* \nbut adjusting it is easy, see the SDL examples.\n\nThe library is sometimes by default configured for RGBA or 5R6G5B, check include/zfeatures.h and change the values in this table:\n```c\n#define TGL_FEATURE_8_BITS         0\n#define TGL_FEATURE_24_BITS        0\n#define TGL_FEATURE_16_BITS        1\n#define TGL_FEATURE_32_BITS        0\n```\n\nmake sure that only ONE of these values is 1.\n\n## Related Projects\n* [PortableGL](https://github.com/rswinkle/PortableGL) is an implementation of OpenGL 3.x core in clean C99 as a single header library.\n* [TinyGLES](https://github.com/lunixbochs/tinygles) is a software OpenGL ES driver.\n* [Vincent ES](https://github.com/hmwill/GLESv20) is a software renderer based on OpenGL ES 2.0 API.\n* [softgl](https://github.com/bit-hack/softgl) is a software renderer based on OpenGL 1.x.\n* [TinyGL.js](https://github.com/humu2009/tinygl.js) is based upon TinyGL's implementation written in C and compiled to JavaScript via Emscripten. It only uses software rasterization and does not require WebGL to run.\n* [scummvm/graphics/tinygl](https://github.com/scummvm/scummvm/tree/master/graphics/tinygl) contains a series of aggressive modifications against the original TinyGL.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjserv%2Ftinygl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjserv%2Ftinygl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjserv%2Ftinygl/lists"}