Skip to content

MaGetzUb/smol_libs

Repository files navigation

smol_libs

My attempt of making single header C-libraries for *maximum portability.

* no apple platform support yet.

So far I've made

  • smol_frame.h for creating simple windows for graphics programming. In the sample code (smol_frame_test.c) I use TSoding's olive.c.
  • smol_utils.h containing function such as smol_timer() to measure delta time in a frame. smol_timer() on windows returns the computer uptime, and on linux returns the seconds(microseconds included) since unix epoch. I was considering to use clock_gettime() instead of gettimeofday(), but gettimeofday() seem to require no additioncal compiler arguments. Some recently added features are utf8<->utf32 and utf16<->utf32 conversions, as well as filesystem scanning and entire file reading.
  • smol_input.h a complimentary header for input management, has functions for checking is key hit(=pressed), down (=being pressed) and up (=released) and for mouse buttons too. Also it contains functions for mouse location on a window, as well as wheel delta/orientation. These functions will change when multiple frames and shared event queues are properly implemented.
  • smol_canvas.h My own attempt for software rendering 2D shapes, lines, circles, images, and text triangles(not working yet).
  • smol_math.h A rudimentary linear algebra library, for vectors, quaternions and matrices (only compatible with OpenGL atm).
  • smol_text_renderer.h A simple text renderer that batch renders a text.

Also there's several tests:

Building on Windows

by using Microsoft Visual Studio 2022 Command prompt smol_frame_test.c, smol_snake_test.c, or any other test, should be able to be compiled with command:

cl.exe /Zi /EHsc /nologo /Fo:.\build\ .\smol_xxxx_test.c /link /OUT:.\build\smol_xxxx_test.exe

and smol_pix_font_creator.c can be built with:

cl.exe /Zi /EHsc /nologo /Fo:.\build\ .\smol_pix_font_creator.c /link comdlg32.lib /OUT:.\build\smol_pix_font_creator.exe

by using MinGW on windows gcc smol_xxxx_test.c -o smol_xxxx_test

Building on Linux

I've used following commands to compile all the tests:

Using Xlib:

gcc -fdiagnostics-color=always -std=c99 -g -pedantic -Wall smol_xxxx_test.c -lm -o build/smol_xxxx_test

Using xcb:

 gcc -fdiagnostics-color=always -std=c99 -g -pedantic -Wall smol_xxxx_test.c -lxcb -lxcb-icccm lxcb-keysyms -lxcb-xkb -lxkbcommon -lxkbcommon-x11 -lm -o build/smol_xxxx_test

On Emscripten

This command should apply everything in this repo, if it doesn't I'll update it later

emcc smol_xxxx_test.c -o smol_xxx_test.html -sFULL_ES2=1 -sFULL_ES3=1 -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2  -s WASM=1 -sAUDIO_WORKLET=1 -sWASM_WORKERS=1 -sASYNCIFY=1 

TODO: build scripts

About

My attempt of making stb like single-header library solutions in C.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published