| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A portable, software-only OpenGL 1.1 rasterizer written in pure C99.
Originally developed by Fabrice Bellard, this version has been extensively enhanced for performance and portability. It is a small, partial OpenGL 1.1 implementation with optional multithreading support.
TinyGL consists of three major modules:
TinyGL includes the following safety features:
TinyGL is written in pure C99 with minimal standard library dependencies. It does not require malloc or free directly; allocation calls are aliased to gl_malloc() and gl_free(), so you can drop in a custom allocator.
Sanity-check portability from the repo root with make raw_examples, which builds the raw demos using only the C standard library.
The raw examples use these standard library headers:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>If your system supports it, the library can use alignas for improved SIMD support. This adds a dependency on <stdalign.h> and can increase vertex processing speed (disabled by default for maximum portability).
If you are unsure whether your target platform can support TinyGL, compile with the build-time and runtime tests enabled (they are enabled by default):
The SDL examples have been tested on Debian 10 and Windows 10, while the library itself has been confirmed to compile on many more platforms.
Compared to the original TinyGL:
Rendering:
Performance Optimizations:
API Additions:
Code Quality:
Note that this software rasterizer is not GL 1.1 compliant and does not constitute a complete GL implementation.
TinyGL is not header-only. It ships C sources plus internal headers (build-only) and public headers (gl.h, zfeatures.h, zbuffer.h). You can build it as a static library or compile the sources directly into your program.
Basic usage:
#include <GL/gl.h>
#include "zbuffer.h"
/* Open a framebuffer (pass NULL to allocate internally) */
ZBuffer *frameBuffer = ZB_open(winSizeX, winSizeY, mode, NULL);
/* Initialize TinyGL with the framebuffer */
glInit(frameBuffer);
/* Make TinyGL calls here */
/* Copy framebuffer to display (pitch = bytes per row) */
ZB_copyFrameBuffer(frameBuffer, screen->pixels, screen->pitch);
/* Clean up */
ZB_close(frameBuffer);
glClose();SDL2 is required only for the sdl_examples, not for the library itself. There is no FILE* usage or I/O outside of msghandling.c; stub those calls to remove all stdio dependency.
OpenMP is used on supported platforms to parallelize certain operations:
Compile with -fopenmp to enable. This is optional (disabled in config.mk by default) and not required to use TinyGL.
Functions not in the GL 1.1 spec, added for convenience. These cannot be added to display lists unless noted.
Simpler alternative to glDeleteLists (which is also implemented).
Display-list compatible. Enable/disable specular rendering. Turn off if not using specular lighting to save cycles.
Retrieve raw pixel data of a texture for modification.
Display-list compatible (as glPlotPixel calls). Renders 8-bit Latin extended character set using a built-in 8x8 font.
Display-list compatible. Set the size of text drawn by glDrawText.
Display-list compatible. Plot a pixel directly to the buffer.
Server-side buffers for clientside array data. Valid target: GL_ARRAY_BUFFER. See model.c demo for usage.
Multithreaded post-processing. The callback receives screen coordinates (x, y), current pixel color (ARGB or 5R6G5B), and depth value (z). Returns the new pixel color. Note: take care to prevent race conditions when multithreading is enabled.
Query TinyGL configuration via glGetIntegerv:
GL_POLYGON_MAX_VERTEX = 0xf001,
GL_MAX_BUFFERS = 0xf002,
GL_TEXTURE_HASH_TABLE_SIZE = 0xf003,
GL_MAX_TEXTURE_LEVELS = 0xf004,
GL_MAX_SPECULAR_BUFFERS = 0xf005,
GL_MAX_DISPLAY_LISTS = 0xf006,
GL_ERROR_CHECK_LEVEL = 0xf007,
GL_IS_SPECULAR_ENABLED = 0xf008,See include/zfeatures.h for all compile-time options. Key settings:
Pixel format (enable exactly one):
#define TGL_FEATURE_16_BITS 0 /* 5R6G5B format */
#define TGL_FEATURE_32_BITS 1 /* ARGB format */Note: 32-bit output is ARGB; see SDL examples for format conversion if needed.
Other notable options:
What can I use TinyGL for?
TinyGL uses too much memory
How do I use 16-bit color? Set the feature flags in include/zfeatures.h:
#define TGL_NO_COPY_COLOR 0xff00ff
#define TGL_NO_DRAW_COLOR 0xff00ff
#define TGL_COLOR_MASK 0x00ffffff
#define TGL_FEATURE_16_BITS 0
#define TGL_FEATURE_32_BITS 1Flip TGL_FEATURE_16_BITS to 1 and TGL_FEATURE_32_BITS to 0 for 16-bit output. Adjust the NO_COPY/NO_DRAW constants to match your chosen format if you disable drawing or copying.
TinyGL is licensed under the MIT License. See LICENSE for details. Note: The upstream TinyGL changed its license from Zlib-like to MIT in 2022.
| Back | FazBrowse Home | New Git URL |