mk-fg / easy-vg

Simple OpenVG API wrapper for direct-to-screen 2D graphics from C and python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EasyVG [mk-fg fork]

One LICENSE

EasyVG provides an abstraction layer on top of native OpenVG graphics API, for easy creation of OpenVG contexts and drawing shapes, images, and text, without requiring anything other than the most minimal system setup.

EasyVG follows standard C and EGL API naming conventions.

EasyVG is fully compatible with Raspberry Pi boards.

This mk-fg/easy-vg repository is a fork of (in a recent-first order):

Difference from upstream EasyVG (mgthomas99/easy-vg):

  • Has API frozen at a state of ~2018-08-01 master branch, with simple "draw things via single call" API, same as ajstarks/openvg has, before introducing paths (which are still in mgthomas99/easy-vg#develop branch at the time of writing).

  • Intended to be built and used as a shared libshapes.so library, including from python via ctypes wrapper.

  • Updated with fixes and minor additional API features where necessary, without changing its current methods and logic if possible.

Text & Fonts

EasyVG is capable of rendering text.

One default font (DejaVuSans.ttf) is converted and built-into libshapes.so via Makefile.

To use custom TrueType fonts, developers should convert the font into C code use the font2openvg binary (use make lib/font2openvg or just make to build it), and then include and init it using loadfont() in C API.

Loading custom fonts at runtime (incl. via python wrapper) is not supported.

Using font2openvg

The font2openvg repository contains more information on font2openvg tool included in this repo.

Once the lib/font2openvg is built, compile a TrueType font file.

For the below demonstrations, it will be assumed that you are using a source font file named DejaVuSans.ttf and a compiled output named DejaVuSans.inc.

Once a font is compiled, it can be included in your code like this:

    #include "DejaVuSans.inc"
    Fontinfo DejaFont

    loadfont(DejaVuSans_glyphPoints,
            DejaVuSans_glyphPointIndices,
            DejaVuSans_glyphInstructions,
            DejaVuSans_glyphInstructionIndices,
            DejaVuSans_glyphInstructionCounts,
            DejaVuSans_glyphAdvances,
            DejaVuSans_characterMap,
            DejaVuSans_glyphCount);

    // Unload the font when done
    unloadfont(DejaFont.Glyphs, DejaFont.Count);

Build and Run Examples

Note that you will need at least 64 MB of GPU RAM (when using a single DispmanX layer, 128+ for more)

For building libshapes.so and/or including the code, requirements are:

  • DejaVu fonts, jpeg and freetype libraries with headers.
  • For building and easy packaging on raspbian/debian: build-essentials checkinstall
# apt install libfreetype6-dev libjpeg8-dev ttf-dejavu-core
# apt install build-essentials checkinstall

Runtime requirements for libshapes.so and python wrapper:

  • libbrcmEGL / libbrcmGLESv2 - RPi's VC4 GL libs.
  • libjpeg - for createImageFromJpeg, can be omitted when including code from C.
  • python3 - when/if using python wrapper.
# apt install libjpeg8 python3

Basic build process:

% curl https://github.com/mk-fg/easy-vg/archive/master.tar.gz | tar -xz
% cd easy-vg-master
% make

Build and run C example(s):

% pushd example
% make hello
% ./hello
% popd

Package/install on raspbian/debian (including libshapes.so and python module):

% sudo checkinstall -Dy --pkgname=easy-vg --pkgversion=1 --backup=no -- make install-checkinstall
% dpkg -L easy-vg
% dpkg-deb -I easy-vg_1-1_armhf.deb

Install / uninstall to current rootfs (not recommended outside of packaging scripts and such):

% make install
% make install-python
% make uninstall

Run python example:

% python3 python/hello.py

Build self-contained C binary (e.g. example.c, see also example/hello.c) based on the library code:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <jpeglib.h>
#include "VG/openvg.h"
#include "VG/vgu.h"
#include "./src/fontinfo.h"
#include "./src/libshapes.h"

// Load image from specified jpg file and display it stretched to full screen.

int main(int argc, char *argv[]) {
  int w, h;
  evgInit(&w, &h, -1);
  evgBegin();
  evgImage(0, 0, w, h, argv[1]);
  evgEnd();
  while (1) sleep(3600);
  evgFinish();
  return 0;
}
% gcc -Wall \
  -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads \
  -I. ./example.c -o ./example \
  ./build/libshapes.o ./build/oglinit.o -L/opt/vc/lib -lbrcmEGL -lbrcmGLESv2 -lbcm_host -lpthread -ljpeg
% curl -OL https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg
% ./example Example.jpg

Build C binary linked against installed libshapes.so:

#include <shapes.h>
#include <fontinfo.h>

// ... code using libshapes.so
% gcc -Wall \
  -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads \
  example.c -o example -lshapes
% ./example

Have fun!

License

See the LICENSE file for license information.

About

Simple OpenVG API wrapper for direct-to-screen 2D graphics from C and python

License:Other


Languages

Language:C 65.7%Language:C++ 19.8%Language:Python 10.1%Language:Makefile 4.3%