Raylib

#import Rendering.Raylib;

Bindings for the raylib 5.0 game development library.

To compile a program that uses this module, make sure you have the raylib libraries installed in your lib folder.

Important

TODO: This currently only contains support for 2D rendering.

Example:

#import Rendering.Raylib;

main :: () {
    InitWindow(800, 600, "Hello, raylib!");
    SetTargetFPS(60);
    while (WindowShouldClose() == false) {
        BeginDrawing();
            ClearBackground(RAYWHITE);
            DrawText("Hello, World!", 10, 10, 20, RED);
        EndDrawing();
    }
    CloseWindow();
}

Functions


Color32(r, g, b, a)

create :: Color32(r : int, g : int, b : int, a : int)

Creates a Color32 from individual RGBA components (0-255 each)

Color32(l)

create :: Color32(l : int)

Creates a grayscale Color32 from a single integer component (0-255)

InitWindow(width, height, title)

InitWindow :: (width : int, height : int, title : *char)

Initialises the window and OpenGL context

CloseWindow()

CloseWindow :: ()

Closes the window and unloads the OpenGL context

WindowShouldClose()

WindowShouldClose :: bool()

Returns true when the user presses Escape or clicks the close button

IsWindowReady()

IsWindowReady :: bool()

Returns true if the window has been initialized successfully

IsWindowMinimized()

IsWindowMinimized :: bool()

Returns true if the window is currently minimized

IsWindowMaximized()

IsWindowMaximized :: bool()

Returns true if the window is currently maximized

IsWindowFocused()

IsWindowFocused :: bool()

Returns true if the window is currently focused

IsWindowResized()

IsWindowResized :: bool()

Returns true if the window was resized this frame

SetWindowTitle(title)

SetWindowTitle :: (title : *char)

Sets the window title

SetWindowSize(width, height)

SetWindowSize :: (width : int, height : int)

Sets the window dimensions

SetWindowPosition(x, y)

SetWindowPosition :: (x : int, y : int)

Sets the window position on screen

GetScreenWidth()

GetScreenWidth :: int()

Returns the current screen width in pixels

GetScreenHeight()

GetScreenHeight :: int()

Returns the current screen height in pixels

SetTargetFPS(fps)

SetTargetFPS :: (fps : int)

Sets the target frames-per-second

GetFPS()

GetFPS :: int()

Returns the current frames-per-second

GetFrameTime()

GetFrameTime :: float()

Returns time in seconds for the last frame drawn (delta time)

GetTime()

GetTime :: double()

Returns elapsed time in seconds since InitWindow()

BeginDrawing()

BeginDrawing :: ()

Sets up the canvas to start drawing

EndDrawing()

EndDrawing :: ()

Ends canvas drawing and swaps buffers

ClearBackground(color)

ClearBackground :: (color : Color32)

Sets the background colour for this frame

BeginTextureMode(target)

BeginTextureMode :: (target : RenderTexture2D)

Begins drawing to an off-screen render texture

EndTextureMode()

EndTextureMode :: ()

Ends drawing to the render texture and resumes drawing to the screen

DrawPixel(posX, posY, color)

DrawPixel :: (posX : int, posY : int, color : Color32)

Draws a single pixel

DrawLine(startPosX, startPosY, endPosX, endPosY, color)

DrawLine :: (startPosX : int, startPosY : int, endPosX : int, endPosY : int, color : Color32)

Draws a line between two points

DrawRectangle(posX, posY, width, height, color)

DrawRectangle :: (posX : int, posY : int, width : int, height : int, color : Color32)

Draws a filled rectangle

DrawRectangleRect(rect, color)

DrawRectangleRect :: (rect : Rect, color : Color32)

Draws a filled rectangle using a Rect struct

DrawRectangleOutline(posX, posY, width, height, color)

DrawRectangleOutline :: (posX : int, posY : int, width : int, height : int, color : Color32)

Draws the outline of a rectangle

DrawCircle(centerX, centerY, radius, color)

DrawCircle :: (centerX : int, centerY : int, radius : float, color : Color32)

Draws a filled circle

DrawCircleOutline(centerX, centerY, radius, color)

DrawCircleOutline :: (centerX : int, centerY : int, radius : float, color : Color32)

Draws the outline of a circle

DrawFPS(posX, posY)

DrawFPS :: (posX : int, posY : int)

Draws the current FPS counter at the given position

DrawText(text, posX, posY, fontSize, color)

DrawText :: (text : *char, posX : int, posY : int, fontSize : int, color : Color32)

Draws text using the default font

MeasureText(text, fontSize)

MeasureText :: int(text : *char, fontSize : int)

Returns the width in pixels of the given text at the given font size

IsKeyPressed(key)

IsKeyPressed :: bool(key : int)

Returns true if the key was pressed this frame (once)

IsKeyDown(key)

IsKeyDown :: bool(key : int)

Returns true while the key is held down

IsKeyReleased(key)

IsKeyReleased :: bool(key : int)

Returns true if the key was released this frame

IsKeyUp(key)

IsKeyUp :: bool(key : int)

Returns true while the key is not held

GetKeyPressed()

GetKeyPressed :: int()

Returns the keycode of the next key in the input queue, or 0

IsMouseButtonPressed(button)

IsMouseButtonPressed :: bool(button : int)

Returns true if the mouse button was pressed this frame

IsMouseButtonDown(button)

IsMouseButtonDown :: bool(button : int)

Returns true while the mouse button is held

IsMouseButtonReleased(button)

IsMouseButtonReleased :: bool(button : int)

Returns true if the mouse button was released this frame

GetMouseX()

GetMouseX :: int()

Returns the current mouse X position in pixels

GetMouseY()

GetMouseY :: int()

Returns the current mouse Y position in pixels

GetMouseWheelMove()

GetMouseWheelMove :: float()

Returns the mouse wheel scroll delta for this frame

SetMousePosition(x, y)

SetMousePosition :: (x : int, y : int)

Sets the mouse cursor position

LoadImage(fileName)

LoadImage :: Image(fileName : *char)

Loads an image from file into CPU memory (RAM)

LoadImageFromMemory(fileType, fileData, dataSize)

LoadImageFromMemory :: Image(fileType : *char, fileData : *uint8, dataSize : int)

Loads an image from a memory buffer; fileType is the extension e.g. ".png"

LoadImageFromScreen()

LoadImageFromScreen :: Image()

Loads an image from the current screen buffer (screenshot)

UnloadImage(image)

UnloadImage :: (image : Image)

Unloads image data from CPU memory (RAM)

ExportImage(image, fileName)

ExportImage :: bool(image : Image, fileName : *char)

Exports image data to file; returns true on success

GetImageColor(image, x, y)

GetImageColor :: Color32(image : Image, x : int, y : int)

Returns the pixel color at (x, y) in the image

ImageDrawPixel(image, x, y, color)

ImageDrawPixel :: (image : *Image, posX : int, posY : int, color : Color32)

Sets the pixel color at (x, y) in the image

ImageResize(image, newWidth, newHeight)

ImageResize :: (image : *Image, newWidth : int, newHeight : int)

Resizes an image in-place using bicubic scaling

ImageResizeNN(image, newWidth, newHeight)

ImageResizeNN :: (image : *Image, newWidth : int, newHeight : int)

Resizes an image in-place using nearest-neighbour scaling

LoadRenderTexture(width, height)

LoadRenderTexture :: RenderTexture2D(width : int, height : int)

Loads a render texture (framebuffer) of the given size

UnloadRenderTexture(target)

UnloadRenderTexture :: (target : RenderTexture2D)

Unloads a render texture from GPU memory

LoadTexture(fileName)

LoadTexture :: Texture2D(fileName : *char)

Loads a texture from file into GPU memory (VRAM)

LoadTextureFromImage(image)

LoadTextureFromImage :: Texture2D(image : Image)

Loads a texture from an Image struct

UnloadTexture(texture)

UnloadTexture :: (texture : Texture2D)

Unloads texture from GPU memory (VRAM)

GenTextureMipmaps(texture)

GenTextureMipmaps :: (texture : *Texture2D)

Generates GPU mipmaps for a texture

DrawTexture(texture, posX, posY, tint)

DrawTexture :: (texture : Texture2D, posX : int, posY : int, tint : Color32)

Draws a Texture2D at the given position

DrawTextureV(texture, position, tint)

DrawTextureV :: (texture : Texture2D, position : Vector2, tint : Color32)

Draws a Texture2D at a Vector2 position

DrawTextureEx(texture, position, rotation, scale, tint)

DrawTextureEx :: (texture : Texture2D, position : Vector2, rotation : float, scale : float, tint : Color32)

Draws a Texture2D with extended transform parameters

DrawTextureRec(texture, source, position, tint)

DrawTextureRec :: (texture : Texture2D, source : Rect, position : Vector2, tint : Color32)

Draws a sub-rectangle of a texture

DrawTexturePro(texture, source, dest, origin, rotation, tint)

DrawTexturePro :: (texture : Texture2D, source : Rect, dest : Rect, origin : Vector2, rotation : float, tint : Color32)

Draws a texture with full source/dest rectangle and rotation control

Structs


Color32

@packed:

RGBA color value (4 x uint8)

Members:

Color32.r

uint8

The red color value

Color32.g

uint8

The green color value

Color32.b

uint8

The blue color value

Color32.a

uint8

The alpha color value

Image

Image pixel data stored in CPU memory (RAM)

Members:

Image.data

*uint8

A pointer to the image pixel data

Image.width

int

The width of the image in pixels

Image.height

int

The height of the image in pixels

Image.mipmaps

int

The number of mipmaps of the image

Image.format

int

The format of the image

Texture2D

Texture data stored in GPU memory (VRAM)

Members:

Texture2D.width

int

The width of the image in pixels

Texture2D.height

int

The height of the image in pixels

Texture2D.mipmaps

int

The number of mipmaps of the image

Texture2D.format

int

The format of the image

RenderTexture2D

Framebuffer for off-screen rendering; contains colour and depth textures

Members:

RenderTexture2D.texture

Texture2D

The texture value of the render texture

RenderTexture2D.depth

Texture2D

The depth texture of the render texture