libSDL2_gfxutils

Introduction

libSDL2_gfxutils is a C and C++ compatible library complementary to the SDL2_gfx library and so to the SDL2 library.

libSDL2_gfxutils is issued from a collection of functions that i implemented over the years,

everytime i get i new idea i implement it right away...

I began to implement the function in the python language with the pygame python module which is actually based on the SDL library.


libSDL2_gfxutils is a translation of python functions into the C language and with the respect of the SDL2_gfx standard and newly C++ compatible.

library:SDL2_gfxutils
version:2.0.0
platform:Linux, Windows and Posix compliant (not tested).
compiler:gcc, g++, clang, mingw32, mingw-w64-686, mingw-w64-x86_64.
synopsis:SDL2_gfxutils a SDL2_gfx forms generating and manipulating helper functions set.
Licence:GPLv3.
author:Eddie Brüggemann mrcyberfighter@gmail.com

Screenshots of usage examples from the libSDL2_gfxutils library:


Description:

libSDL2_gfxutils is at first a panoply of diverse forms generating functions, from differents types merge to a generic type compatible with all displaying functions and forms transforming or animating functions.

libSDL2_gfxutils implements its own datatypes compatible easily compatible with the required SDL2_gfx displaying standard.

In short: libSDL2_gfxutils can generate forms with his high-level forms generating functions, transforming or animating it, and use the SDL2_gfx library to display it.

But you can use the low-level, forms generating functions, from the libSDL2_gfxutils library, for generating and animating your own defined forms.

And finally it's very easy to implement a self-builded displaying function for your own requirement.


libSDL2_gfxutils provide first many different forms generating functions.


libSDL2_gfxutils provides forms displaying functions.


libSDL2_gfxutils provides forms transformations functions:


You can dig deeper into the libSDL2_gfxutils, with his very basics, base functions.

To get the basic tools to create as far as your brain can imagined forms.

if you get familiar with the libSDL2_gfxutils library.


libSDL2_gfxutils provides some measurement functions:

And calculation functions:


I invite you to discover the documentation of libSDL2_gfxutils to sea what all libSDL2_gfxutils can do for you.


NOTE: Compatibility with others libraries than SDL2:

The only purpose of the SDL2_gfx library is the form displaying functionality.

So I think it’s possible to adapt easily SDL2_gfxutils to be reusable with others libraries.

You only have to implement the displaying functions adapted to the target library.

If the coordinates arrays from type float does it for the target library, because

it’s easy to round and cast the float in the target type, like this:

int x = (int) roundf(form->coords.x[c]) ;
int y = (int) roundf(form->coords.y[c]) ;

Else the colors are coded on uint8_t values.

And the other members from the Form structure are used for computing.

Thanks to notify me at mrcyberfighter@gmail.com if you want to do so.

And think about forking the github repository from SDL2_gfxutils then.

SDL2_gfxutils preview

libSDL2_gfxutils Datatypes


typedef struct Color_ {
  uint8_t r ;
  uint8_t g ;
  uint8_t b ;
  uint8_t a ;
} Color ;


typedef struct Pixel_ {
  float x ;
  float y ;
} Pixel ;

typedef struct Segment_ {
  Pixel xy1   ;
  Pixel xy2   ;
  Color color ;
} Line ;

typedef struct Coords_ {
  float *x ;
  float *y ;
} Coords ;

typedef struct Polygon_ {
  Coords         coords      ;
  Pixel          center      ;
  Color          color       ;
  uint16_t       count       ;
  float          length      ;
  float          real_length ;
  float          orientation ;
} Polygon ;

typedef Polygon Arc          ;
typedef Polygon Hexagram     ;
typedef Polygon Pentagram    ;
typedef Polygon Star         ;
typedef Polygon Spiral       ;


typedef Polygon         Form ;
typedef Arc             Form ;
typedef Hexagram        Form ;
typedef Pentagram       Form ;
typedef Spiral          Form ;
typedef Star            Form ;


Forms generating functions:

Polygons


Polygon *generate_polygon_radius(uint32_t sides, float radius, Pixel center, float orientation) ;

Polygon *generate_corners_rounded_polygon(uint32_t sides, float radius, Pixel center, float orientation) ;

Polygon *generate_sides_rounded_polygon(uint32_t sides, float radius, Pixel center, float orientation) ;

Polygon *generate_rounded_inside_out_polygon(uint32_t sides, float radius, Pixel center, float orientation) ;

Polygon *generate_alternate_inside_half_circle_polygon(uint32_t sides, float radius, Pixel center, float orientation, bool side_arcs) ;

Polygon *generate_alternate_outside_half_circle_polygon(uint32_t sides, float radius, Pixel center, float orientation, bool side_arcs) ;


Polygons images gallery
Polygon normal Polygon strikethrough Polygon filled
A polygon generated with libsdl2_gfxutils normal displayed A polygon generated with libsdl2_gfxutils strikethrough displayed A polygon generated with libsdl2_gfxutils filled displayed
Corners rounded polygon normal Corners rounded polygon strikethrough Corners rounded polygon filled
A corners rounded polygon generated with libsdl2_gfxutils normal displayed A corners rounded polygon strikethrough displayed A corners rounded polygon generated with libsdl2_gfxutils filled displayed
Sides rounded polygon normal Sides rounded polygon strikethrough Sides rounded polygon filled
A sides rounded polygon generated with libsdl2_gfxutils normal displayed A sides rounded polygon strikethrough displayed A sides rounded polygon generated with libsdl2_gfxutils filled displayed
Rounded inside out polygon normal Rounded inside out polygon strikethrough Rounded inside out polygon filled
A rounded inside out polygon normal displayed A rounded inside out polygon strikethrough displayed A rounded inside out polygon filled displayed
Alternate inside half circle polygon normal Alternate inside half circle polygon strikethrough Alternate inside half circle polygon filled
An alternate inside half circle polygon normal displayed An alternate inside half circle polygon strikethrough displayed An alternate inside half circle polygon filled displayed
Alternate outside half circle polygon normal Alternate outside half circle polygon strikethrough Alternate outside half circle polygon filled
An alternate outside half circle polygon normal displayed An alternate outside half circle polygon strikethrough displayed An alternate outside half circle polygon filled displayed


Stars


Star *generate_star(uint32_t pikes,float radius,Pixel center,float orientation) ;

Star *generate_pentagram_star(float radius, Pixel center, float orientation) ;

Star *generate_hexagram_star(float radius, Pixel center, float orientation) ;


Stars images gallery
Star normal Star strikethrough Star flower
A star generated with libsdl2_gfxutils normal displayed A star generated with libsdl2_gfxutils strikethrough displayed A star generated with libsdl2_gfxutils flower displayed
Pentagram star normal Pentagram star strikethrough Pentagram star flower
A pentagram star generated with libsdl2_gfxutils normal displayed A pentagram star generated with libsdl2_gfxutils strikethrough displayed A pentagram star generated with libsdl2_gfxutils flower displayed
Hexagram star normal Hexagram star strikethrough Hexagram star flower
A hexagram star generated with libsdl2_gfxutils normal displayed A hexagram star generated with libsdl2_gfxutils strikethrough displayed A hexagram star generated with libsdl2_gfxutils flower displayed


Wheels


Polygon *generate_wheel(uint32_t polygon, Pixel center, float radius, float offset, float orientation) ;

Polygon *generate_circular_saw_wheel(uint32_t polygon, float radius, Pixel center, float offset, float orientation, bool reverse) ;

Polygon *generate_wheel_peaks_trigon(uint32_t sides,float radius, Pixel center, float peak_offset, float orientation) ;

Polygon *generate_wheel_peaks_rounded_square(uint32_t sides, float radius, Pixel center, float peak_length, float orientation) ;


Wheels images gallery
Wheel normal Wheel strikethrough Wheel filled
A wheel generated with libsdl2_gfxutils normal displayed A wheel generated with libsdl2_gfxutils strikethrough displayed A wheel generated with libsdl2_gfxutils filled displayed
Circular saw wheel normal Circular saw wheel strikethrough Circular saw wheel filled
A circular saw wheel generated with libsdl2_gfxutils normal displayed A circular saw wheel strikethrough displayed A circular saw wheel generated with libsdl2_gfxutilsfilled displayed
Wheel peaks trigon normal Wheel peaks trigon strikethrough Wheel peaks trigon filled
A wheel peaks trigon normal displayed A wheel peaks trigon strikethrough displayed A wheel peaks trigon filled displayed
Wheel peaks rounded square normal Wheel peaks rounded square strikethrough Wheel peaks rounded square filled
A wheel peaks rounded_square normal displayed A wheel peaks rounded square strikethrough displayed A wheel peaks rounded square filled displayed


Fractals


Polygon *generate_fractal(uint32_t polygon, float radius, Pixel center, float orientation, bool complex) ;


Fractals images gallery
Fractals normal Fractals strikethrough Fractals filled
A fractal generated with libsdl2_gfxutils normal displayed A fractal generated with libsdl2_gfxutils strikethrough displayed A fractal generated with libsdl2_gfxutils filled displayed


Others


Spiral *generate_simple_spiral(Pixel center, uint32_t turns, uint32_t base, float offset_exponent, float orientation,  bool reverse) ;

Pentagram *generate_pentagram(float radius, Pixel center, float orientation) ;

Star *generate_hexagram_star(float radius, Pixel center, float orientation) ;

Arc *generate_circle_arc(float radius, Pixel center, float start_pos, float circle_part) ;

Line *generate_segment(Pixel start_point, float length, float angle) ;


Others forms images gallery
Spiral normal Pentagram normal Hexagram normal
A spiral generated with libsdl2_gfxutils normal displayed A pentagram generated with libsdl2_gfxutils normal displayed A hexagram generated with libsdl2_gfxutils normal displayed
Arcs Lines
Arcs generated with libsdl2_gfxutils normal displayed Lines generated with libsdl2_gfxutils normal displayed


Forms transforming or animating functions

High-level Forms transformations functions:


void rotate_form(Form *form, float angle) ;

void mirror_form(Form *form, Pixel center, char axes) ;

void scale_form(Form *form, float factor) ;

void translate_form(Form *form, float x, float y) ;

Form *remove_doubles_form(Form *form) ;

Low-level Forms transformations functions:


Pixel rotate(Pixel center, float angle, Pixel pixel) ;

Pixel mirror(Pixel pixel, Pixel center, char axes) ;

Pixel scale(Pixel center, float factor, Pixel pixel) ;

Pixel translate(Pixel pixel, float x, float y) ;



Forms displaying functions:

Normal displaying functions:


int display_line(SDL_Renderer *pRenderer, Line *line) ;

int display_arc(SDL_Renderer *pRenderer, Arc *arc) ;


int display_polygon(SDL_Renderer *pRenderer, Form *polygon) ;

int display_strikethrough_polygon(SDL_Renderer *pRenderer, Form *polygon) ;

int display_filled_polygon(SDL_Renderer *pRenderer, Form *polygon) ;


int display_pentagram(SDL_Renderer *pRenderer, Pentagram *pentagram) ;

int display_hexagram(SDL_Renderer *pRenderer, Pentagram *hexagram)  ;


int display_star(SDL_Renderer *pRenderer, Star *star) ;

int display_flower_star(SDL_Renderer *pRenderer, Star *star) ;

int display_strikethrough_star(SDL_Renderer *pRenderer, Star *star_striketrough) ;

int display_polygon_star(SDL_Renderer *pRenderer, Star *star) ;

int display_filled_star(SDL_Renderer *pRenderer, Star *star) ;


int display_spiral(SDL_Renderer *pRenderer, Spiral *spiral) ;

Anti-aliasing displaying functions:


int aa_display_line(SDL_Renderer *pRenderer, Line *line) ;

int aa_display_arc(SDL_Renderer *pRenderer, Arc *arc) ;


int aa_display_polygon(SDL_Renderer *pRenderer, Form *polygon) ;

int aa_display_strikethrough_polygon(SDL_Renderer *pRenderer, Form *polygon) ;


int aa_display_pentagram(SDL_Renderer *pRenderer, Pentagram *pentagram) ;

int aa_display_hexagram(SDL_Renderer *pRenderer, Pentagram *hexagram)  ;


int aa_display_star(SDL_Renderer *pRenderer, Star *star) ;

int aa_display_flower_star(SDL_Renderer *pRenderer, Star *star) ;

int aa_display_strikethrough_star(SDL_Renderer *pRenderer, Star *star) ;

int aa_display_polygon_star(SDL_Renderer *pRenderer, Star *star) ;


int aa_display_spiral(SDL_Renderer *pRenderer, Spiral *spiral) ;

Thickness settable displaying functions:


int display_line_thick(SDL_Renderer *pRenderer, Line *line, uint8_t thickness) ;

int display_arc_thick(SDL_Renderer *pRenderer, Arc *arc, uint8_t thickness) ;


int display_polygon_thick(SDL_Renderer *pRenderer, Form *polygon, uint8_t thickness) ;

int display_strikethrough_polygon_thick(SDL_Renderer *pRenderer, Form *polygon, uint8_t thickness) ;


int display_pentagram_thick(SDL_Renderer *pRenderer, Pentagram *pentagram, uint8_t thickness) ;

int display_hexagram_thick(SDL_Renderer *pRenderer, Pentagram *hexagram, uint8_t thickness)  ;


int display_star_thick(SDL_Renderer *pRenderer, Star *star, uint8_t thickness) ;

int display_flower_star_thick(SDL_Renderer *pRenderer, Star *star, uint8_t thickness) ;

int display_strikethrough_star_thick(SDL_Renderer *pRenderer, Star *star_striketrough, uint8_t thickness) ;

int display_polygon_star_thick(SDL_Renderer *pRenderer, Star *star, uint8_t thickness) ;


int display_spiral_thick(SDL_Renderer *pRenderer, Spiral *spiral, uint8_t thickness) ;


Getters and setters functions:

Setters functions:


void set_form_center(Form *form, Pixel center, bool translate) ;

void set_form_radius(Form *form, float radius) ;

void set_form_color(Form *form, uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) ;

void set_line_color(Line *line, uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) ;

Getters functions:


Pixel get_form_center(Form *form) ;

Color get_form_color(Form *form) ;

float get_form_length(Form *form) ;

float get_form_real_length(Form *form) ;

float get_form_orientation(Form *form) ;


Base functions:

Measurement functions


float get_angle(int position, float scale, float orientation) ;

float get_distance_pixels(Pixel px1, Pixel px2) ;

Calculation functions


Pixel get_middle_from_line(Line line) ;

void compute_trajectory(Pixel positions[], Line trajectory, uint32_t steps) ;



Documentation:

You can access to the documentation of the libSDL2_gfxutils library project online or download the documentation:

Online documentation:

ReadTheDoc online documentation:


Download documentation:


SDL2_gfxutils header files:


Usage examples:



Files and useful links:


libSDL2_gfxutils is distributed as archive files for following compilers: gcc, g++, clang, mingw32, mingw-w64-686, mingw-w64-x86_64.


Available archive files from the libSDL2_gfxutils project.

To install on POSIX compliant systems simply type:
$ ./configure
$ make
$ sudo make install
For mingw32, mingw-w64-686, mingw-w64-x86_64:

Simply copy the static inclusion library and the *.dll files where you need.

github repository:

Credits

Author: Eddie Brüggemann.
Contact: mrcyberfighter@gmail.com
License: GPLv3.
Thank's to my beloved mother, my family and to the doctors.
Stay away from drugs: drugs destroy your brain and your life.