![]() |
pntr
Header-only CPU graphics library
|
Macros | |
| #define | PNTR_DEG2RAD 0.017453293f |
| #define | PNTR_SINF(value) _pntr_sinf(value) |
| #define | PNTR_COSF(value) _pntr_cosf(value) |
| #define | PNTR_CEILF(x) _pntr_ceilf(x) |
| #define | PNTR_FABSF(x) (((x) < 0) ? -(x) : (x)) |
| #define | PNTR_FLOORF(x) (float)(((int)(x)) - (((x) < 0.0f) ? 1 : 0)) |
| #define | PNTR_FMODF(dividend, divisor) ((divisor) == 0.0f ? 0.0f : (dividend) - ((int)((dividend) / (divisor))) * (divisor)) |
| #define | PNTR_MAX(a, b) ((a) > (b) ? (a) : (b)) |
| #define | PNTR_MIN(a, b) ((a) < (b) ? (a) : (b)) |
Compound literal to initialize a structure.
@param type The type of the structure to intiailize.
@return The initialized structure.
@note MSVC C++ compiler does not support compound literals (C99 feature)
@code
pntr_color color = PNTR_CLITERAL(pntr_color) { 255, 255, 255, 255 };
@endif
/
#define PNTR_CLITERAL(type) (type)
#endif
#endif
/** Color, represented by an unsigned 32-bit integer.
Has four components: Red, Green, Blue, and Alpha. Depending on the pixel format, will shift the order in which the components are defines.
/** Union data representing the 32-bit integer, split into four bytes.
The order in which the values are sorted depends on which pixel format you're using.
/** A rectangle. / typedef struct pntr_rectangle { int x; /** The x position of the rectangle. */ int y; /** The y position of the rectangle. */ int width; /** The width of the rectangle. */ int height; /** The height of the rectangle. */ } pntr_rectangle;
/** An image, represented by pixel data.
/** Whether or not the image is a portion of another image, sharing the same image data.
/** A rectangle representing the region of the image that can be changed.
/** A vector, represented by x and y coordinates. / typedef struct pntr_vector { int x; /** The X coordinate. */ int y; /** The Y coordinate. */ } pntr_vector;
/** Font used to render text.
/** Pixel format. / typedef enum pntr_pixelformat { PNTR_PIXELFORMAT_RGBA8888 = 0, /** RGBA, with 8 bytes for each component. */ PNTR_PIXELFORMAT_ARGB8888, /** ARGB, with 8 bytes for each component. */ PNTR_PIXELFORMAT_GRAYSCALE /** Grayscale, with one byte for each pixel, 0 - 255. 0 being disabled, 255 being enabled. */ } pntr_pixelformat;
/** Possible image filters to apply. / typedef enum pntr_filter { PNTR_FILTER_NEARESTNEIGHBOR = 0, /** Nearest-neighbor interpolation for fast processing. Good for a pixel art look. */ PNTR_FILTER_BILINEAR /** Bilinear interpolation will combine multiple pixels together when processing for smoother scaling. */ } pntr_filter;
/** Error states definitions.
/** The associated image format. / typedef enum pntr_image_type { PNTR_IMAGE_TYPE_UNKNOWN = 0, /** Image type: Unknown. */ PNTR_IMAGE_TYPE_PNG, /** Image type: PNG - Portable Network Graphics */ PNTR_IMAGE_TYPE_JPG, /** Image type: JPEG - Joint Photographic Experts Group */ PNTR_IMAGE_TYPE_BMP /** Image type: BMP - Bitmap */ } pntr_image_type;
#ifdef __cplusplus extern "C" { #endif
PNTR_API pntr_image* pntr_new_image(int width, int height); PNTR_API pntr_image* pntr_gen_image_color(int width, int height, pntr_color color); PNTR_API pntr_image* pntr_image_copy(pntr_image* image); PNTR_API pntr_image* pntr_image_from_image(pntr_image* image, int x, int y, int width, int height); PNTR_API pntr_image* pntr_image_subimage(pntr_image* image, int x, int y, int width, int height); PNTR_API pntr_rectangle pntr_image_get_clip(pntr_image* image); PNTR_API void pntr_image_set_clip(pntr_image* image, int x, int y, int width, int height); PNTR_API void pntr_image_set_clip_rec(pntr_image* image, pntr_rectangle clip); PNTR_API void pntr_image_reset_clip(pntr_image* image); PNTR_API void pntr_unload_image(pntr_image* image); PNTR_API void pntr_clear_background(pntr_image* image, pntr_color color); PNTR_API void pntr_draw_point(pntr_image* dst, int x, int y, pntr_color color); PNTR_API void pntr_draw_point_vec(pntr_image* dst, pntr_vector* point, pntr_color color); PNTR_API void pntr_draw_points(pntr_image* dst, pntr_vector* points, int pointsCount, pntr_color color); PNTR_API void pntr_draw_line(pntr_image* dst, int startPosX, int startPosY, int endPosX, int endPosY, pntr_color color); PNTR_API void pntr_draw_line_curve(pntr_image* dst, pntr_vector point1, pntr_vector point2, pntr_vector point3, pntr_vector point4, int segments, pntr_color color); PNTR_API void pntr_draw_line_vec(pntr_image* dst, pntr_vector start, pntr_vector end, pntr_color color); PNTR_API void pntr_draw_line_vertical(pntr_image* dst, int posX, int posY, int height, pntr_color color); PNTR_API void pntr_draw_line_horizontal(pntr_image* dst, int posX, int posY, int width, pntr_color color); PNTR_API void pntr_draw_rectangle(pntr_image* dst, int posX, int posY, int width, int height, pntr_color color); PNTR_API void pntr_draw_rectangle_rec(pntr_image* dst, pntr_rectangle rec, pntr_color color); PNTR_API void pntr_draw_rectangle_fill(pntr_image* dst, int posX, int posY, int width, int height, pntr_color color); PNTR_API void pntr_draw_rectangle_fill_rec(pntr_image* dst, pntr_rectangle rect, pntr_color color); PNTR_API void pntr_draw_rectangle_gradient(pntr_image* dst, int x, int y, int width, int height, pntr_color topLeft, pntr_color topRight, pntr_color bottomLeft, pntr_color bottomRight); PNTR_API void pntr_draw_rectangle_gradient_rec(pntr_image* dst, pntr_rectangle rect, pntr_color topLeft, pntr_color topRight, pntr_color bottomLeft, pntr_color bottomRight); PNTR_API void pntr_draw_triangle(pntr_image* dst, int x1, int y1, int x2, int y2, int x3, int y3, pntr_color color); PNTR_API void pntr_draw_triangle_vec(pntr_image* dst, pntr_vector point1, pntr_vector point2, pntr_vector point3, pntr_color color); 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); PNTR_API void pntr_draw_triangle_fill_vec(pntr_image* dst, pntr_vector point1, pntr_vector point2, pntr_vector point3, pntr_color color); PNTR_API void pntr_draw_ellipse(pntr_image* dst, int centerX, int centerY, int radiusX, int radiusY, pntr_color color); PNTR_API void pntr_draw_ellipse_fill(pntr_image* dst, int centerX, int centerY, int radiusX, int radiusY, pntr_color color); PNTR_API void pntr_draw_circle(pntr_image* dst, int centerX, int centerY, int radius, pntr_color color); PNTR_API void pntr_draw_circle_fill(pntr_image* dst, int centerX, int centerY, int radius, pntr_color color); PNTR_API void pntr_draw_polygon(pntr_image* dst, pntr_vector* points, int numPoints, pntr_color color); PNTR_API void pntr_draw_polygon_fill(pntr_image* dst, pntr_vector* points, int numPoints, pntr_color color); PNTR_API void pntr_draw_polyline(pntr_image* dst, pntr_vector* points, int numPoints, pntr_color color); PNTR_API void pntr_draw_arc(pntr_image* dst, int centerX, int centerY, float radius, float startAngle, float endAngle, int segments, pntr_color color); PNTR_API void pntr_draw_arc_fill(pntr_image* dst, int centerX, int centerY, float radius, float startAngle, float endAngle, int segments, pntr_color color); PNTR_API void pntr_draw_rectangle_rounded(pntr_image* dst, int x, int y, int width, int height, int topLeftRadius, int topRightRadius, int bottomLeftRadius, int bottomRightRadius, pntr_color color); PNTR_API void pntr_draw_rectangle_rounded_fill(pntr_image* dst, int x, int y, int width, int height, int cornerRadius, pntr_color color); PNTR_API void pntr_draw_image(pntr_image* dst, pntr_image* src, int posX, int posY); PNTR_API void pntr_draw_image_rec(pntr_image* dst, pntr_image* src, pntr_rectangle srcRect, int posX, int posY); PNTR_API void pntr_draw_image_tint(pntr_image* dst, pntr_image* src, int posX, int posY, pntr_color tint); PNTR_API void pntr_draw_image_tint_rec(pntr_image* dst, pntr_image* src, pntr_rectangle srcRect, int posX, int posY, pntr_color tint); 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); PNTR_API void pntr_draw_image_rotated_rec(pntr_image* dst, pntr_image* src, pntr_rectangle srcRect, int posX, int posY, float degrees, float offsetX, float offsetY, pntr_filter filter); PNTR_API void pntr_draw_image_flipped(pntr_image* dst, pntr_image* src, int posX, int posY, bool flipHorizontal, bool flipVertical, bool flipDiagonal); PNTR_API void pntr_draw_image_flipped_rec(pntr_image* dst, pntr_image* src, pntr_rectangle srcRec, int posX, int posY, bool flipHorizontal, bool flipVertical, bool flipDiagonal); 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); PNTR_API void pntr_draw_image_scaled_rec(pntr_image* dst, pntr_image* src, pntr_rectangle srcRect, int posX, int posY, float scaleX, float scaleY, float offsetX, float offsetY, pntr_filter filter); PNTR_API void pntr_draw_text(pntr_image* dst, pntr_font* font, const char* text, int posX, int posY, pntr_color tint); PNTR_API void pntr_draw_text_len(pntr_image* dst, pntr_font* font, const char* text, int textLength, int posX, int posY, pntr_color tint); 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); #ifdef PNTR_ENABLE_VARGS PNTR_API void pntr_draw_text_ex(pntr_image* dst, pntr_font* font, int posX, int posY, pntr_color tint, int maxlen, const char* text, ...); #endif PNTR_API pntr_color pntr_new_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a); PNTR_API pntr_color pntr_get_color(unsigned int hexValue); PNTR_API unsigned char pntr_color_r(pntr_color color); PNTR_API unsigned char pntr_color_g(pntr_color color); PNTR_API unsigned char pntr_color_b(pntr_color color); PNTR_API unsigned char pntr_color_a(pntr_color color); PNTR_API void pntr_color_set_r(pntr_color* color, unsigned char r); PNTR_API void pntr_color_set_g(pntr_color* color, unsigned char g); PNTR_API void pntr_color_set_b(pntr_color* color, unsigned char b); PNTR_API void pntr_color_set_a(pntr_color* color, unsigned char a); PNTR_API pntr_color pntr_image_get_color(pntr_image* image, int x, int y); PNTR_API bool pntr_save_file(const char <em>fileName, const void *data, unsigned int bytesToWrite); PNTR_API void pntr_image_to_pixelformat(pntr_image* image, unsigned int* dataSize, pntr_pixelformat pixelFormat); PNTR_API bool pntr_save_image(pntr_image* image, const char* fileName); PNTR_API unsigned char* pntr_save_image_to_memory(pntr_image* image, pntr_image_type type, unsigned int* dataSize); PNTR_API int pntr_get_pixel_data_size(int width, int height, pntr_pixelformat pixelFormat); PNTR_API pntr_image* pntr_load_image(const char* fileName); PNTR_API pntr_image* pntr_load_image_from_memory(pntr_image_type type, const unsigned char* fileData, unsigned int dataSize); PNTR_API pntr_image* pntr_image_from_pixelformat(const void* data, int width, int height, pntr_pixelformat pixelFormat); PNTR_API void* pntr_set_error(pntr_error error); PNTR_API const char* pntr_get_error(void); PNTR_API pntr_error pntr_get_error_code(void); PNTR_API pntr_image* pntr_image_resize(pntr_image* image, int newWidth, int newHeight, pntr_filter filter); PNTR_API pntr_image* pntr_image_scale(pntr_image* image, float scaleX, float scaleY, pntr_filter filter); PNTR_API void pntr_image_color_replace(pntr_image* image, pntr_color color, pntr_color replace); PNTR_API pntr_color pntr_color_tint(pntr_color color, pntr_color tint); PNTR_API void pntr_image_color_tint(pntr_image* image, pntr_color color); PNTR_API pntr_color pntr_color_fade(pntr_color color, float alpha); PNTR_API void pntr_image_color_fade(pntr_image* image, float alpha); PNTR_API pntr_color pntr_color_brightness(pntr_color color, float factor); PNTR_API pntr_color pntr_get_pixel_color(void* srcPtr, pntr_pixelformat srcPixelFormat); PNTR_API void pntr_set_pixel_color(void* dstPtr, pntr_pixelformat dstPixelFormat, pntr_color color); PNTR_API pntr_font* pntr_load_font_default(void); PNTR_API void pntr_unload_font(pntr_font* font); PNTR_API pntr_font* pntr_font_copy(pntr_font* font); PNTR_API pntr_font* pntr_font_scale(pntr_font* font, float scaleX, float scaleY, pntr_filter filter); PNTR_API pntr_font* pntr_load_font_bmf(const char* fileName, const char* characters); PNTR_API pntr_font* pntr_load_font_bmf_from_image(pntr_image* image, const char* characters); PNTR_API pntr_font* pntr_load_font_bmf_from_memory(const unsigned char* fileData, unsigned int dataSize, const char* characters); PNTR_API int pntr_measure_text(pntr_font* font, const char* text); PNTR_API pntr_vector pntr_measure_text_ex(pntr_font* font, const char* text, int textLength); PNTR_API pntr_image* pntr_gen_image_text(pntr_font* font, const char* text, pntr_color tint, pntr_color backgroundColor); PNTR_API pntr_font* pntr_load_font_tty(const char* fileName, int glyphWidth, int glyphHeight, const char* characters); PNTR_API pntr_font* pntr_load_font_tty_from_memory(const unsigned char* fileData, unsigned int dataSize, int glyphWidth, int glyphHeight, const char* characters); PNTR_API pntr_font* pntr_load_font_tty_from_image(pntr_image* image, int glyphWidth, int glyphHeight, const char* characters); PNTR_API unsigned char* pntr_load_file(const char <em>fileName, unsigned int *bytesRead); PNTR_API void pntr_unload_file(unsigned char fileData); PNTR_API const char* pntr_load_file_text(const char <em>fileName); PNTR_API void pntr_unload_file_text(const char text); PNTR_API pntr_font* pntr_load_font_ttf(const char* fileName, int fontSize); PNTR_API pntr_font* pntr_load_font_ttf_from_memory(const unsigned char* fileData, unsigned int dataSize, int fontSize); PNTR_API pntr_color pntr_color_invert(pntr_color color); PNTR_API void pntr_image_color_invert(pntr_image* image); PNTR_API pntr_color pntr_color_alpha_blend(pntr_color dst, pntr_color src); PNTR_API pntr_rectangle pntr_image_alpha_border(pntr_image* image, float threshold); PNTR_API bool pntr_image_crop(pntr_image* image, int x, int y, int width, int height); PNTR_API void pntr_image_alpha_crop(pntr_image* image, float threshold); PNTR_API void pntr_image_color_brightness(pntr_image* image, float factor); PNTR_API void pntr_image_flip(pntr_image* image, bool horizontal, bool vertical); PNTR_API pntr_color pntr_color_contrast(pntr_color color, float contrast); PNTR_API void pntr_image_color_contrast(pntr_image* image, float contrast); PNTR_API void pntr_image_alpha_mask(pntr_image* image, pntr_image* alphaMask, int posX, int posY); PNTR_API bool pntr_image_resize_canvas(pntr_image* image, int newWidth, int newHeight, int offsetX, int offsetY, pntr_color fill); PNTR_API pntr_image* pntr_image_rotate(pntr_image* image, float degrees, pntr_filter filter); PNTR_API pntr_image* pntr_gen_image_gradient(int width, int height, pntr_color topLeft, pntr_color topRight, pntr_color bottomLeft, pntr_color bottomRight); PNTR_API pntr_color pntr_color_bilinear_interpolate(pntr_color color00, pntr_color color01, pntr_color color10, pntr_color color11, float coordinateX, float coordinateY); PNTR_API void* pntr_load_memory(size_t size); PNTR_API void pntr_unload_memory(void* pointer); PNTR_API void* pntr_memory_copy(void* destination, void* source, size_t size); PNTR_API pntr_image_type pntr_get_file_image_type(const char* filePath);
PNTR_API void pntr_draw_line_thick(pntr_image* dst, int startPosX, int startPosY, int endPosX, int endPosY, int thickness, pntr_color color); PNTR_API void pntr_draw_line_thick_vec(pntr_image* dst, pntr_vector start, pntr_vector end, int thickness, pntr_color color); PNTR_API void pntr_draw_rectangle_thick(pntr_image* dst, int posX, int posY, int width, int height, int thickness, pntr_color color); PNTR_API void pntr_draw_rectangle_thick_rec(pntr_image* dst, pntr_rectangle rect, int thickness, pntr_color color); PNTR_API void pntr_draw_triangle_thick(pntr_image* dst, int x1, int y1, int x2, int y2, int x3, int y3, int thickness, pntr_color color); PNTR_API void pntr_draw_triangle_thick_vec(pntr_image* dst, pntr_vector point1, pntr_vector point2, pntr_vector point3, int thickness, pntr_color color); PNTR_API void pntr_draw_ellipse_thick(pntr_image* dst, int centerX, int centerY, int radiusX, int radiusY, int thickness, pntr_color color); PNTR_API void pntr_draw_circle_thick(pntr_image* dst, int centerX, int centerY, int radius, int thickness, pntr_color color); PNTR_API void pntr_draw_polygon_thick(pntr_image* dst, pntr_vector* points, int numPoints, int thickness, pntr_color color); PNTR_API void pntr_draw_polyline_thick(pntr_image* dst, pntr_vector* points, int numPoints, int thickness, pntr_color color); PNTR_API void pntr_draw_arc_thick(pntr_image* dst, int centerX, int centerY, float radius, float startAngle, float endAngle, int segments, int thickness, pntr_color color); PNTR_API void pntr_draw_rectangle_thick_rounded(pntr_image* dst, int x, int y, int width, int height, int topLeftRadius, int topRightRadius, int bottomLeftRadius, int bottomRightRadius, int thickness, pntr_color color); PNTR_API void pntr_draw_line_vertical_thick(pntr_image* dst, int posX, int posY, int height, int thickness, pntr_color color); PNTR_API void pntr_draw_line_horizontal_thick(pntr_image* dst, int posX, int posY, int width, int thickness, pntr_color color); PNTR_API void pntr_draw_line_curve_thick(pntr_image* dst, pntr_vector point1, pntr_vector point2, pntr_vector point3, pntr_vector point4, int segments, int thickness, pntr_color color);
// Internal PNTR_API void pntr_put_horizontal_line_unsafe(pntr_image* dst, int posX, int posY, int width, pntr_color color); PNTR_API void pntr_draw_point_unsafe(pntr_image* dst, int x, int y, pntr_color color);
#ifdef __cplusplus } #endif
/**
/
#ifndef PNTR_LIGHTGRAY /** Light gray. / #define PNTR_LIGHTGRAY pntr_new_color(200, 200, 200, 255) #endif #ifndef PNTR_GRAY /** Gray. / #define PNTR_GRAY pntr_new_color(130, 130, 130, 255) #endif #ifndef PNTR_DARKGRAY /** Dark gray. / #define PNTR_DARKGRAY pntr_new_color(80, 80, 80, 255) #endif #ifndef PNTR_YELLOW /** Yellow. / #define PNTR_YELLOW pntr_new_color(253, 249, 0, 255) #endif #ifndef PNTR_GOLD /** Gold. / #define PNTR_GOLD pntr_new_color(255, 203, 0, 255) #endif #ifndef PNTR_ORANGE /** Orange. / #define PNTR_ORANGE pntr_new_color(255, 161, 0, 255) #endif #ifndef PNTR_PINK /** Pink. / #define PNTR_PINK pntr_new_color(255, 109, 194, 255) #endif #ifndef PNTR_RED /** Red. / #define PNTR_RED pntr_new_color(230, 41, 55, 255) #endif #ifndef PNTR_MAROON /** Maroon. / #define PNTR_MAROON pntr_new_color(190, 33, 55, 255) #endif #ifndef PNTR_GREEN /** Green. / #define PNTR_GREEN pntr_new_color(0, 228, 48, 255) #endif #ifndef PNTR_LIME /** Lime. / #define PNTR_LIME pntr_new_color(0, 158, 47, 255) #endif #ifndef PNTR_DARKGREEN /** Dark green. / #define PNTR_DARKGREEN pntr_new_color(0, 117, 44, 255) #endif #ifndef PNTR_SKYBLUE /** Sky blue. / #define PNTR_SKYBLUE pntr_new_color(102, 191, 255, 255) #endif #ifndef PNTR_BLUE /** Blue. / #define PNTR_BLUE pntr_new_color(0, 121, 241, 255) #endif #ifndef PNTR_DARKBLUE /** Dark blue. / #define PNTR_DARKBLUE pntr_new_color(0, 82, 172, 255) #endif #ifndef PNTR_PURPLE /** Purple. / #define PNTR_PURPLE pntr_new_color(200, 122, 255, 255) #endif #ifndef PNTR_VIOLET /** Violet. / #define PNTR_VIOLET pntr_new_color(135, 60, 190, 255) #endif #ifndef PNTR_DARKPURPLE /** Dark purple. / #define PNTR_DARKPURPLE pntr_new_color(112, 31, 126, 255) #endif #ifndef PNTR_BEIGE /** Beige. / #define PNTR_BEIGE pntr_new_color(211, 176, 131, 255) #endif #ifndef PNTR_BROWN /** Brown. / #define PNTR_BROWN pntr_new_color(127, 106, 79, 255) #endif #ifndef PNTR_DARKBROWN /** Dark brown. / #define PNTR_DARKBROWN pntr_new_color(76, 63, 47, 255) #endif #ifndef PNTR_WHITE /** White. / #define PNTR_WHITE pntr_new_color(255, 255, 255, 255) #endif
#ifndef PNTR_WHITE_VALUE /** The integer representation of PNTR_WHITE.
PNTR_WHITE.value . | #define PNTR_CEILF | ( | x | ) | _pntr_ceilf(x) |
Computes the smallest integer value not less than arg.
| x | Floating-point value |
| #define PNTR_COSF | ( | value | ) | _pntr_cosf(value) |
Calculates cosine of the given value.
| value | Floating-point value representing angle in radians |
| #define PNTR_FABSF | ( | x | ) | (((x) < 0) ? -(x) : (x)) |
Computes the absolute value of a floating point value.
| x | Floating point value |
| #define PNTR_FLOORF | ( | x | ) | (float)(((int)(x)) - (((x) < 0.0f) ? 1 : 0)) |
Computes the largest integer value not greater than arg.
| x | Floating point value. |
| #define PNTR_FMODF | ( | dividend, | |
| divisor | |||
| ) | ((divisor) == 0.0f ? 0.0f : (dividend) - ((int)((dividend) / (divisor))) * (divisor)) |
Computes the floating-point remainder of the division operation x/y.
| dividend | floating point value |
| divisor | floating point value |
| #define PNTR_MAX | ( | a, | |
| b | |||
| ) | ((a) > (b) ? (a) : (b)) |
Return the largest value of the two given values.
| a | The first value to compare. |
| b | The second value to compare. |
| #define PNTR_MIN | ( | a, | |
| b | |||
| ) | ((a) < (b) ? (a) : (b)) |
Return the smallest value of the two given values.
| a | The first value to compare. |
| b | The second value to compare. |
| #define PNTR_SINF | ( | value | ) | _pntr_sinf(value) |
Calculates sine of the given value in radians.
| value | The input value of sinf() |