-
Notifications
You must be signed in to change notification settings - Fork 0
API Reference
Complete reference for all BlitEngine functions.
Initialize the BlitEngine.
int blit_init(BlitEngine *engine);Parameters:
-
engine- Pointer to BlitEngine structure to initialize
Returns:
-
0on success -
-1on failure
Example:
BlitEngine engine;
if (blit_init(&engine) != 0) {
printf("Failed to initialize!\n");
return 1;
}Notes:
- Call this once at program start
- Initializes NodGL, opens input devices, gets screen resolution
- Must call
blit_shutdown()when done
Shutdown the BlitEngine and clean up resources.
void blit_shutdown(BlitEngine *engine);Parameters:
-
engine- Engine to shut down
Example:
blit_shutdown(&engine);Notes:
- Call this once at program end
- Releases NodGL resources and closes input devices
Update input state for the current frame.
void blit_update_input(BlitEngine *engine);Parameters:
-
engine- Engine instance
Example:
while (blit_is_running(&engine)) {
blit_update_input(&engine); // Always first in loop!
// ... game logic ...
}Notes:
- Call once per frame at the start of your game loop
- Reads keyboard and mouse events
- Updates
engine.inputstructure
Check if the engine should keep running.
int blit_is_running(BlitEngine *engine);Parameters:
-
engine- Engine instance
Returns:
-
1if running -
0if should exit
Example:
while (blit_is_running(&engine)) {
// Game loop
}Begin a new frame and clear the screen.
void blit_begin_frame(BlitEngine *engine, uint32_t clear_color);Parameters:
-
engine- Engine instance -
clear_color- Color to clear screen to (ARGB format: 0xAARRGGBB)
Example:
blit_begin_frame(&engine, 0xFF000020); // Dark blueNotes:
- Call once per frame before drawing
- Clears the entire screen to the specified color
End the current frame and present to screen.
void blit_end_frame(BlitEngine *engine);Parameters:
-
engine- Engine instance
Example:
blit_end_frame(&engine);Notes:
- Call once per frame after all drawing
- Presents the frame to the screen
- Increments frame counter
- Yields CPU to other processes
Create a sprite from pixel data.
Sprite* blit_sprite_create(BlitEngine *engine, int width, int height, uint32_t *pixels);Parameters:
-
engine- Engine instance -
width- Sprite width in pixels -
height- Sprite height in pixels -
pixels- Pixel data array (ARGB format)
Returns:
- Pointer to created sprite, or
NULLon failure
Example:
uint32_t pixels[32 * 32];
// Fill pixels array...
Sprite *sprite = blit_sprite_create(&engine, 32, 32, pixels);Create a solid color sprite.
Sprite* blit_sprite_create_color(BlitEngine *engine, int width, int height, uint32_t color);Parameters:
-
engine- Engine instance -
width- Sprite width -
height- Sprite height -
color- Fill color (ARGB: 0xAARRGGBB)
Returns:
- Pointer to created sprite, or
NULLon failure
Example:
Sprite *red_square = blit_sprite_create_color(&engine, 32, 32, 0xFFFF0000);Create a circular sprite.
Sprite* blit_sprite_create_circle(BlitEngine *engine, int radius, uint32_t color);Parameters:
-
engine- Engine instance -
radius- Circle radius in pixels -
color- Circle color (ARGB)
Returns:
- Pointer to created sprite, or
NULLon failure
Example:
Sprite *blue_ball = blit_sprite_create_circle(&engine, 16, 0xFF0000FF);Notes:
- Creates a sprite of size
radius*2 x radius*2 - Areas outside circle are transparent
Free a sprite and release its resources.
void blit_sprite_free(BlitEngine *engine, Sprite *sprite);Parameters:
-
engine- Engine instance -
sprite- Sprite to free
Example:
blit_sprite_free(&engine, my_sprite);Draw a sprite at a position.
void blit_sprite_draw(BlitEngine *engine, Sprite *sprite, int x, int y);Parameters:
-
engine- Engine instance -
sprite- Sprite to draw -
x- X position (top-left) -
y- Y position (top-left)
Example:
blit_sprite_draw(&engine, player_sprite, 100, 200);Create a game entity.
Entity* blit_entity_create(float x, float y, int width, int height, Sprite *sprite);Parameters:
-
x- Initial X position -
y- Initial Y position -
width- Width for collision (not visual size) -
height- Height for collision -
sprite- Visual appearance (can be NULL)
Returns:
- Pointer to created entity, or
NULLon failure
Example:
Entity *player = blit_entity_create(100, 100, 32, 32, player_sprite);Free an entity.
void blit_entity_free(Entity *entity);Parameters:
-
entity- Entity to free
Example:
blit_entity_free(player);Notes:
- Does NOT free the entity's sprite (free that separately)
Update entity position based on velocity.
void blit_entity_update(Entity *entity);Parameters:
-
entity- Entity to update
Example:
entity->vx = 5;
entity->vy = -2;
blit_entity_update(entity); // Moves entity by (5, -2)Notes:
- Adds
vxtoxandvytoy
Draw an entity.
void blit_entity_draw(BlitEngine *engine, Entity *entity);Parameters:
-
engine- Engine instance -
entity- Entity to draw
Example:
blit_entity_draw(&engine, player);Notes:
- Only draws if entity is active and has a sprite
Check if two entities collide.
int blit_entity_collides(Entity *a, Entity *b);Parameters:
-
a- First entity -
b- Second entity
Returns:
-
1if colliding -
0if not colliding
Example:
if (blit_entity_collides(player, enemy)) {
printf("Hit!\n");
}Check if entity is visible on screen.
int blit_entity_on_screen(BlitEngine *engine, Entity *entity);Parameters:
-
engine- Engine instance -
entity- Entity to check
Returns:
-
1if on screen -
0if off screen
Example:
if (blit_entity_on_screen(&engine, bullet)) {
blit_entity_draw(&engine, bullet);
}Keep entity within screen bounds.
void blit_entity_clamp_to_screen(BlitEngine *engine, Entity *entity);Parameters:
-
engine- Engine instance -
entity- Entity to clamp
Example:
blit_entity_clamp_to_screen(&engine, player);Draw a filled rectangle.
void blit_draw_rect(BlitEngine *engine, int x, int y, int w, int h, uint32_t color);Parameters:
-
engine- Engine instance -
x,y- Position -
w,h- Size -
color- Fill color (ARGB)
Example:
blit_draw_rect(&engine, 50, 50, 100, 80, 0xFFFF0000);Draw a rectangle outline.
void blit_draw_rect_outline(BlitEngine *engine, int x, int y, int w, int h, uint32_t color, int thickness);Parameters:
-
engine- Engine instance -
x,y- Position -
w,h- Size -
color- Line color (ARGB) -
thickness- Line thickness in pixels
Example:
blit_draw_rect_outline(&engine, 50, 50, 100, 80, 0xFF00FF00, 3);Draw a line.
void blit_draw_line(BlitEngine *engine, int x0, int y0, int x1, int y1, uint32_t color, int thickness);Parameters:
-
engine- Engine instance -
x0,y0- Start point -
x1,y1- End point -
color- Line color (ARGB) -
thickness- Line thickness
Example:
blit_draw_line(&engine, 0, 0, 100, 100, 0xFFFFFFFF, 2);Draw a filled circle.
void blit_draw_circle(BlitEngine *engine, int cx, int cy, int radius, uint32_t color);Parameters:
-
engine- Engine instance -
cx,cy- Center point -
radius- Circle radius -
color- Fill color (ARGB)
Example:
blit_draw_circle(&engine, 200, 200, 30, 0xFF0000FF);Draw simple text.
void blit_draw_text(BlitEngine *engine, const char *text, int x, int y, uint32_t color);Parameters:
-
engine- Engine instance -
text- Text string to draw -
x,y- Position -
color- Text color (ARGB)
Example:
blit_draw_text(&engine, "Score: 100", 10, 10, 0xFFFFFFFF);Notes:
- Simple bitmap font (6x12 pixels per character)
- Each character is drawn as a small rectangle
Check if two rectangles overlap.
int blit_rects_overlap(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);Returns:
-
1if overlapping -
0if not overlapping
Check if a point is inside a rectangle.
int blit_point_in_rect(int px, int py, int rx, int ry, int rw, int rh);Returns:
-
1if inside -
0if outside
Calculate distance between two points.
float blit_distance(float x1, float y1, float x2, float y2);Returns:
- Approximate distance (Manhattan distance)
Clamp a value between min and max.
float blit_clamp(float value, float min, float max);Example:
health = blit_clamp(health, 0, 100);Get a random integer.
int blit_random_int(int min, int max);Parameters:
-
min- Minimum value (inclusive) -
max- Maximum value (inclusive)
Returns:
- Random integer between min and max
Example:
int dice = blit_random_int(1, 6);Get a random float between 0 and 1.
float blit_random_float(void);Returns:
- Random float between 0.0 and 1.0
Example:
if (blit_random_float() < 0.1) { // 10% chance
spawn_powerup();
}Check if a key is currently held down.
int blit_key_down(BlitEngine *engine, int keycode);Returns:
-
1if key is down -
0if key is up
Example:
if (blit_key_down(&engine, KEY_W)) {
player_y -= 3;
}Check if a key was just pressed this frame.
int blit_key_pressed(BlitEngine *engine, int keycode);Returns:
-
1if just pressed -
0otherwise
Example:
if (blit_key_pressed(&engine, KEY_SPACE)) {
fire_weapon(); // Only fires once per press
}Check if mouse button is held down.
int blit_mouse_down(BlitEngine *engine, int button);Parameters:
-
button-MOUSE_LEFT,MOUSE_RIGHT, orMOUSE_MIDDLE
Returns:
-
1if button is down -
0if button is up
Check if mouse button was just clicked.
int blit_mouse_clicked(BlitEngine *engine, int button);Returns:
-
1if just clicked -
0otherwise
KEY_ESC // Escape key
KEY_SPACE // Space bar
KEY_ENTER // Enter/Return
KEY_W, KEY_A, KEY_S, KEY_D // WASD keys
KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT // Arrow keys
KEY_1, KEY_2, KEY_3 // Number keysMOUSE_LEFT // Left mouse button
MOUSE_RIGHT // Right mouse button
MOUSE_MIDDLE // Middle mouse buttontypedef struct {
NodGL_Device device; // Graphics device
NodGL_Context ctx; // Graphics context
uint32_t screen_width; // Screen width in pixels
uint32_t screen_height; // Screen height in pixels
int event_queue_fd; // Input event file descriptor
Input input; // Current input state
int running; // Is engine running?
uint32_t frame_count; // Total frames rendered
} BlitEngine;int w = engine.screen_width;
int h = engine.screen_height;
int mx = engine.input.mouse_x;
int my = engine.input.mouse_y;
int buttons = engine.input.mouse_buttons;
uint32_t frames = engine.frame_count;typedef struct {
float x, y; // Position
float vx, vy; // Velocity
int width, height; // Size (for collision)
Sprite *sprite; // Visual appearance
int active; // Is entity active?
void *user_data; // Custom game data
} Entity;Back to: BlitEngine Introduction