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
main(void)
{
  char *s = "Hello, World!";
  Vector2 sz, tv;
  float vx = 5.f, vy = 5.f;
  Color colors[] = {
    BLACK, GRAY, DARKGRAY, YELLOW,
    GOLD, ORANGE, PINK, RED, MAROON,
    GREEN, LIME, DARKGREEN, SKYBLUE,
    BLUE, DARKBLUE, PURPLE, VIOLET,
    DARKPURPLE, BEIGE, BROWN, DARKBROWN,
    WHITE, BLACK, MAGENTA,
  };

  uint cc = 0, ncol = sizeof(colors)/sizeof(colors[0]), W = 600, H = 600;

  InitWindow(W, H, nil);
  SetTargetFPS(60);

  sz = MeasureTextEx(GetFontDefault(), s, 20, 0);
  tv = (Vector2){ 0.f, 0.f };

  while (!WindowShouldClose()) {
    if (IsKeyPressed(KEY_SPACE)) cc = (cc+1)%ncol;
    BeginDrawing();

    ClearBackground(LIGHTGRAY);

    SetWindowPosition(tv.x, tv.y);
    DrawText(s, tv.x, tv.y, 20, colors[cc]);

    tv.x += vx, tv.y += vy;

    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;

    DrawFPS(0, 0);
    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

Resources