pntr
Image manipulation library
Examples

These are a few examples of pntr in use.

Alpha Mask

void pntr_examples_alphamask() {
// Load the Tuffy font, and find the size of the text output.
pntr_font* font = pntr_load_font_ttf("resources/tuffy.ttf", 80);
pntr_vector textSize = pntr_measure_text_ex(font, "Alpha Mask!", 0);
// Create a background to use as the alphamask.
// Create an alpha mask of text
pntr_image* imageText = pntr_gen_image_text(font, "Alpha Mask!", PNTR_WHITE);
// Apply the alpha mask to the image.
pntr_image_alpha_mask(output, imageText, 0, 0);
pntr_save_image(output, "pntr_examples_alphamask.png");
// Clean up
pntr_unload_image(imageText);
}
#define PNTR_BLUE
Definition: pntr.h:824
#define PNTR_DARKGREEN
Definition: pntr.h:812
#define PNTR_WHITE
Definition: pntr.h:872
#define PNTR_PURPLE
Definition: pntr.h:836
#define PNTR_RED
Definition: pntr.h:788
PNTR_API void pntr_unload_image(pntr_image *image)
Definition: pntr.h:1744
PNTR_API pntr_image * pntr_gen_image_gradient(int width, int height, pntr_color topLeft, pntr_color topRight, pntr_color bottomLeft, pntr_color bottomRight)
Definition: pntr.h:5197
PNTR_API pntr_image * pntr_gen_image_text(pntr_font *font, const char *text, pntr_color tint)
Definition: pntr.h:3836
PNTR_API bool pntr_save_image(pntr_image *image, const char *fileName)
Definition: pntr.h:4426
PNTR_API pntr_font * pntr_load_font_ttf(const char *fileName, int fontSize)
Definition: pntr.h:3938
PNTR_API void pntr_image_alpha_mask(pntr_image *image, pntr_image *alphaMask, int posX, int posY)
Definition: pntr.h:4661
PNTR_API pntr_vector pntr_measure_text_ex(pntr_font *font, const char *text, int textLength)
Definition: pntr.h:3774
PNTR_API void pntr_unload_font(pntr_font *font)
Definition: pntr.h:3530
Definition: pntr.h:467
Definition: pntr.h:404
Definition: pntr.h:445
int x
Definition: pntr.h:449
int y
Definition: pntr.h:454

Fonts

void pntr_examples_fonts() {
// Default Font
pntr_draw_image(canvas, defaultFont->atlas, 0, 0);
// Font Drawing
pntr_draw_text(canvas, defaultFont, "Default Font Example", 10, 50, PNTR_BLACK);
// BM Font
pntr_font* bmFont = pntr_load_font_bmf("resources/bmfont.png", " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/");
pntr_draw_rectangle_fill(canvas, 0, 90, 200, 20, PNTR_BLACK);
pntr_draw_text(canvas, bmFont, "BM Font Example", 10, 90, PNTR_WHITE);
// TTY Font
pntr_font* ttyFont = pntr_load_font_tty("resources/ttyfont-16x16.png", 16, 16,
"\x7f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~");
pntr_color background = pntr_get_color(0x0000caff);
pntr_color border = pntr_get_color(0x8a8affff);
pntr_draw_rectangle_fill(canvas, 0, 120, canvas->width, 60, border);
pntr_draw_rectangle_fill(canvas, 0, 130, canvas->width, 40, background);
const char* text = "*** TTY Font Example ***";
int textWidth = pntr_measure_text(ttyFont, text);
pntr_draw_text(canvas, ttyFont, text, canvas->width / 2 - textWidth / 2, 140, PNTR_WHITE);
// TTF Font
pntr_font* ttfFont = pntr_load_font_ttf("resources/tuffy.ttf", 28);
const char* ttfText = "TTF Font Example";
pntr_vector textSize = pntr_measure_text_ex(ttfFont, ttfText, 0);
pntr_draw_text(canvas, ttfFont, ttfText, 200, 20, PNTR_DARKPURPLE);
// Resize the default font
pntr_font* resizedFont = pntr_font_scale(defaultFont, 2.0f, 2.0f, PNTR_FILTER_NEARESTNEIGHBOR);
pntr_draw_text(canvas, resizedFont, "Blue Text", 10, 65, PNTR_BLUE);
pntr_unload_font(resizedFont);
// Word-wrapped
pntr_draw_rectangle(canvas, 225, 50, 150, 60, PNTR_BLUE);
pntr_draw_text_wrapped(canvas, bmFont, "The quick brown fox jumps over the lazy dog.", 225, 50, 150, PNTR_RED);
pntr_save_image(canvas, "pntr_examples_fonts.png");
pntr_unload_font(defaultFont);
pntr_unload_font(ttyFont);
pntr_unload_font(ttfFont);
}
#define PNTR_RAYWHITE
Definition: pntr.h:909
#define PNTR_DARKPURPLE
Definition: pntr.h:848
#define PNTR_BLACK
Definition: pntr.h:891
PNTR_API pntr_image * pntr_gen_image_color(int width, int height, pntr_color color)
Definition: pntr.h:1549
PNTR_API pntr_color pntr_get_color(unsigned int hexValue)
Definition: pntr.h:1832
PNTR_API void pntr_draw_text(pntr_image *dst, pntr_font *font, const char *text, int posX, int posY, pntr_color color)
Definition: pntr.h:3626
PNTR_API int pntr_measure_text(pntr_font *font, const char *text)
Definition: pntr.h:3761
PNTR_API void pntr_draw_image(pntr_image *dst, pntr_image *src, int posX, int posY)
Definition: pntr.h:2780
PNTR_API void pntr_draw_rectangle_fill(pntr_image *dst, int posX, int posY, int width, int height, pntr_color color)
Definition: pntr.h:2155
PNTR_API void pntr_draw_text_wrapped(pntr_image *dst, pntr_font *font, const char *text, int posX, int posY, int maxWidth, pntr_color tint)
Definition: pntr.h:3681
PNTR_API pntr_font * pntr_load_font_tty(const char *fileName, int glyphWidth, int glyphHeight, const char *characters)
Definition: pntr.h:3450
PNTR_API pntr_font * pntr_load_font_bmf(const char *fileName, const char *characters)
Definition: pntr.h:3314
PNTR_API pntr_font * pntr_load_font_default(void)
Definition: pntr.h:3869
PNTR_API void pntr_draw_rectangle(pntr_image *dst, int posX, int posY, int width, int height, pntr_color color)
Definition: pntr.h:2122
PNTR_API pntr_font * pntr_font_scale(pntr_font *font, float scaleX, float scaleY, pntr_filter filter)
Definition: pntr.h:3583
@ PNTR_FILTER_NEARESTNEIGHBOR
Definition: pntr.h:523
pntr_image * atlas
Definition: pntr.h:471
int width
Definition: pntr.h:413
Definition: pntr.h:314

Image

void pntr_examples_image() {
pntr_image* image;
pntr_image* resized;
// Load an image
image = pntr_load_image("resources/logo-128x128.png");
// Resize the image
resized = pntr_image_resize(image, image->width / 2, image->height / 2, PNTR_FILTER_NEARESTNEIGHBOR);
// Draw an image on the canvas
pntr_draw_image(canvas, image, 30, 30);
// Draw a section of an image
rect.x = 25;
rect.y = 16;
rect.width = 65;
rect.height = 58;
pntr_draw_image_rec(canvas, image, rect, 170, 30);
// Draw the resized image
pntr_draw_image(canvas, resized, 170, 100);
// Draw the resized image
pntr_draw_image_flipped(canvas, image, 240, 30, true, false, true);
pntr_save_image(canvas, "pntr_examples_image.png");
}
PNTR_API pntr_image * pntr_load_image(const char *fileName)
Definition: pntr.h:2746
PNTR_API void pntr_draw_image_rec(pntr_image *dst, pntr_image *src, pntr_rectangle srcRect, int posX, int posY)
Definition: pntr.h:2815
PNTR_API pntr_image * pntr_image_resize(pntr_image *image, int newWidth, int newHeight, pntr_filter filter)
Definition: pntr.h:2980
int height
Definition: pntr.h:418
Definition: pntr.h:376
int x
Definition: pntr.h:380
int height
Definition: pntr.h:395
int y
Definition: pntr.h:385
int width
Definition: pntr.h:390

Resize

void pntr_examples_resize() {
float size = 0.5f;
pntr_image* originalImage = pntr_load_image("resources/logo-128x128.png");
pntr_draw_image(canvas, originalImage, 10, 10);
pntr_draw_image_scaled(canvas, originalImage,
canvas->width / 4 - originalImage->width * size / 2.0f,
canvas->height / 2 - originalImage->height * size / 2.0f,
size, size, 0.0f, 0.0f, PNTR_FILTER_NEARESTNEIGHBOR);
pntr_draw_image_scaled(canvas, originalImage,
canvas->width / 2 + canvas->width / 4 - originalImage->width * size / 2.0f,
canvas->height / 2 - originalImage->height * size / 2.0f,
size, size, 0.0f, 0.0f, PNTR_FILTER_BILINEAR);
pntr_draw_image_scaled(canvas, originalImage,
canvas->width / 2 - originalImage->width * 0.75f / 2.0f,
canvas->height / 2 - originalImage->height * 0.75f / 2.0f,
0.75f, 0.75, 0.0f, 0.0f, PNTR_FILTER_NEARESTNEIGHBOR);
pntr_save_image(canvas, "pntr_examples_resize.png");
pntr_unload_image(originalImage);
}
PNTR_API void pntr_draw_image_scaled(pntr_image *dst, pntr_image *src, int posX, int posY, float scaleX, float scaleY, float offsetX, float offsetY, pntr_filter filter)
Definition: pntr.h:4803
@ PNTR_FILTER_BILINEAR
Definition: pntr.h:530

Rotate

void pntr_examples_rotate() {
pntr_image* imageToRotate = pntr_load_image("resources/logo-128x128.png");
// Draw the image rotated on screen using a nearest neighbor filter.
pntr_draw_image_rotated(canvas, imageToRotate, 10, canvas->height / 2, 0.0f, 0, imageToRotate->height / 2.0f, PNTR_FILTER_NEARESTNEIGHBOR);
// Draw the rotated image on the screen with a smooth filter.
pntr_draw_image_rotated(canvas, imageToRotate, 140, canvas->height / 2, 32.0f, 0, imageToRotate->height / 2.0f, PNTR_FILTER_BILINEAR);
// Draw the rotated image on the screen with a smooth filter.
pntr_draw_image_rotated(canvas, imageToRotate, 280, canvas->height / 2, 180.0f, 0, imageToRotate->height / 2.0f, PNTR_FILTER_BILINEAR);
pntr_save_image(canvas, "pntr_examples_rotate.png");
pntr_unload_image(imageToRotate);
}
PNTR_API void pntr_draw_image_rotated(pntr_image *dst, pntr_image *src, int posX, int posY, float degrees, float offsetX, float offsetY, pntr_filter filter)
Definition: pntr.h:5006

Shapes

void pntr_examples_shapes() {
// Define some colors
pntr_color lightGreen = PNTR_GREEN;
lightGreen.rgba.a = 180;
pntr_color lightBlue = PNTR_BLUE;
lightBlue.rgba.a = 180;
// Rectangles
pntr_draw_rectangle_fill(canvas, 10, 30, 50, 50, PNTR_RED);
pntr_draw_rectangle_fill(canvas, 20, 40, 50, 50, lightGreen);
pntr_draw_rectangle_fill(canvas, 30, 50, 50, 50, lightBlue);
pntr_draw_rectangle_thick(canvas, 10, 120, 50, 50, 5, PNTR_RED);
pntr_draw_rectangle_thick(canvas, 20, 130, 50, 50, 5, PNTR_GREEN);
pntr_draw_rectangle_thick(canvas, 30, 140, 50, 50, 5, PNTR_BLUE);
// Circle
pntr_draw_circle(canvas, 110, 60, 21, PNTR_RED);
pntr_draw_circle_fill(canvas, 160, 60, 21, PNTR_BLUE);
pntr_draw_ellipse(canvas, 110, 100, 20, 10, PNTR_GREEN);
pntr_draw_ellipse_fill(canvas, 160, 100, 20, 10, PNTR_ORANGE);
// Line
pntr_draw_line(canvas, 200, 50, 250, 80, PNTR_DARKGREEN);
// Triangle
250, 50,
300, 80,
350, 20, PNTR_PURPLE);
// Rectangle Gradient
pntr_draw_rectangle_gradient(canvas, 100, 120, 80, 80, PNTR_RED, PNTR_GREEN, PNTR_BLUE, PNTR_BLACK);
// Polygon
pntr_vector points[10];
points[0] = PNTR_CLITERAL(pntr_vector) {210, 110};
points[1] = PNTR_CLITERAL(pntr_vector) {215, 130};
points[2] = PNTR_CLITERAL(pntr_vector) {240, 140};
points[3] = PNTR_CLITERAL(pntr_vector) {200, 160};
pntr_draw_polygon_fill(canvas, points, 4, PNTR_BLUE);
pntr_draw_polygon(canvas, points, 4, PNTR_BLACK);
// Arc
int radius = 40;
pntr_draw_arc_fill(canvas, 300, 120, radius, 90.0f, 180.0f, radius * 1.5f, PNTR_ORANGE);
pntr_draw_arc(canvas, 300, 120, radius, 90.0f, 180.0f, radius *1.5f, PNTR_RED);
// Polyline
points[0] = PNTR_CLITERAL(pntr_vector) {240, 110};
points[1] = PNTR_CLITERAL(pntr_vector) {260, 130};
points[2] = PNTR_CLITERAL(pntr_vector) {220, 140};
points[3] = PNTR_CLITERAL(pntr_vector) {240, 160};
pntr_draw_polyline(canvas, points, 4, PNTR_PURPLE);
pntr_save_image(canvas, "pntr_examples_shapes.png");
}
#define PNTR_GREEN
Definition: pntr.h:800
#define PNTR_ORANGE
Definition: pntr.h:776
PNTR_API void pntr_draw_circle(pntr_image *dst, int centerX, int centerY, int radius, pntr_color color)
Definition: pntr.h:2241
PNTR_API void pntr_draw_triangle_fill(pntr_image *dst, int x1, int y1, int x2, int y2, int x3, int y3, pntr_color color)
Definition: pntr.h:2456
PNTR_API void pntr_draw_line(pntr_image *dst, int startPosX, int startPosY, int endPosX, int endPosY, pntr_color color)
Definition: pntr.h:1919
PNTR_API void pntr_draw_ellipse_fill(pntr_image *dst, int centerX, int centerY, int radiusX, int radiusY, pntr_color color)
Definition: pntr.h:2377
PNTR_API void pntr_draw_circle_fill(pntr_image *dst, int centerX, int centerY, int radius, pntr_color color)
Definition: pntr.h:2289
PNTR_API void pntr_draw_ellipse(pntr_image *dst, int centerX, int centerY, int radiusX, int radiusY, pntr_color color)
Definition: pntr.h:2327
unsigned char a
Definition: pntr.h:348

Sprite

void pntr_examples_sprite() {
// Load the image
pntr_image* scarfy = pntr_load_image("resources/scarfy.png");
pntr_rectangle frameRec;
frameRec.x = 0;
frameRec.y = 0;
frameRec.width = scarfy->width / 6;
frameRec.height = scarfy->height;
frameRec.x = 1 * (float)scarfy->width / 6;
pntr_draw_image_rec(canvas, scarfy, frameRec, 10, canvas->height / 2 - frameRec.height / 2);
frameRec.x = 3 * (float)scarfy->width / 6;
pntr_draw_image_rec(canvas, scarfy, frameRec, 120, canvas->height / 2 - frameRec.height / 2);
frameRec.x = 5 * (float)scarfy->width / 6;
pntr_draw_image_rec(canvas, scarfy, frameRec, 250, canvas->height / 2 - frameRec.height / 2);
pntr_save_image(canvas, "pntr_examples_sprite.png");
}