Build rawdraw on Windows
masterUsing Clang
clang simple.c -o simple -Irawdraw -lopengl32 -lgdi32 -luser32Using TCC (Tiny C Compiler)
C:\tcc\tcc simple.c -Irawdraw -lopengl32 -lgdi32 -luser32 C:\windows\system32\msvcrt.dllrepository·master·Indexed 19 days ago
https://github.com/cntools/rawdrawAn OS-agnostic, lightweight graphics library for drawing lines, boxes, text, and bitmaps. It supports a range of environments from high-level desktop applications using OpenGL, Vulkan, or WebAssembly to bare-metal embedded systems using software rasterization. The library can be integrated as a single-file header (STB-style) or a Git submodule.
clang simple.c -o simple -Irawdraw -lopengl32 -lgdi32 -luser32C:\tcc\tcc simple.c -Irawdraw -lopengl32 -lgdi32 -luser32 C:\windows\system32\msvcrt.dllYou can integrate rawdraw using two methods:
Download rawdraw_sf.h and include it directly in your project. To use this method, you must define CNFG_IMPLEMENTATION in exactly one C file before including the header.
#define CNFG_IMPLEMENTATION
#include "rawdraw_sf.h"Add the repository as a submodule to your project:
git submodule add https://github.com/cntools/rawdrawNote: If you encounter a git error, ensure you have run git init in your project root first.
//Method 1: Single-file header
#define CNFG_IMPLEMENTATION
#include "rawdraw_sf.h"Install the necessary X11 and Mesa development libraries.
Debian/Ubuntu:
sudo apt-get update
sudo apt-get install xorg-dev libx11-dev libxinerama-dev libxext-dev mesa-common-dev libglu1-mesa-devArch Linux:
sudo pacman -Sy xorg-server-devel libx11 libxinerama libxext mesa gluUse gcc to compile your source file (e.g., simple.c) linking against math, X11, and GL libraries:
gcc -o simple simple.c -lm -lX11 -lGLTo build or run rawdrawwasm, you must install the following system dependencies via apt-get:
binaryenclangllvmlldterserDepending on your environment, you may need to manually add the LLVM binaries to your PATH to ensure the build tools are discoverable.
sudo apt-get install binaryen clang llvm lld terser
# Example: adding LLVM to PATH if necessary
export PATH=$PATH:/usr/lib/llvm-10/binRawdraw uses #define flags to configure its backend and capabilities.
CNFGOGL: Use OpenGL/OpenGL ES if available.CNFGVK: Use Vulkan if available.CNFGRASTERIZER: Use software rasterization (useful for embedded platforms or when no GPU is available).CNFG3D: Includes CNFG3D rasterized graphics functions (requires CNFGRASTERIZER).__android__: Build for Android (forces CNFGOGL).WINDOWS, WIN32, WIN64: Build for Windows.HAS_XSHAPE: Include X11 on-screen display functionality.HAS_XINERAMA: Use X11 Xinerama for cleaner full-screen handling.CNFG_IMPLEMENTATION: Required in exactly one file to include the implementation code.When integrating rawdrawwasm into a web application, you can load the WebAssembly module either synchronously (for small blobs to prevent flashing) or asynchronously using WebAssembly.instantiate. Once loaded, you typically access the exports and call the main() function to start the application.
function wasmloaded(wa)
{
instance = wa;
wasmExports = instance.exports;
instance.exports.main();
}
// Attempt in-thread loading for small blobs to avoid flashing
if( blob.length < 4096 )
{
let mod = new WebAssembly.Module(array);
var wa = new WebAssembly.Instance( mod, imports );
wasmloaded( wa );
}
else
{
WebAssembly.instantiate(array, imports).then( function(wa) { wasmloaded(wa.instance); } );
}A standard rawdraw application follows this lifecycle:
CNFG_IMPLEMENTATION.HandleKey, HandleButton, HandleMotion, and HandleDestroy.main, call CNFGSetup to initialize the window.CNFGHandleInput().CNFGSwapBuffers().Common drawing functions include:
CNFGColor(uint32_t color): Sets the current drawing color.CNFGTackPixel(int x, int y): Draws a single pixel.CNFGTackSegment(int x1, int y1, int x2, int y2): Draws a line.CNFGTackRectangle(int x, int y, int w, int h): Draws a box.CNFGBlitImage(uint32_t* data, int x, int y, int w, int h): Draws a bitmap.#define CNFG_IMPLEMENTATION
#include "rawdraw_sf.h"
void HandleKey( int keycode, int bDown ) { }
void HandleButton( int x, int y, int button, int bDown ) { }
void HandleMotion( int x, int y, int mask ) { }
int HandleDestroy() { return 0; }
int main()
{
CNFGSetup( "Example App", 1024, 768 );
while(CNFGHandleInput())
{
CNFGBGColor = 0x000080ff; //Dark Blue Background
short w, h;
CNFGClearFrame();
CNFGGetDimensions( &w, &h );
CNFGColor( 0xffffffff );
CNFGPenX = 1; CNFGPenY = 1;
CNFGDrawText( "Hello, World", 2 );
CNFGTackPixel( 30, 30 );
CNFGTackSegment( 50, 50, 100, 50 );
CNFGColor( 0x800000FF );
CNFGTackRectangle( 100, 50, 150, 100 );
CNFGColor( 0x800000FF );
RDPoint points[3] = { { 30, 36}, {20, 50}, { 40, 50 } };
CNFGTackPoly( points, 3 );
CNFGSwapBuffers();
}
}