Aqui está os gráficos equivalentes a "Hello, World"
// first OpenVG program
// Anthony Starks ([email protected])
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "VG/openvg.h"
#include "VG/vgu.h"
#include "fontinfo.h"
#include "shapes.h"
int main() {
int width, height;
char s[3];
init(&width, &height); // Graphics initialization
Start(width, height); // Start the picture
Background(0, 0, 0); // Black background
Fill(44, 77, 232, 1); // Big blue marble
Circle(width / 2, 0, width); // The "world"
Fill(255, 255, 255, 1); // White text
TextMid(width / 2, height / 2, "hello, world", SerifTypeface, width / 10); // Greetings
End(); // End the picture
fgets(s, 2, stdin); // look at the pic, end with [RETURN]
finish(); // Graphics cleanup
exit(0);
}
As coordenadas são valores de VGFLOAT, com a origem no canto inferior esquerdo, com X aumentando para a direita e Y aumentando. OpenVG especifica as cores como uma matriz VGFLOAT contendo valores alfa vermelha, verde, azul, variando de 0,0 a 1,0, mas normalmente as cores são especificadas como RGBA (0-255 para RGB, A de 0,0 a 1,0)
void WindowClear()
Windowclear limpa a janela para definir anteriormente a cor de fundo
void AreaClear(unsigned int x, unsigned int y, unsigned int w, unsigned int h)
AreaClear limpa um determinado retângulo nas coordenadas da janela
void WindowOpacity(unsigned int a)
WindowOpacity define a opacidade da janela
void WindowPosition(int x, int y)
WindowPosition move a janela para a posição determinada
void init(int *w, int *h)
Inicialize os gráficos: a largura e a altura da tela são retornadas. Isso deve iniciar todos os programas.
void initWindowSize(int x, int y, unsigned int w, unsigned int h)
Inicialize com dimensões específicas
void finish()
Desligue os gráficos. Isso deve encerrar todos os programas.
void Start(int width, int height)
Comece a imagem, limpe a tela com um branco padrão, defina o golpe e encha o preto.
void End()
Termine a imagem, renderizando a tela.
void SaveEnd(char *filename)
Termine a imagem, renderizando a tela, salve a varredura no arquivo nomeado como palavras de 4 bytes RGBA, com um passo de largura*4 bytes. O programa RAW2PNG converte a varredura "RAW" em PNG.
void saveterm(), restoreterm(), rawterm()
Configurações do terminal, salve as configurações atuais, restaure as configurações, coloque o terminal no modo bruto.
void setfill(float color[4])
Defina a cor de preenchimento
void Background(unsigned int r, unsigned int g, unsigned int b)
Preencha a tela com a cor do plano de fundo definida a partir dos valores RGB.
void BackgroundRGB(unsigned int r, unsigned int g, unsigned int b, VGfloat a)
Limpa a tela para uma cor de fundo com alfa
void StrokeWidth(float width)
Defina a largura do golpe.
void RGBA(unsigned int r, unsigned int g, unsigned int b, VGfloat a, VGfloat color[4])
Preencha um vetor de cores dos valores RGBA.
void RGB(unsigned int r, unsigned int g, unsigned int b, VGfloat color[4])
Preencha um vetor de cores dos valores RGB.
void Stroke(unsigned int r, unsigned int g, unsigned int b, VGfloat a)
Defina a cor do AVC usando valores RGBA.
void Fill(unsigned int r, unsigned int g, unsigned int b, VGfloat a)
Defina a cor de preenchimento usando valores RGBA.
void FillLinearGradient(VGfloat x1, VGfloat y1, VGfloat x2, VGfloat y2, VGfloat *stops, int n)
Defina o preenchimento como um gradiente linear delimitado por (x1, y1) e (x2, y2). Usando compensações e cores especificadas em n número de paradas
void FillRadialGradient(VGfloat cx, VGfloat cy, VGfloat fx VGfloat fy, VGfloat r, VGfloat *stops, int n)
Defina o preenchimento como um gradiente radial centrado em (cx, cy) com raio r e ponto focal em (fx, ry), usando compensações e cores especificadas em n número de paradas
void Line(VGfloat x1, VGfloat y1, VGfloat x2, VGfloat y2)
Desenhe uma linha entre (x1, y1) e (x2, y2).
void Rect(VGfloat x, VGfloat y, VGfloat w, VGfloat h)
Desenhe um retângulo com sua origem (inferior esquerdo) em (x, y) e o tamanho é (largura, altura).
void RectOutline(VGfloat x, VGfloat y, VGfloat w, VGfloat h)
Versão delineada
void Roundrect(VGfloat x, VGfloat y, VGfloat w, VGfloat h, VGfloat rw, VGfloat rh)
Desenhe um retângulo arredondado com sua origem (inferior esquerdo) em (x, y) e o tamanho é (largura, altura).
A largura e a altura dos cantos são especificadas com (RW, RH).
void RoundrectOutline(VGfloat x, VGfloat y, VGfloat w, VGfloat h, VGfloat rw, VGfloat rh)
Versão delineada
void Polygon(VGfloat *x, VGfloat *y, VGint n)
Desenhe um polígono usando as coordenadas nas matrizes apontadas por x e y. O número de coordenadas é n.
void Polyline(VGfloat *x, VGfloat *y, VGint n)
Desenhe uma poliina usando as coordenadas em matrizes apontadas por x e y. O número de coordenadas é n.
void Circle(VGfloat x, VGfloat y, VGfloat d)
Desenhe um círculo centrado em (x, y) com diâmetro d.
void CircleOutline(VGfloat x, VGfloat y, VGfloat r)
Versão delineada
void Ellipse(VGfloat x, VGfloat y, VGfloat w, VGfloat h)
Desenhe uma elipse centrada em (x, y) com raios (w, h).
void EllipseOutline(VGfloat x, VGfloat y, VGfloat w, VGfloat h)
Versão delineada
void Qbezier(VGfloat sx, VGfloat sy, VGfloat cx, VGfloat cy, VGfloat ex, VGfloat ey)
Desenhe uma curva bezier quadrática começando em (SX, SY), usando pontos de controle em (CX, CY), terminando em (ex, ey).
void QbezierOutline(VGfloat sx, VGfloat sy, VGfloat cx, VGfloat cy, VGfloat ex, VGfloat ey)
Versão delineada
void Cbezier(VGfloat sx, VGfloat sy, VGfloat cx, VGfloat cy, VGfloat px, VGfloat py, VGfloat ex, VGfloat ey)
Desenhe uma curva bezier cúbica começando em (SX, SY), usando pontos de controle em (cx, cy) e (px, py), terminando em (ex, ey).
void CbezierOutline(VGfloat sx, VGfloat sy, VGfloat cx, VGfloat cy, VGfloat px, VGfloat py, VGfloat ex, VGfloat ey)
Versão delineada
void Arc(VGfloat x, VGfloat y, VGfloat w, VGfloat h, VGfloat sa, VGfloat aext)
Desenhe um arco elíptico centrado em (x, y), com largura e altura em (w, h). O ângulo inicial (graus) é SA, a extensão do ângulo é AEXT.
void ArcOutline(VGfloat x, VGfloat y, VGfloat w, VGfloat h, VGfloat sa, VGfloat aext)
Versão delineada
void Text(VGfloat x, VGfloat y, char* s, Fontinfo f, int pointsize)
Desenhe um texto (s) de texto (s) no local (x, y), usando o Pointize.
void TextMid(VGfloat x, VGfloat y, char* s, Fontinfo f, int pointsize)
Desenhe um texto (s) de texto (s) em centralização no local (x, y), usando o ponto de ponta.
void TextEnd(VGfloat x, VGfloat y, char* s, Fontinfo f, int pointsize)
Desenhe um texto (s) de texto (s) com seu empréstimo alinhado à localização (x, y), usando o ponto de ponta
VGfloat TextWidth(char *s, Fontinfo f, int pointsize)
Retornar a largura do texto
VGfloat TextHeight(Fontinfo f, int pointsize)
Devolver a altura de uma fonte
TextDepth(Fontinfo f, int pointsize)
Retorne a distância de uma fonte além da linha de base.
void Image(VGfloat x, VGfloat y, int w, int h, char * filename)
Coloque uma imagem JPEG com dimensões (W, H) em (x, y).
void Translate(VGfloat x, VGfloat y)
Traduza o sistema de coordenadas para (x, y).
void Rotate(VGfloat r)
Gire o sistema de coordenadas em torno do ângulo R (graus).
void Scale(VGfloat x, VGfloat y)
Escala por x, y.
void Shear(VGfloat x, VGfloat y)
Cisalhamento pelos ângulos x, y.
void ClipRect(VGint x, VGint y, VGint w, VGint h)
Limite de desenho a área de desenho para o retângulo especificado, termine com clipend ()
void ClipEnd()
Área de recorte de extremidades
Também está incluído o programa FONT2OPENVG, que transforma as informações da fonte em fonte C que você pode incorporar em seu programa. O Makefile faz o código da fonte dos arquivos encontrados em/usr/share/fonts/truetype/ttf-dejavu/. Se você deseja usar outras fontes, ajuste o makefile de acordo ou gerar o código da fonte por conta própria assim que o programa FONT2OPENVG for construído.
FONT2OPENVG leva três argumentos: o arquivo de fonte TrueType, o arquivo de saída a ser incluído e o prefixo para identificadores. Por exemplo, para usar a fonte Dejavu Sans:
./font2openvg /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf DejaVuSans.inc DejaVuSans
e inclua o código gerado em seu programa:
#include "DejaVuSans.inc"
Fontinfo DejaFont
A função loadfont cria caminhos OpenVG a partir dos dados da fonte:
loadfont(DejaVuSans_glyphPoints,
DejaVuSans_glyphPointIndices,
DejaVuSans_glyphInstructions,
DejaVuSans_glyphInstructionIndices,
DejaVuSans_glyphInstructionCounts,
DejaVuSans_glyphAdvances,
DejaVuSans_characterMap,
DejaVuSans_glyphCount);
A função UNLOADFONT libera as informações do caminho:
unloadfont(DejaFont.Glyphs, DejaFont.Count);
Observe que a localização dos arquivos de fonte pode ser diferente. (O local atual para Jessie IS/usr/share/fonts/truetype/ttf-dejavu) Use a variável Fontlib Makefile para ajustar esse local.
Observe que você precisará de pelo menos 64 mbytes de RAM da GPU : . Você também precisará das fontes Dejavu e das bibliotecas JPEG e Freetype. A ferramenta de recuperação também é útil para formatação de código. Instale -os via:
pi@raspberrypi ~ $ sudo apt-get install libjpeg8-dev indent libfreetype6-dev ttf-dejavu-core
Em seguida, construa a biblioteca e teste:
pi@raspberrypi ~ $ git clone git://github.com/ajstarks/openvg
pi@raspberrypi ~ $ cd openvg
pi@raspberrypi ~/openvg $ make
g++ -I/usr/include/freetype2 fontutil/font2openvg.cpp -o font2openvg -lfreetype
./font2openvg /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf DejaVuSans.inc DejaVuSans
224 glyphs written
./font2openvg /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf DejaVuSansMono.inc DejaVuSansMono
224 glyphs written
./font2openvg /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf DejaVuSerif.inc DejaVuSerif
224 glyphs written
gcc -O2 -Wall -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -c libshapes.c
gcc -O2 -Wall -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -c oglinit.c
pi@raspberrypi ~/openvg/client $ cd client
pi@raspberrypi ~/openvg/client $ make test
cc -Wall -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -o shapedemo shapedemo.c ../libshapes.o ../oglinit.o -L/opt/vc/lib -lGLESv2 -ljpeg
./shapedemo demo 5
O programa "Shapedemo" exerce uma API de alto nível construída no OpenVG encontrada em libshapes.c.
./shapedemo # show a reference card
./shapedemo raspi # show a self-portrait
./shapedemo image # show four test images
./shapedemo astro # the sun and the earth, to scale
./shapedemo text # show blocks of text in serif, sans, and mono fonts
./shapedemo rand 10 # show 10 random shapes
./shapedemo rotate 10 a # rotated and faded "a"
./shapedemo test "hello, world" # show a test pattern, with "hello, world" at mid-display in sans, serif, and mono.
./shapedemo fontsize # show a range of font sizes (per <https://speakerdeck.com/u/idangazit/p/better-products-through-typography>)
./shapedemo demo 10 # run through the demo, pausing 10 seconds between each one; contemplate the awesome.
Para instalar a biblioteca Shapes como uma biblioteca compartilhada em todo o sistema
pi@raspberrypi ~/openvg $ make library
pi@raspberrypi ~/openvg $ sudo make install
A biblioteca do OpenVG Shapes agora pode ser usada no código C, incluindo Shapes.H e Fontinfo.h e vinculando -se a libshapes.so:
#include <shapes.h>
#include <fontinfo.h>
pi@raspberrypi ~ $ gcc -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads anysource.c -o anysource -lshapes
pi@raspberrypi ~ $ ./anysource
Um invólucro de linguagem de programação GO para a biblioteca é encontrado no OpenVG.go. Os clientes de amostra estão no diretório Go-Client. A API segue de perto a API C; Aqui está o programa "Hello, World" em Go:
A API GO
package main
import (
"bufio"
"github.com/ajstarks/openvg"
"os"
)
func main() {
width, height := openvg.Init() // OpenGL, etc initialization
w2 := openvg.VGfloat(width / 2)
h2 := openvg.VGfloat(height / 2)
w := openvg.VGfloat(width)
openvg.Start(width, height) // Start the picture
openvg.BackgroundColor("black") // Black background
openvg.FillRGB(44, 77, 232, 1) // Big blue marble
openvg.Circle(w2, 0, w) // The "world"
openvg.FillColor("white") // White text
openvg.TextMid(w2, h2, "hello, world", "serif", width/10) // Greetings
openvg.End() // End the picture
bufio.NewReader(os.Stdin).ReadBytes('n') // Pause until [RETURN]
openvg.Finish() // Graphics cleanup
}
Para construir o invólucro: (verifique se o Gopath está definido)
pi@raspberrypi ~/openvg $ go install .
pi@raspberrypi ~/openvg $ cd go-client/hellovg
pi@raspberrypi ~/openvg/go-client/hellovg $ go build .
pi@raspberrypi ~/openvg/go-client/hellovg $ ./hellovg