PlutoVG standalone 2D vector graphics library 32/64-bit dynamic/static Windows/Linux.

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
Post Reply
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

PlutoVG standalone 2D vector graphics library 32/64-bit dynamic/static Windows/Linux.

Post by D.J.Peters »

PlutoVG is a komplete standalone 2D vector graphics C library.
https://github.com/sammycage/plutovg

Image

download: libplutovg.zip from Nov 09, 2022

Included are 32/64-bit static and dýnamic libs for Windows and Linux.

I prefer static linking for FreeBASIC

but you can linking dynamic also
#define PLUTOVG_DYNAMIC
#include "plutovg.bi"

' ...

For other devices then x86,x86_64 eg. ARM / ARM64
I created in the libplutovg-src folder a codeblocks folder
you can open the libplutovg.workspace with the codeblocks IDE
and rebuild static/dynamic 32/64-bit libs for Windows or any Linux device.

Joshy

file: test01.bas create vector graphic in memory and save it as png file.

Code: Select all

#define PLUTOVG_STATIC
#include "plutovg.bi"

' draw vector graphic im memory and save it as PNG image

const as double pi = 3.14159265358979323846

const as long iWidth = 150
const as long iHeight = 150

ChDir(ExePath()) ' save *.png in exepath

dim as double center_x = iWidth * 0.5
dim as double center_y = iHeight * 0.5
dim as double face_radius = 70
dim as double eye_radius = 10
dim as double mouth_radius = 50
dim as double eye_offset_x = 25
dim as double eye_offset_y = 20
dim as double eye_x = center_x - eye_offset_x
dim as double eye_y = center_y - eye_offset_y

dim as plutovg_surface_t ptr surface = plutovg_surface_create(iWidth, iHeight)
dim as plutovg_t ptr         pluto = plutovg_create(surface)

plutovg_save(pluto)
  plutovg_arc(pluto, center_x, center_y, face_radius, 0, 2 * pi, 0)
  plutovg_set_source_rgb(pluto, 1, 1, 0)
  plutovg_fill_preserve(pluto)
  plutovg_set_source_rgb(pluto, 0, 0, 0)
  plutovg_set_line_width(pluto, 5)
  plutovg_stroke(pluto)
plutovg_restore(pluto)

plutovg_save(pluto)
  plutovg_arc(pluto, eye_x, eye_y, eye_radius, 0, 2 * pi, 0)
  plutovg_arc(pluto, center_x + eye_offset_x, eye_y, eye_radius, 0, 2 * pi, 0)
  plutovg_fill(pluto)
plutovg_restore(pluto)

plutovg_save(pluto)
  plutovg_arc(pluto, center_x, center_y, mouth_radius, 0, pi, 0)
  plutovg_set_line_width(pluto, 5)
  plutovg_stroke(pluto)
plutovg_restore(pluto)

plutovg_surface_write_to_png(surface, "smiley.png")
print "'smiley.png' saved press any key ..."
sleep
plutovg_surface_destroy(surface)
plutovg_destroy(pluto)
file: test02.bas create vector graphic on FBGFX image and put it on the screen.

Code: Select all

#define PLUTOVG_STATIC
#include "plutovg.bi"

' draw vector graphic on FBGFX Image

const as double pi = 3.14159265358979323846

const as long iWidth  = 150
const as long iHeight = 150

dim as double center_x = iWidth * 0.5
dim as double center_y = iHeight * 0.5
dim as double face_radius = 70
dim as double eye_radius = 10
dim as double mouth_radius = 50
dim as double eye_offset_x = 25
dim as double eye_offset_y = 20
dim as double eye_x = center_x - eye_offset_x
dim as double eye_y = center_y - eye_offset_y

screenres iWidth,iHeight,32
line (0,0)-(iWidth,iHeight),RGBA(255,255,255,255),BF

dim as any ptr img = ImageCreate(iWidth,iHeight,RGBA(0,0,0,0))
dim as ubyte ptr imgPixels
dim as long imgWidth,imgHeight,imgBytes,imgPitch
ImageInfo(img,imgWidth,imgHeight,imgBytes,imgPitch,imgPixels)

var surface = plutovg_surface_create_for_data(imgPixels,imgWidth,imgHeight,imgPitch)
var pluto = plutovg_create(surface)

plutovg_save(pluto)
  plutovg_arc(pluto, center_x, center_y, face_radius, 0, 2 * pi, 0)
  plutovg_set_source_rgb(pluto, 1, 1, 0)
  plutovg_fill_preserve(pluto)
  plutovg_set_source_rgb(pluto, 0, 0, 0)
  plutovg_set_line_width(pluto, 5)
  plutovg_stroke(pluto)
plutovg_restore(pluto)

plutovg_save(pluto)
  plutovg_arc(pluto, eye_x, eye_y, eye_radius, 0, 2 * pi, 0)
  plutovg_arc(pluto, center_x + eye_offset_x, eye_y, eye_radius, 0, 2 * pi, 0)
  plutovg_fill(pluto)
plutovg_restore(pluto)

plutovg_save(pluto)
  plutovg_arc(pluto, center_x, center_y, mouth_radius, 0, pi, 0)
  plutovg_set_line_width(pluto, 5)
  plutovg_stroke(pluto)
plutovg_restore(pluto)

put (0,0),img,ALPHA
sleep
plutovg_surface_destroy(surface)
plutovg_destroy(pluto)
Last edited by D.J.Peters on Nov 09, 2022 19:40, edited 6 times in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: PlutoVG standalone 2D vector graphics library 32/64-bit dynamic/static Windows/Linux.

Post by D.J.Peters »

PlutoVG for FreeBASIC is complete now. (see first post)
I build 32/64-bit static/dynamic Windows/Linux libs.

Joshy
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: PlutoVG standalone 2D vector graphics library 32/64-bit dynamic/static Windows/Linux.

Post by D.J.Peters »

PlutoVG supports high quality truetype font rendering including UTF-8.

Joshy
Image
file: test03.bas

Code: Select all

#define PLUTOVG_STATIC
#include "plutovg.bi"

' draw vector font's on FBGFX Image

const as long iWidth  = 640
const as long iHeight = 480
const as double FONT_SIZE = 128

screenres iWidth,iHeight,32

var img = ImageCreate(iWidth,iHeight,0)
dim as ubyte ptr imgPixels
dim as long imgWidth,imgHeight,imgBytes,imgPitch
ImageInfo(img,imgWidth,imgHeight,imgBytes,imgPitch,imgPixels)

var surface = plutovg_surface_create_for_data(imgPixels,imgWidth,imgHeight,imgPitch)
var pluto   = plutovg_create(surface)
var font    = plutovg_font_load_from_file("fonts/GeosansLight.ttf",FONT_SIZE)
plutovg_set_font(pluto,font)
plutovg_set_source_rgb(pluto, 1, 1, 0)

plutovg_text(pluto, "Hello World", 32, 128)
plutovg_fill(pluto)

plutovg_text(pluto, "Hello World", 32, 256)
plutovg_stroke(pluto)

plutovg_save(pluto)
  plutovg_text(pluto, "Hello World", 90, 344)
  plutovg_rotate(pluto,.2)  
  plutovg_fill(pluto)
plutovg_restore(pluto)

put (0,0),img,PSET 'ALPHA
sleep
plutovg_surface_destroy(surface)
plutovg_destroy(pluto)
plutovg_font_destroy(font)
Last edited by D.J.Peters on Oct 12, 2022 17:45, edited 2 times in total.
SARG
Posts: 1755
Joined: May 27, 2005 7:15
Location: FRANCE

Re: PlutoVG standalone 2D vector graphics library 32/64-bit dynamic/static Windows/Linux.

Post by SARG »

@Joshy,

We can't see directly the images. I guess it's necessary https instead htpp.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: PlutoVG standalone 2D vector graphics library 32/64-bit dynamic/static Windows/Linux.

Post by D.J.Peters »

SARG wrote: Oct 12, 2022 16:59We can't see directly the images. I guess it's necessary https instead htpp.
thank you I installed a SSL certificates the problem should be fixed now.

joshy
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: PlutoVG standalone 2D vector graphics library 32/64-bit dynamic/static Windows/Linux.

Post by D.J.Peters »

Drawing holes in shapes (circle in filled round rectangle).

Joshy

file: test04.bas

Code: Select all

#define PLUTOVG_STATIC
#include "plutovg.bi"

' draw a hole in a filled shape

const as long iWidth  = 415
const as long iHeight = 415
screenres iWidth,iHeight,32
var img = ImageCreate(iWidth,iHeight,0)
dim as ubyte ptr imgPixels
dim as long imgWidth,imgHeight,imgBytes,imgPitch
ImageInfo(img,imgWidth,imgHeight,imgBytes,imgPitch,imgPixels)

var surface = plutovg_surface_create_for_data(imgPixels,imgWidth,imgHeight,imgPitch)
var pluto   = plutovg_create(surface)

for y as integer = 0 to 9
  dim as integer topY = 10 + y * 40  
  for x as integer = 0 to 9
    dim as integer topX = 10 + x * 40 
    plutovg_set_source_rgb(pluto, x*0.1,y*0.1, 1-x*0.1)
    plutovg_round_rect(pluto, topX, topY, 35, 35, 7.5, 7.5)
    plutovg_set_fill_rule(pluto, 0) ' change the winding rule
      plutovg_circle(pluto, topX+17.5, topY+17.5,10)
    plutovg_set_fill_rule(pluto, 1) ' and back for next round rectangle
    plutovg_fill(pluto)    
    'plutovg_stroke(pluto) 
  next
next

put (0,0),img,PSET 'ALPHA
sleep
plutovg_surface_destroy(surface)
plutovg_destroy(pluto)
plutovg_fill(pluto)
Image
plutovg_stroke(pluto)
Image
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: PlutoVG standalone 2D vector graphics library 32/64-bit dynamic/static Windows/Linux.

Post by D.J.Peters »

fixed a small bug and static linking is default now.
(see first post)

Joshy
Post Reply