FB Graphics
FBGraphics (FBG) : Simple C 16, 24, 32 bpp generic graphics library with parallelism support and custom backend.
Data Structures | Macros | Functions
fbgraphics.h File Reference
#include <time.h>
#include <sys/time.h>
#include <stdint.h>
#include <math.h>

Go to the source code of this file.

Data Structures

struct  _fbg_rgb
 RGBA color data structure. More...
 
struct  _fbg_hsl
 HSL color data structure. More...
 
struct  _fbg_img
 Image data structure. More...
 
struct  _fbg_font
 Bitmap font data structure. More...
 
struct  _fbg
 FB Graphics context data structure. More...
 

Macros

#define fbg_fade(fbg, fade_amount)   fbg_fadeDown(fbg, fade_amount)
 background fade to black with controllable factor More...
 
#define fbg_write(fbg, text, x, y)   fbg_text(fbg, &fbg->current_font, text, x, y, fbg->text_color.r, fbg->text_color.g, fbg->text_color.b)
 draw a text by using the current font and the current color More...
 
#define fbg_imageScale(fbg, img, x, y, sx, sy)   fbg_imageEx(fbg, img, x, y, sx, sy, 0, 0, img->width, img->height)
 draw a scaled image (Nearest-neighbor algorithm) More...
 
#define _FBG_MAX(a, b)   ((a) > (b) ? a : b)
 integer MAX Math function More...
 
#define _FBG_MIN(a, b)   ((a) < (b) ? a : b)
 integer MIN Math function More...
 
#define _FBG_SGN(x)   ((x<0)?-1:((x>0)?1:0))
 integer SIGN function More...
 
#define _FBG_DEGTORAD(angle_degree)   ((angle_degree) * M_PI / 180.0)
 convert a degree angle to radians More...
 
#define _FBG_RADTODEG(angle_radians)   ((angle_radians) * 180.0 / M_PI)
 convert a radian angle to degree More...
 
#define _FBG_SOURCE_OVER(a, b, c)   (c * a + b * (1.f - a))
 

Functions

struct _fbgfbg_customSetup (int width, int height, int components, int initialize_buffers, int allow_resizing, void *user_context, void(*user_draw)(struct _fbg *fbg), void(*user_flip)(struct _fbg *fbg), void(*backend_resize)(struct _fbg *fbg, unsigned int new_width, unsigned int new_height), void(*user_free)(struct _fbg *fbg))
 initialize a FB Graphics context (typically used by a custom rendering backend) More...
 
void fbg_close (struct _fbg *fbg)
 free up the memory associated with a FB Graphics context and close the framebuffer device More...
 
void fbg_setResizeCallback (struct _fbg *fbg, void(*user_resize)(struct _fbg *fbg, unsigned int new_width, unsigned int new_height))
 register a user resize callback More...
 
void fbg_resize (struct _fbg *fbg, int new_width, int new_height)
 
void fbg_pushResize (struct _fbg *fbg, int new_width, int new_height)
 
void fbg_fadeDown (struct _fbg *fbg, unsigned char rgb_fade_amount)
 background fade to black with controllable factor More...
 
void fbg_fadeUp (struct _fbg *fbg, unsigned char rgb_fade_amount)
 background fade to white with controllable factor More...
 
void fbg_clear (struct _fbg *fbg, unsigned char brightness)
 fast grayscale background clearing More...
 
void fbg_fill (struct _fbg *fbg, unsigned char r, unsigned char g, unsigned char b)
 set the filling color for fast drawing operations More...
 
void fbg_getPixel (struct _fbg *fbg, int x, int y, struct _fbg_rgb *color)
 get the RGB value of a pixel More...
 
void fbg_pixel (struct _fbg *fbg, int x, int y, unsigned char r, unsigned char g, unsigned char b)
 draw a pixel More...
 
void fbg_pixela (struct _fbg *fbg, int x, int y, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
 draw a pixel with alpha component (alpha blending) More...
 
void fbg_fpixel (struct _fbg *fbg, int x, int y)
 fast pixel drawing which use the fill color set by fbg_fill() More...
 
void fbg_plot (struct _fbg *fbg, int index, unsigned char value)
 direct pixel access from index value More...
 
void fbg_rect (struct _fbg *fbg, int x, int y, int w, int h, unsigned char r, unsigned char g, unsigned char b)
 draw a rectangle More...
 
void fbg_recta (struct _fbg *fbg, int x, int y, int w, int h, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
 draw a rectangle with alpha transparency More...
 
void fbg_frect (struct _fbg *fbg, int x, int y, int w, int h)
 fast rectangle drawing which use the fill color set by fbg_fill() More...
 
void fbg_hline (struct _fbg *fbg, int x, int y, int w, unsigned char r, unsigned char g, unsigned char b)
 draw a horizontal line More...
 
void fbg_vline (struct _fbg *fbg, int x, int y, int h, unsigned char r, unsigned char g, unsigned char b)
 draw a vertical line More...
 
void fbg_line (struct _fbg *fbg, int x1, int y1, int x2, int y2, unsigned char r, unsigned char g, unsigned char b)
 draw a line from two points (Bresenham algorithm) More...
 
void fbg_polygon (struct _fbg *fbg, int num_vertices, int *vertices, unsigned char r, unsigned char g, unsigned char b)
 draw a polygon More...
 
void fbg_background (struct _fbg *fbg, unsigned char r, unsigned char g, unsigned char b)
 clear the background with a color More...
 
void fbg_hslToRGB (struct _fbg_rgb *color, float h, float s, float l)
 convert HSL values to RGB color More...
 
void fbg_rgbToHsl (struct _fbg_hsl *color, float r, float g, float b)
 convert RGB values to HSL color More...
 
void fbg_draw (struct _fbg *fbg)
 draw to the screen More...
 
void fbg_flip (struct _fbg *fbg)
 flip the buffers More...
 
struct _fbg_imgfbg_createImage (struct _fbg *fbg, unsigned int width, unsigned int height)
 create an empty image More...
 
struct _fbg_imgfbg_loadPNG (struct _fbg *fbg, const char *filename)
 load a PNG image from a file (lodePNG library) More...
 
struct _fbg_imgfbg_loadJPEG (struct _fbg *fbg, const char *filename)
 load a JPEG image from a file (NanoJPEG library) More...
 
struct _fbg_imgfbg_loadImage (struct _fbg *fbg, const char *filename)
 load an image (PNG or JPEG) More...
 
void fbg_image (struct _fbg *fbg, struct _fbg_img *img, int x, int y)
 draw an image More...
 
void fbg_imageColorkey (struct _fbg *fbg, struct _fbg_img *img, int x, int y, int cr, int cg, int cb)
 draw an image with colorkeying support (image colorkey value will be ignored) More...
 
void fbg_imageClip (struct _fbg *fbg, struct _fbg_img *img, int x, int y, int cx, int cy, int cw, int ch)
 draw a clipped image More...
 
void fbg_imageFlip (struct _fbg_img *img)
 flip an image vertically More...
 
void fbg_imageEx (struct _fbg *fbg, struct _fbg_img *img, int x, int y, float sx, float sy, int cx, int cy, int cw, int ch)
 draw an image with support for clipping and scaling (Nearest-neighbor algorithm) More...
 
void fbg_freeImage (struct _fbg_img *img)
 free the memory associated with an image More...
 
struct _fbg_fontfbg_createFont (struct _fbg *fbg, struct _fbg_img *img, int glyph_width, int glyph_height, unsigned char first_char)
 create a bitmap font from an image More...
 
void fbg_textFont (struct _fbg *fbg, struct _fbg_font *font)
 set the current font More...
 
void fbg_textColor (struct _fbg *fbg, unsigned char r, unsigned char g, unsigned char b)
 set the current text color More...
 
void fbg_textBackground (struct _fbg *fbg, int r, int g, int b, int a)
 set the current text background color (based on colorkey value!) More...
 
void fbg_textColorKey (struct _fbg *fbg, unsigned char v)
 set the current text color key More...
 
void fbg_text (struct _fbg *fbg, struct _fbg_font *fnt, char *text, int x, int y, int r, int g, int b)
 draw a text More...
 
void fbg_freeFont (struct _fbg_font *font)
 free the memory associated with a font More...
 
void fbg_drawFramerate (struct _fbg *fbg, struct _fbg_font *fnt, int task, int x, int y, int r, int g, int b)
 draw the framerate of a particular parallel task More...
 
int fbg_getFramerate (struct _fbg *fbg, int task)
 get the framerate of a particular task More...
 
void fbg_drawInto (struct _fbg *fbg, unsigned char *buffer)
 set an offscreen target for all subsequent fbg context draw calls, it is important to reset back to display target once done by calling fbg_drawInto(NULL) otherwise you may have segfaults / memory leaks upon resizing and other actions More...
 
float fbg_randf (float min, float max)
 pseudo random number between min / max More...
 

Data Structure Documentation

◆ _fbg_rgb

struct _fbg_rgb

RGBA color data structure.

Hold RGBA components [0,255]

Definition at line 74 of file fbgraphics.h.

Data Fields
unsigned char a
unsigned char b
unsigned char g
unsigned char r

◆ _fbg_hsl

struct _fbg_hsl

HSL color data structure.

Hold HSL components S/L [0,1], HUE [0, 360]

Definition at line 83 of file fbgraphics.h.

Data Fields
int h
float l
float s

◆ _fbg_img

struct _fbg_img

Image data structure.

Hold images informations and data

Definition at line 91 of file fbgraphics.h.

Data Fields
unsigned char * data RGB image data (bpp depend on framebuffer settings)
unsigned int height Image height in pixels.
unsigned int width Image width in pixels.

◆ _fbg_font

struct _fbg_font

Bitmap font data structure.

Hold bitmap font informations and associated image

Definition at line 103 of file fbgraphics.h.

Data Fields
struct _fbg_img * bitmap Associated font image data structure.
unsigned char first_char First ASCII character of the bitmap font file.
int * glyph_coord_x Pre-computed X glyphs coordinates.
int * glyph_coord_y Pre-computed Y glyphs coordinates.
int glyph_height Height of a glyph.
int glyph_width Width of a glyph.

Macro Definition Documentation

◆ _FBG_DEGTORAD

#define _FBG_DEGTORAD (   angle_degree)    ((angle_degree) * M_PI / 180.0)

convert a degree angle to radians

Definition at line 851 of file fbgraphics.h.

◆ _FBG_MAX

#define _FBG_MAX (   a,
 
)    ((a) > (b) ? a : b)

integer MAX Math function

Definition at line 844 of file fbgraphics.h.

◆ _FBG_MIN

#define _FBG_MIN (   a,
 
)    ((a) < (b) ? a : b)

integer MIN Math function

Definition at line 846 of file fbgraphics.h.

◆ _FBG_RADTODEG

#define _FBG_RADTODEG (   angle_radians)    ((angle_radians) * 180.0 / M_PI)

convert a radian angle to degree

Definition at line 853 of file fbgraphics.h.

◆ _FBG_SGN

#define _FBG_SGN (   x)    ((x<0)?-1:((x>0)?1:0))

integer SIGN function

Definition at line 848 of file fbgraphics.h.

◆ _FBG_SOURCE_OVER

#define _FBG_SOURCE_OVER (   a,
  b,
 
)    (c * a + b * (1.f - a))

Definition at line 855 of file fbgraphics.h.

◆ fbg_fade

#define fbg_fade (   fbg,
  fade_amount 
)    fbg_fadeDown(fbg, fade_amount)

background fade to black with controllable factor

Parameters
fbgpointer to a FBG context / data structure
fade_amountfade amount
See also
fbg_fadeUp(), fbg_fadeDown()

Definition at line 819 of file fbgraphics.h.

◆ fbg_imageScale

#define fbg_imageScale (   fbg,
  img,
  x,
  y,
  sx,
  sy 
)    fbg_imageEx(fbg, img, x, y, sx, sy, 0, 0, img->width, img->height)

draw a scaled image (Nearest-neighbor algorithm)

Parameters
fbgpointer to a FBG context / data structure
imgimage structure pointer
ximage X position (upper left coordinate)
yimage Y position (upper left coordinate)
sxThe X scale factor
syThe Y scale factor
See also
fbg_createImage(), fbg_loadPNG(), fbg_loadJPEG(), fbg_loadImage(), fbg_imageClip(), fbg_freeImage(), fbg_image(), fbg_imageFlip(), fbg_imageEx()

Definition at line 841 of file fbgraphics.h.

◆ fbg_write

#define fbg_write (   fbg,
  text,
  x,
 
)    fbg_text(fbg, &fbg->current_font, text, x, y, fbg->text_color.r, fbg->text_color.g, fbg->text_color.b)

draw a text by using the current font and the current color

Parameters
fbgpointer to a FBG context / data structure
textthe text to draw ('
' and ' ' are treated automatically)
x
y
See also
fbg_textFont(), fbg_textColor(), fbg_text(), fbg_textColorkey(), fbg_textBackground()

Definition at line 829 of file fbgraphics.h.

Function Documentation

◆ fbg_background()

void fbg_background ( struct _fbg fbg,
unsigned char  r,
unsigned char  g,
unsigned char  b 
)

clear the background with a color

Parameters
fbgpointer to a FBG context / data structure
r
g
b
See also
fbg_clear()

◆ fbg_clear()

void fbg_clear ( struct _fbg fbg,
unsigned char  brightness 
)

fast grayscale background clearing

Parameters
fbgpointer to a FBG context / data structure
brightnesspixel brightness (grayscale)
See also
fbg_background()

◆ fbg_close()

void fbg_close ( struct _fbg fbg)

free up the memory associated with a FB Graphics context and close the framebuffer device

Parameters
fbgpointer to a FBG context / data structure
See also
fbg_customSetup()

◆ fbg_createFont()

struct _fbg_font* fbg_createFont ( struct _fbg fbg,
struct _fbg_img img,
int  glyph_width,
int  glyph_height,
unsigned char  first_char 
)

create a bitmap font from an image

Parameters
fbgpointer to a FBG context / data structure
imgimage structure pointer
glyph_widthglyph / character width
glyph_heightglyph / character height
first_charthe first character of the bitmap font
Returns
_fbg_font structure pointer
See also
fbg_freeFont(), fbg_textFont(), fbg_text(), fbg_write(), fbg_drawFramerate()

◆ fbg_createImage()

struct _fbg_img* fbg_createImage ( struct _fbg fbg,
unsigned int  width,
unsigned int  height 
)

create an empty image

Parameters
fbgpointer to a FBG context / data structure
widthimage width
heightimage height
Returns
_fbg_img data structure pointer
See also
fbg_freeImage(), fbg_image(), fbg_imageFlip(), fbg_createFont()

◆ fbg_customSetup()

struct _fbg* fbg_customSetup ( int  width,
int  height,
int  components,
int  initialize_buffers,
int  allow_resizing,
void *  user_context,
void(*)(struct _fbg *fbg)  user_draw,
void(*)(struct _fbg *fbg)  user_flip,
void(*)(struct _fbg *fbg, unsigned int new_width, unsigned int new_height)  backend_resize,
void(*)(struct _fbg *fbg)  user_free 
)

initialize a FB Graphics context (typically used by a custom rendering backend)

Parameters
widthrender width
heightrender height
componentsimage components (3 = RGB, 4 = RGBA etc.)
initialize_bufferswether internal buffers should be allocated / freed
allow_resizingwether to allow internal context resize (any registered callbacks will still be called)
user_contextuser rendering data storage (things like window context etc.)
user_drawfunction to call upon fbg_draw()
user_flipfunction to call upon fbg_flip()
backend_resizefunction to call upon fbg_resize()
user_freefunction to call upon fbg_close()
Returns
_fbg structure pointer to pass to any FBG library functions
See also
fbg_close()

◆ fbg_draw()

void fbg_draw ( struct _fbg fbg)

draw to the screen

Parameters
fbgpointer to a FBG context / data structure

◆ fbg_drawFramerate()

void fbg_drawFramerate ( struct _fbg fbg,
struct _fbg_font fnt,
int  task,
int  x,
int  y,
int  r,
int  g,
int  b 
)

draw the framerate of a particular parallel task

Parameters
fbgpointer to a FBG context / data structure
fnt_fbg_font structure pointer
taskthe task id
x
y
r
g
b

◆ fbg_drawInto()

void fbg_drawInto ( struct _fbg fbg,
unsigned char *  buffer 
)

set an offscreen target for all subsequent fbg context draw calls, it is important to reset back to display target once done by calling fbg_drawInto(NULL) otherwise you may have segfaults / memory leaks upon resizing and other actions

Parameters
fbgpointer to a FBG context / data structure
buffera buffer to render to, it should be the format of the display, target is the display if NULL

◆ fbg_fadeDown()

void fbg_fadeDown ( struct _fbg fbg,
unsigned char  rgb_fade_amount 
)

background fade to black with controllable factor

Parameters
fbgpointer to a FBG context / data structure
rgb_fade_amountfade amount
See also
fbg_fade(), fbg_fadeUp()

◆ fbg_fadeUp()

void fbg_fadeUp ( struct _fbg fbg,
unsigned char  rgb_fade_amount 
)

background fade to white with controllable factor

Parameters
fbgpointer to a FBG context / data structure
rgb_fade_amountfade amount
See also
fbg_fadeDown()

◆ fbg_fill()

void fbg_fill ( struct _fbg fbg,
unsigned char  r,
unsigned char  g,
unsigned char  b 
)

set the filling color for fast drawing operations

Parameters
fbgpointer to a FBG context / data structure
r
g
b
See also
fbg_fpixel(), fbg_frect()

◆ fbg_flip()

void fbg_flip ( struct _fbg fbg)

flip the buffers

Parameters
fbgpointer to a FBG context / data structure

◆ fbg_fpixel()

void fbg_fpixel ( struct _fbg fbg,
int  x,
int  y 
)

fast pixel drawing which use the fill color set by fbg_fill()

Parameters
fbgpointer to a FBG context / data structure
xpixel X position (upper left coordinate)
ypixel Y position (upper left coordinate)
See also
fbg_pixel(), fbg_fill(), fbg_pixela()

◆ fbg_frect()

void fbg_frect ( struct _fbg fbg,
int  x,
int  y,
int  w,
int  h 
)

fast rectangle drawing which use the fill color set by fbg_fill()

Parameters
fbgpointer to a FBG context / data structure
xrectangle X position (upper left coordinate)
yrectangle Y position (upper left coordinate)
wrectangle width
hrectangle height
See also
fbg_fill, fbg_rect(), fbg_recta()

◆ fbg_freeFont()

void fbg_freeFont ( struct _fbg_font font)

free the memory associated with a font

Parameters
font_fbg_font structure pointer
See also
fbg_createFont()

◆ fbg_freeImage()

void fbg_freeImage ( struct _fbg_img img)

free the memory associated with an image

Parameters
imgimage structure pointer
See also
fbg_createImage(), fbg_loadPNG(), fbg_loadJPEG(), fbg_loadImage()

◆ fbg_getFramerate()

int fbg_getFramerate ( struct _fbg fbg,
int  task 
)

get the framerate of a particular task

Parameters
fbgpointer to a FBG context / data structure
taskthe task id
Returns
task framerate

◆ fbg_getPixel()

void fbg_getPixel ( struct _fbg fbg,
int  x,
int  y,
struct _fbg_rgb color 
)

get the RGB value of a pixel

Parameters
fbgpointer to a FBG context / data structure
x
y
colora pointer to a _fbg_rgb data structure

◆ fbg_hline()

void fbg_hline ( struct _fbg fbg,
int  x,
int  y,
int  w,
unsigned char  r,
unsigned char  g,
unsigned char  b 
)

draw a horizontal line

Parameters
fbgpointer to a FBG context / data structure
xline X position (upper left coordinate)
yline Y position (upper left coordinate)
wline width
r
g
b
See also
fbg_vline, fbg_line()

◆ fbg_hslToRGB()

void fbg_hslToRGB ( struct _fbg_rgb color,
float  h,
float  s,
float  l 
)

convert HSL values to RGB color

Parameters
colorpointer to a _fbg_rgb data structure
hthe hue
sthe saturation
lthe lightness
See also
rgbToHsl()

◆ fbg_image()

void fbg_image ( struct _fbg fbg,
struct _fbg_img img,
int  x,
int  y 
)

draw an image

Parameters
fbgpointer to a FBG context / data structure
imgimage structure pointer
ximage X position (upper left coordinate)
yimage Y position (upper left coordinate)
See also
fbg_createImage(), fbg_loadPNG(), fbg_loadJPEG(), fbg_loadImage(), fbg_imageClip(), fbg_freeImage(), fbg_imageFlip(), fbg_imageEx(), fbg_imageScale(), fbg_imageColorkey()

◆ fbg_imageClip()

void fbg_imageClip ( struct _fbg fbg,
struct _fbg_img img,
int  x,
int  y,
int  cx,
int  cy,
int  cw,
int  ch 
)

draw a clipped image

Parameters
fbgpointer to a FBG context / data structure
imgimage structure pointer
ximage X position (upper left coordinate)
yimage Y position (upper left coordinate)
cxThe X coordinate where to start clipping
cyThe Y coordinate where to start clipping
cwThe width of the clipped image (from cx)
chThe height of the clipped image (from cy)
See also
fbg_createImage(), fbg_loadPNG(), fbg_loadJPEG(), fbg_loadImage(), fbg_freeImage(), fbg_image(), fbg_imageFlip(), fbg_imageEx(), fbg_imageScale(), fbg_imageColorkey()

◆ fbg_imageColorkey()

void fbg_imageColorkey ( struct _fbg fbg,
struct _fbg_img img,
int  x,
int  y,
int  cr,
int  cg,
int  cb 
)

draw an image with colorkeying support (image colorkey value will be ignored)

Parameters
fbgpointer to a FBG context / data structure
imgimage structure pointer
ximage X position (upper left coordinate)
yimage Y position (upper left coordinate)
crcolorkey red component
cgcolorkey green component
cbcolorkey blue component
See also
fbg_createImage(), fbg_loadPNG(), fbg_loadJPEG(), fbg_loadImage(), fbg_imageClip(), fbg_freeImage(), fbg_imageFlip(), fbg_imageEx(), fbg_imageScale(), fbg_image()

◆ fbg_imageEx()

void fbg_imageEx ( struct _fbg fbg,
struct _fbg_img img,
int  x,
int  y,
float  sx,
float  sy,
int  cx,
int  cy,
int  cw,
int  ch 
)

draw an image with support for clipping and scaling (Nearest-neighbor algorithm)

Parameters
fbgpointer to a FBG context / data structure
imgimage structure pointer
ximage X position (upper left coordinate)
yimage Y position (upper left coordinate)
sxThe X scale factor
syThe Y scale factor
cxThe X coordinate where to start clipping
cyThe Y coordinate where to start clipping
cwThe width of the clipped image (from cx)
chThe height of the clipped image (from cy)
See also
fbg_createImage(), fbg_loadPNG(), fbg_loadJPEG(), fbg_loadImage(), fbg_imageClip(), fbg_freeImage(), fbg_image(), fbg_imageFlip(), fbg_imageScale(), fbg_imageColorkey()

◆ fbg_imageFlip()

void fbg_imageFlip ( struct _fbg_img img)

flip an image vertically

Parameters
imgimage structure pointer
See also
fbg_createImage(), fbg_loadPNG(), fbg_loadJPEG(), fbg_loadImage()

◆ fbg_line()

void fbg_line ( struct _fbg fbg,
int  x1,
int  y1,
int  x2,
int  y2,
unsigned char  r,
unsigned char  g,
unsigned char  b 
)

draw a line from two points (Bresenham algorithm)

Parameters
fbgpointer to a FBG context / data structure
x1point 1 X position (upper left coordinate)
y1point 1 Y position (upper left coordinate)
x2point 2 X position (upper left coordinate)
y2point 2 Y position (upper left coordinate)
r
g
b
See also
fbg_hline(), fbg_vline(), fbg_polygon()

◆ fbg_loadImage()

struct _fbg_img* fbg_loadImage ( struct _fbg fbg,
const char *  filename 
)

load an image (PNG or JPEG)

Parameters
fbgpointer to a FBG context / data structure
filenameJPEG/PNG image filename
Returns
_fbg_img data structure pointer
See also
fbg_freeImage(), fbg_image(), fbg_imageFlip(), fbg_createFont(), fbg_imageClip(), fbg_loadPNG(), fbg_loadJPEG(), fbg_imageEx(), fbg_imageScale(), fbg_imageColorkey()

◆ fbg_loadJPEG()

struct _fbg_img* fbg_loadJPEG ( struct _fbg fbg,
const char *  filename 
)

load a JPEG image from a file (NanoJPEG library)

Parameters
fbgpointer to a FBG context / data structure
filenameJPEG image filename
Returns
_fbg_img data structure pointer
See also
fbg_freeImage(), fbg_image(), fbg_imageFlip(), fbg_createFont(), fbg_imageClip(), fbg_loadPNG(), fbg_loadImage(), fbg_imageEx(), fbg_imageScale(), fbg_imageColorkey()

◆ fbg_loadPNG()

struct _fbg_img* fbg_loadPNG ( struct _fbg fbg,
const char *  filename 
)

load a PNG image from a file (lodePNG library)

Parameters
fbgpointer to a FBG context / data structure
filenamePNG image filename
Returns
_fbg_img data structure pointer
See also
fbg_freeImage(), fbg_image(), fbg_imageFlip(), fbg_createFont(), fbg_imageClip(), fbg_loadJPEG(), fbg_loadImage(), fbg_imageEx(), fbg_imageScale(), fbg_imageColorkey()

◆ fbg_pixel()

void fbg_pixel ( struct _fbg fbg,
int  x,
int  y,
unsigned char  r,
unsigned char  g,
unsigned char  b 
)

draw a pixel

Parameters
fbgpointer to a FBG context / data structure
xpixel X position (upper left coordinate)
ypixel Y position (upper left coordinate)
r
g
b
See also
fbg_fpixel(), fbg_pixela()

◆ fbg_pixela()

void fbg_pixela ( struct _fbg fbg,
int  x,
int  y,
unsigned char  r,
unsigned char  g,
unsigned char  b,
unsigned char  a 
)

draw a pixel with alpha component (alpha blending)

Parameters
fbgpointer to a FBG context / data structure
xpixel X position (upper left coordinate)
ypixel Y position (upper left coordinate)
r
g
b
a
See also
fbg_fpixel(), fbg_pixel()

◆ fbg_plot()

void fbg_plot ( struct _fbg fbg,
int  index,
unsigned char  value 
)

direct pixel access from index value

Parameters
fbgpointer to a FBG context / data structure
indexpixel index in the buffer
valuecolor value
See also
fbg_pixel(), fbg_fill(), fbg_pixela()

◆ fbg_polygon()

void fbg_polygon ( struct _fbg fbg,
int  num_vertices,
int *  vertices,
unsigned char  r,
unsigned char  g,
unsigned char  b 
)

draw a polygon

Parameters
fbgpointer to a FBG context / data structure
num_verticesthe number of vertices
verticespointer to a list of vertices (a list of X/Y points)
r
g
b

◆ fbg_pushResize()

void fbg_pushResize ( struct _fbg fbg,
int  new_width,
int  new_height 
)

push a resize event for the FB Graphics context note : the resize event is processed into the fbg_draw function note : resizing is not yet allowed in framebuffer mode note : if you want to immediately resize the context, see fbg_resize

Parameters
fbgpointer to a FBG context / data structure
new_widthnew render width
new_heightnew render height
See also
fbg_resize(), fbg_setResizeCallback()

◆ fbg_randf()

float fbg_randf ( float  min,
float  max 
)

pseudo random number between min / max

Parameters
min
max
Returns
pseudo random number between min / max

◆ fbg_rect()

void fbg_rect ( struct _fbg fbg,
int  x,
int  y,
int  w,
int  h,
unsigned char  r,
unsigned char  g,
unsigned char  b 
)

draw a rectangle

Parameters
fbgpointer to a FBG context / data structure
xrectangle X position (upper left coordinate)
yrectangle Y position (upper left coordinate)
wrectangle width
hrectangle height
r
g
b
See also
fbg_frect(), fbg_recta()

◆ fbg_recta()

void fbg_recta ( struct _fbg fbg,
int  x,
int  y,
int  w,
int  h,
unsigned char  r,
unsigned char  g,
unsigned char  b,
unsigned char  a 
)

draw a rectangle with alpha transparency

Parameters
fbgpointer to a FBG context / data structure
xrectangle X position (upper left coordinate)
yrectangle Y position (upper left coordinate)
wrectangle width
hrectangle height
r
g
b
a
See also
fbg_frect(), fbg_rect()

◆ fbg_resize()

void fbg_resize ( struct _fbg fbg,
int  new_width,
int  new_height 
)

resize the FB Graphics context immediately note : prefer the usage of fbg_pushResize when integrating the resize event of a custom backend (fbg_pushResize is thread safe all the time) note : resizing is not yet allowed in framebuffer mode

Parameters
fbgpointer to a FBG context / data structure
new_widthnew render width
new_heightnew render height
See also
fbg_pushResize(), fbg_setResizeCallback()

◆ fbg_rgbToHsl()

void fbg_rgbToHsl ( struct _fbg_hsl color,
float  r,
float  g,
float  b 
)

convert RGB values to HSL color

Parameters
colorpointer to a _fbg_hsl data structure
r
g
b
See also
fbg_hslToRGB()

◆ fbg_setResizeCallback()

void fbg_setResizeCallback ( struct _fbg fbg,
void(*)(struct _fbg *fbg, unsigned int new_width, unsigned int new_height)  user_resize 
)

register a user resize callback

Parameters
fbgpointer to a FBG context / data structure
user_resizeresize function
See also
fbg_resize(), fbg_pushResize()

◆ fbg_text()

void fbg_text ( struct _fbg fbg,
struct _fbg_font fnt,
char *  text,
int  x,
int  y,
int  r,
int  g,
int  b 
)

draw a text

Parameters
fbgpointer to a FBG context / data structure
fnt_fbg_font structure pointer
textthe text to draw ('
' and ' ' are treated automatically)
x
y
r
g
b
See also
fbg_createFont(), fbg_write(), fbg_textColorkey(), fbg_textBackground()

◆ fbg_textBackground()

void fbg_textBackground ( struct _fbg fbg,
int  r,
int  g,
int  b,
int  a 
)

set the current text background color (based on colorkey value!)

Parameters
fbgpointer to a FBG context / data structure
r
g
b
a0 = transparent background (based on colorkey), 255 = full text background
See also
fbg_createFont(), fbg_write(), fbg_textColorKey(), fbg_textColor()

◆ fbg_textColor()

void fbg_textColor ( struct _fbg fbg,
unsigned char  r,
unsigned char  g,
unsigned char  b 
)

set the current text color

Parameters
fbgpointer to a FBG context / data structure
r
g
b
See also
fbg_createFont(), fbg_write(), fbg_textColorKey(), fbg_textBackground()

◆ fbg_textColorKey()

void fbg_textColorKey ( struct _fbg fbg,
unsigned char  v 
)

set the current text color key

Parameters
fbgpointer to a FBG context / data structure
vgrayscale value
See also
fbg_createFont(), fbg_write(), fbg_textColor()

◆ fbg_textFont()

void fbg_textFont ( struct _fbg fbg,
struct _fbg_font font 
)

set the current font

Parameters
fbgpointer to a FBG context / data structure
font_fbg_font structure pointer
See also
fbg_createFont(), fbg_text(), fbg_write(), fbg_drawFramerate()

◆ fbg_vline()

void fbg_vline ( struct _fbg fbg,
int  x,
int  y,
int  h,
unsigned char  r,
unsigned char  g,
unsigned char  b 
)

draw a vertical line

Parameters
fbgpointer to a FBG context / data structure
xline X position (upper left coordinate)
yline Y position (upper left coordinate)
hline height
r
g
b
See also
fbg_hline, fbg_line()