Luno is a lightweight 2D graphics library designed for creating games or graphical applications in C. It provides a simple interface for window management, drawing primitives, image handling, text rendering, and input handling.
- Window Management: Create and scale windows.
- Rendering: Draw pixels, lines, rectangles, circles, and images.
- Font Rendering: Render bitmap fonts with ease.
- Input Handling: Detect keyboard, mouse buttons, and mouse wheel inputs.
- Timers: Create timers for interval-based actions.
- Collision Detection: Perform basic 2D overlap checks.
- Small header-only library: ~1.2k lines of C
- Software rendered images and bitmap fonts
- Keyboard and mouse input
- Image Loading (via rc_tga)
- No dependencies
- Windows only
-
Clone the repository:
git clone git@github.com:RednibCoding/luno.git
-
Copy the 'luno.h' into your project.
-
Include the Luno header:
#define LUNO_IMPL #include "luno/luno.h"
Do
#define LUNO_IMPLbefore you includeluno.hin one C file to create the implementation. In all other files just includeluno.hwithout creating the implementations.#include "luno/luno.h"
-
Compile your project:
gcc -o game.exe main.c -lgdi32 -luser32 -lwinmm
#define LUNO_IMPL
#include "luno/Luno.h"
int main()
{
if (!Luno_Create("Luno Window", 800, 600, 30))
return -1;
Luno_SetClearColor(LUNO_DARKGRAY);
while (Luno_Update())
{
Luno_Clear();
Luno_DrawText("Hello Luno", 50, 50, LUNO_WHITE);
}
Luno_Close();
return 0;
}Creates a window with the specified title, dimensions, and target frame rate.
- Parameters:
title: The title of the window.width,height: Dimensions of the window.targetFPS: The desired frames per second.
- Returns:
trueon success,falseon failure.
Closes the window and releases resources.
Scales the window dimensions by a given factor.
- Parameter:
factor: The scaling factor (e.g.,2doubles the size).
Sets the background color used when clearing the screen.
Clears the screen to the current clear color.
Draws a single pixel at the specified coordinates.
Gets the pixel color of the given image at the location x, y.
Draws a rectangle.
- Parameters:
rect: The rectangle to draw.color: The color of the rectangle.fill:trueto fill the rectangle,falsefor an outline.
Draws a circle.
- Parameters:
x,y: The center of the circle.radius: The radius of the circle.color: The color of the circle.fill:trueto fill the circle,falsefor an outline.
Draws a line between two points.
Creates a blank image.
- Returns: A pointer to the created image.
Loads an image from a file.
- Returns: A pointer to the loaded image, or
NULLon failure.
Loads an image from memory.
- Returns: A pointer to the loaded image, or
NULLon failure.
Fills an image with a specified color.
Draws an image at the specified position.
Draws a portion of an image.
Releases resources associated with an image.
Creates a font from an image.
Loads a font from a file.
Loads a font from memory.
Draws a string of text.
Draws formatted text.
Releases resources associated with a font.
Checks if a key was pressed this frame.
Checks if a key is currently held down.
Checks if a key was released this frame.
Checks if a mouse button was pressed this frame.
Checks if a mouse button is currently held down.
Checks if a mouse button was released this frame.
Returns the current mouse position.
Returns the change in mouse position since the last frame.
Returns the change in the mouse wheel since the last frame.
Sets the cursor visibility.
Checks if the cursor is visible.
Creates a timer with the specified interval (in milliseconds).
Checks if the timer has reached its interval this frame.
Resets a timer to start counting from now.
Returns the elapsed time in milliseconds since the timer started.
Checks if a point is inside a rectangle.
Checks if two rectangles overlap.
Checks if a point is inside a circle.
Checks if a rectangle and circle overlap.
bool Luno_CirclesOverlaps(int cx1, int cy1, float circle1Radius, int cx2, int cy2, float circle2Radius)
Checks if two circles overlap.
The Luno library provides a variety of predefined colors for ease of use:
#define LUNO_WHITE (LunoColor){255, 255, 255, 255}
#define LUNO_BLACK (LunoColor){0, 0, 0, 255}
#define LUNO_RED (LunoColor){255, 0, 0, 255}
#define LUNO_GREEN (LunoColor){0, 255, 0, 255}
#define LUNO_BLUE (LunoColor){0, 0, 255, 255}
#define LUNO_YELLOW (LunoColor){255, 255, 0, 255}
#define LUNO_CYAN (LunoColor){0, 255, 255, 255}
#define LUNO_MAGENTA (LunoColor){255, 0, 255, 255}
#define LUNO_LIGHTGRAY (LunoColor){211, 211, 211, 255}
#define LUNO_GRAY (LunoColor){128, 128, 128, 255}
#define LUNO_DARKGRAY (LunoColor){64, 64, 64, 255}
#define LUNO_ORANGE (LunoColor){255, 165, 0, 255}
#define LUNO_PURPLE (LunoColor){128, 0, 128, 255}
#define LUNO_BROWN (LunoColor){165, 42, 42, 255}
#define LUNO_PINK (LunoColor){255, 192, 203, 255}
#define LUNO_LIME (LunoColor){50, 205, 50, 255}
#define LUNO_TEAL (LunoColor){0, 128, 128, 255}
#define LUNO_GOLD (LunoColor){255, 215, 0, 255}
#define LUNO_SILVER (LunoColor){192, 192, 192, 255}
#define LUNO_BEIGE (LunoColor){245, 245, 220, 255}
#define LUNO_IVORY (LunoColor){255, 255, 240, 255}
#define LUNO_KHAKI (LunoColor){240, 230, 140, 255}
#define LUNO_NAVY (LunoColor){0, 0, 128, 255}
#define LUNO_MAROON (LunoColor){128, 0, 0, 255}
#define LUNO_OLIVE (LunoColor){128, 128, 0, 255}
#define LUNO_AQUA (LunoColor){0, 255, 255, 255}
#define LUNO_CORAL (LunoColor){255, 127, 80, 255}
#define LUNO_TAN (LunoColor){210, 180, 140, 255}
#define LUNO_SKYBLUE (LunoColor){135, 206, 235, 255}
#define LUNO_MINT (LunoColor){189, 252, 201, 255}
#define LUNO_PEACH (LunoColor){255, 218, 185, 255}
#define LUNO_CHOCOLATE (LunoColor){210, 105, 30, 255}
#define LUNO_VIOLET (LunoColor){238, 130, 238, 255}
#define LUNO_INDIGO (LunoColor){75, 0, 130, 255}
#define LUNO_TURQUOISE (LunoColor){64, 224, 208, 255}
#define LUNO_SALMON (LunoColor){250, 128, 114, 255}
#define LUNO_WHEAT (LunoColor){245, 222, 179, 255}typedef struct {
int x;
int y;
} LunoPoint;Represents a 2D point.
typedef struct {
int r, g, b, a;
} LunoColor;Represents a color with red, green, blue, and alpha components.
typedef struct {
int x, y, w, h;
} LunoRect;Represents a rectangle.
typedef struct {
_LunoPixel *pixels;
int width, height;
} LunoImage;Represents an image, including pixel data and dimensions.
typedef struct {
LunoRect rect;
int xadv;
} LunoGlyph;Represents a font glyph, including its rectangle and horizontal advance.
typedef struct
{
int interval; // Interval in milliseconds.
int lastTrigger; // Last trigger time in milliseconds.
} LunoTimer;Represents a Timer for interval-based actions.
typedef struct {
LunoImage *image;
LunoGlyph glyphs[256];
} LunoFont;Represents a font, including its image and glyphs.
Type: double
Description: Delta time in seconds since the last frame.
Type: double
Description: The current frames per second.
Type: int
Description: Milliseconds since the application started.
- Lua bindings: Readme
Luno is open-source and available under the MIT License.