Graphical applications with raylib on 9front
raylib is a simple and portable game-making library.
I recently have ported a chunk of it to run on the 9front fork of plan9. This is a small tutorial on how to get started with it.
Installation
; git/clone https://github.com/krzysckh/raylib9.git
; cd raylib9
; build.rc
; cp libraylib.a /somewhere/convenient/libraylib.a
Usage
This is a sample C program demonstrating basics of raylib.
#include <u.h>
#include "raylib.h"
void
(void)
main{
char *s = "Hello, World!";
, tv;
Vector2 szfloat vx = 5.f, vy = 5.f;
[] = {
Color colors, GRAY, DARKGRAY, YELLOW,
BLACK, ORANGE, PINK, RED, MAROON,
GOLD, LIME, DARKGREEN, SKYBLUE,
GREEN, DARKBLUE, PURPLE, VIOLET,
BLUE, BEIGE, BROWN, DARKBROWN,
DARKPURPLE, BLACK, MAGENTA,
WHITE};
= 0, ncol = sizeof(colors)/sizeof(colors[0]), W = 600, H = 600;
uint cc
(W, H, nil);
InitWindow(60);
SetTargetFPS
= MeasureTextEx(GetFontDefault(), s, 20, 0);
sz = (Vector2){ 0.f, 0.f };
tv
while (!WindowShouldClose()) {
if (IsKeyPressed(KEY_SPACE)) cc = (cc+1)%ncol;
();
BeginDrawing
(LIGHTGRAY);
ClearBackground
(tv.x, tv.y);
SetWindowPosition(s, tv.x, tv.y, 20, colors[cc]);
DrawText
.x += vx, tv.y += vy;
tv
if (tv.x+sz.x >= (float)W || tv.x < 0.f) vx = -vx;
if (tv.y+sz.y >= (float)H || tv.y < 0.f) vy = -vy;
(0, 0);
DrawFPS();
EndDrawing}
();
CloseWindow}
# assuming ./raylib9 is the raylib9 repo
; 6c -o temp.6 -Iraylib9 temp.c
; 6l -o a.out temp.6 raylib9/libraylib.a /$objtype/lib/ape/libap.a
; a.out
Internals
raylib9 uses PixelForge to
simulate OpenGL calls. It's vendored with the repo under
external/PixelForge
. Some things have been changed because
the plan9 c compilers are little crybabies.
Some stuff in raylib.h
was changed. In case raylib
struct names interfere with others, define RL_NO_STRUCT
,
and refer to them prefixed with rl
, so Rectangle → rlRectangle,
Color → rlColor
etc.
Limitations ∧ Bugs
- the performance is not great,
- keyboard input is kind of wacky, but fixable,
- texture transformations may not work correctly,
- no sound,
- compiling stuff without
libap.a
will cause memory problems (invalid writes frommemset
...?), - a lot more probably
Resources
- Source of raylib9,
- C Programming in Plan 9,
- Writing Interactive Graphical Programs on the 9front wiki