Complete API documentation for the Piper game framework.
bool InitGame(int width, int height, const char* title);Initializes the game window and framework systems.
Parameters:
width- Window width in pixelsheight- Window height in pixelstitle- Window title string
Returns: true on success, false on failure
Example:
if (!InitGame(800, 600, "My Game")) {
return -1;
}bool GameShouldClose(void);Checks if the window should close (user clicked X or pressed ESC).
Returns: true if window should close
void BeginFrame(void);Starts a new frame. Call this at the beginning of your game loop.
- Processes input events
- Updates delta time
- Sets up 2D rendering context
void EndFrame(void);Finishes the current frame and presents it to the window.
void CloseGame(void);Cleans up and closes the game. Call before exiting.
float GetDeltaTime(void);Gets the time in seconds since the last frame.
Returns: Time in seconds (float)
Example:
float speed = 200.0f; // pixels per second
float dt = GetDeltaTime();
x += speed * dt; // Frame-independent movementint GetScreenWidth(void);Gets the screen width in pixels.
int GetScreenHeight(void);Gets the screen height in pixels.
typedef struct {
float r, g, b, a; // Range: 0.0 to 1.0
} Color;Color MakeColor(int r, int g, int b, int a);Creates a color from 0-255 RGB values.
Parameters:
r, g, b, a- Color components (0-255)
Color MakeColorF(float r, float g, float b, float a);Creates a color from 0.0-1.0 float values.
void SetDrawColor(Color color);Sets the current drawing color for shapes.
void ClearBackground(Color color);Clears the screen with the specified color.
void DrawRectangle(float x, float y, float width, float height);Draws a filled rectangle.
Parameters:
x, y- Top-left corner positionwidth, height- Rectangle dimensions
void DrawCircle(float x, float y, float radius);Draws a filled circle.
Parameters:
x, y- Center positionradius- Circle radius
void DrawTriangle(float x1, float y1, float x2, float y2, float x3, float y3);Draws a filled triangle.
Parameters:
x1, y1- First vertexx2, y2- Second vertexx3, y3- Third vertex
void DrawPolygon(float* points, int numPoints);Draws a filled polygon.
Parameters:
points- Array of x,y coordinates [x1, y1, x2, y2, ...]numPoints- Number of vertices
void DrawLine(float x1, float y1, float x2, float y2, float thickness);Draws a line between two points.
void DrawRectangleLines(float x, float y, float width, float height, float thickness);Draws a rectangle outline.
void DrawCircleLines(float x, float y, float radius, float thickness);Draws a circle outline.
typedef struct {
unsigned int id;
int width;
int height;
} Texture;Texture* LoadTexture(const char* filename);Loads a texture from file (PNG, JPG, BMP, TGA supported).
Returns: Pointer to texture or NULL on failure
void DrawTexture(Texture* texture, float x, float y);Draws texture at position with original size.
void DrawTextureEx(Texture* texture, float x, float y, float width, float height,
float rotation, Color tint);Draws texture with transformations.
Parameters:
rotation- Rotation in degreestint- Color tint to apply
void DrawTexturePart(Texture* texture,
float srcX, float srcY, float srcWidth, float srcHeight,
float destX, float destY, float destWidth, float destHeight);Draws a portion of a texture (for sprite sheets).
void UnloadTexture(Texture* texture);Frees texture memory.
typedef struct {
float x, y; // Position
float zoom; // Scale factor (1.0 = normal)
float rotation; // Rotation in degrees
} Camera2D;void BeginCamera(Camera2D camera);Begins 2D camera mode.
void EndCamera(void);Ends camera mode.
Example:
Camera2D cam = {0, 0, 1.0f, 0};
BeginCamera(cam);
// Draw world objects
EndCamera();
// Draw UI (not affected by camera)bool IsKeyDown(int key);Checks if key is currently held down.
bool IsKeyPressed(int key);Checks if key was just pressed this frame.
KEY_SPACE, KEY_ESCAPE
KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT
KEY_W, KEY_S, KEY_A, KEY_Dvoid GetMousePosition(int* x, int* y);Gets current mouse cursor position.
Example:
int mx, my;
GetMousePosition(&mx, &my);bool IsMouseButtonDown(int button);Checks if mouse button is currently held.
bool IsMouseButtonPressed(int button);Checks if mouse button was just pressed this frame.
bool IsMouseButtonReleased(int button);Checks if mouse button was just released this frame.
MOUSE_LEFT (0)
MOUSE_MIDDLE (1)
MOUSE_RIGHT (2)typedef struct Font Font; // OpaqueFont* LoadFont(const char* fontPath, float fontSize);Loads a TrueType font from file.
Parameters:
fontPath- Path to .ttf font filefontSize- Font size in pixels
Returns: Pointer to font or NULL on failure
Font* LoadFontFromMemory(unsigned char* fontData, int dataSize, float fontSize);Loads font from memory buffer.
void UnloadFont(Font* font);Frees font memory.
void RenderText(Font* font, const char* text, float x, float y, Color color);Renders text at position.
void RenderTextEx(Font* font, const char* text, float x, float y, float spacing, Color color);Renders text with custom spacing.
Parameters:
spacing- Additional space between characters
float MeasureText(Font* font, const char* text);Returns the width of text in pixels.
float GetTextHeight(Font* font);Returns the line height for the font.
typedef vec2 Vector2; // float[2]void Vector2Make(Vector2 result, float x, float y);Creates a 2D vector.
Example:
Vector2 pos;
Vector2Make(pos, 100, 200);float Vector2Length(Vector2 v); // Length/magnitude
float Vector2Distance(Vector2 a, Vector2 b); // Distance between points
float Vector2Dot(Vector2 a, Vector2 b); // Dot product
float Vector2Angle(Vector2 v); // Angle in radians
void Vector2Normalize(Vector2 result, Vector2 v); // Normalize to unit length
void Vector2Rotate(Vector2 result, Vector2 v, float angle); // Rotate by angle
void Vector2Lerp(Vector2 result, Vector2 a, Vector2 b, float t); // Linear interpolationYou also have access to all vec2 functions from linmath.h:
vec2_add(r, a, b); // Add vectors
vec2_sub(r, a, b); // Subtract vectors
vec2_scale(r, v, s); // Scale by scalar
vec2_mul_inner(a, b); // Dot producttypedef struct Transform2D {
Vector2 position;
float rotation; // Radians
Vector2 scale;
} Transform2D;Transform2D Transform2DMake(float x, float y, float rotation,
float scaleX, float scaleY);void Transform2DApply(Vector2 result, Transform2D const* transform, Vector2 point);Applies transformation to a point.
float Clamp(float value, float min, float max);
float Lerp(float a, float b, float t);
float MapRange(float value, float inMin, float inMax, float outMin, float outMax);
float ToRadians(float degrees);
float ToDegrees(float radians);COLOR_WHITE
COLOR_BLACK
COLOR_RED
COLOR_GREEN
COLOR_BLUE
COLOR_YELLOW
COLOR_CYAN
COLOR_MAGENTA
COLOR_ORANGE
COLOR_PURPLE
COLOR_GRAY
COLOR_DARKGRAY
COLOR_LIGHTGRAYPI = 3.14159265358979323846
DEG2RAD = PI / 180.0
RAD2DEG = 180.0 / PI#define PIPER_IMPLEMENTATION
#define RGFWDEF
#include "piper.h"
int main() {
InitGame(800, 600, "Game");
while (!GameShouldClose()) {
BeginFrame();
ClearBackground(COLOR_BLACK);
// Your game code here
EndFrame();
}
CloseGame();
return 0;
}Vector2 position, velocity;
Vector2Make(position, 400, 300);
Vector2Make(velocity, 100, 0);
// In game loop:
Vector2 vel;
vec2_scale(vel, velocity, GetDeltaTime());
vec2_add(position, position, vel);For more examples, see the examples/ directory and TUTORIAL.md.