


Code: Select all
shapes: shapes.c
cc -Wall -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -o shapes shapes.c -L/opt/vc/lib -lGLESv2
Code: Select all
pi@raspberrypi ~/vg $ make fonts shapes
g++ -I /usr/include/freetype2 font2openvg.cpp -o font2openvg -lfreetype
for f in /usr/share/fonts/truetype/ttf-dejavu/*.ttf; do fn=`basename $f .ttf`; ./font2openvg $f $fn.inc $fn; done
224 glyphs written
224 glyphs written
224 glyphs written
224 glyphs written
224 glyphs written
224 glyphs written
cc -Wall -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -o shapes shapes.c -L/opt/vc/lib -lGLESv2
pi@raspberrypi ~/vg $ ./shapes # hit return when you are done looking at the awesomness
pi@raspberrypi ~/vg $ ./shapes 100 # show 100 random shapes
Code: Select all
#include <linux/input.h>
#include <fcntl.h>
#include <pthread.h>Code: Select all
typedef struct{
int fd;
struct input_event ev;
VGfloat x;
VGfloat y;
int left;
int right;
}mouse_t;
mouse_t mouse;
void* eventThread(void* arg) {
//Open mouse driver
if ( (mouse.fd = open("/dev/input/event2", O_RDONLY)) < 0) {
printf("Error opening Mouse!\n");
quitState=1;
return &quitState;
}
printf("Mouse Active!\n");
//Reset mouse
mouse.x=0;
mouse.y=0;
while(1){
read(mouse.fd,&mouse.ev,sizeof(struct input_event));
// Check events
//Reset Mouse button states
mouse.left=0;
mouse.right=0;
if(mouse.ev.type == EV_REL) {
if(mouse.ev.code==REL_X){
mouse.x += (VGfloat)mouse.ev.value;
if(mouse.x<0){mouse.x=0;}
if(mouse.x>1680){mouse.x=1680;}
}
if(mouse.ev.code==REL_Y){
mouse.y -= (VGfloat)mouse.ev.value;
if(mouse.y<0){mouse.y=0;}
if(mouse.y>1050){mouse.y=1050;}
} //This ones goes backwards hense the minus
}
if(mouse.ev.type==EV_KEY){
//printf("Time Stamp:%d - type %d, code %d, value %d\n",mouse.ev.time.tv_usec,mouse.ev.type,mouse.ev.code,mouse.ev.value);
if(mouse.ev.code==BTN_LEFT){
mouse.left=1;
printf("User Quit\n");
quitState=1;
return &quitState; //Left mouse to quit
}
if(mouse.ev.code==BTN_RIGHT){
mouse.right=1;
}
}
}
}
Code: Select all
//Start Event Thread
int err =pthread_create( &inputThread, NULL, &eventThread, NULL);
if(err != 0){
printf("Error creating input event thread...");
return -1;
}
printf("Event Thread Started\n");
Code: Select all
#include <linux/input.h>
#include <fcntl.h>
#include <pthread.h>
#include <stdlib.h>
typedef struct
{
int fd;
struct input_event ev;
float x;
float y;
int left;
int right;
} mouse_t;
mouse_t mouse;
int quitState;
float width = 1920, height=1080;
void* eventThread(void* arg) {
//Open mouse driver
if ( (mouse.fd = open("/dev/input/event2", O_RDONLY)) < 0) {
printf("Error opening Mouse!\n");
quitState=1;
return &quitState;
}
printf("Mouse Active!\n");
//Reset mouse
mouse.x=0;
mouse.y=0;
while(1) {
read(mouse.fd,&mouse.ev,sizeof(struct input_event));
printf("[%4.0f,%4.0f]\n", mouse.x, mouse.y);
// Check events
//Reset Mouse button states
mouse.left=0;
mouse.right=0;
if(mouse.ev.type == EV_REL) {
if(mouse.ev.code==REL_X) {
mouse.x += (float)mouse.ev.value;
if(mouse.x<0){mouse.x=0;}
if(mouse.x>width){mouse.x=width;}
}
if(mouse.ev.code==REL_Y) {
mouse.y -= (float)mouse.ev.value;
if(mouse.y<0){mouse.y=0;}
if(mouse.y>height){mouse.y=height;}
} //This ones goes backwards hense the minus
}
if(mouse.ev.type==EV_KEY) {
if(mouse.ev.code==BTN_LEFT) {
mouse.left=1;
printf("User Quit\n");
quitState=1;
return &quitState; //Left mouse to quit
}
if(mouse.ev.code==BTN_RIGHT) {
mouse.right=1;
}
}
}
}
void main() {
//Start Event Thread
pthread_t inputThread;
int err =pthread_create( &inputThread, NULL, &eventThread, NULL);
if(err != 0) {
printf("Error creating input event thread...");
return -1;
}
printf("Event Thread Started\n");
while (getchar() != '\n') {
;
}
}
Code: Select all
cc m.c -o m -lpthread
./m
Event Thread Started
Mouse Active!
Code: Select all
import "github.com/ajstarks.openvg"
func main() {
width, height := 500, 500
openvg.Init()
openvg.Start(width, height, "black")
openvg.Circle(100,100,20, "fill:red")
openvg.Setfill("bliue")
r := 20
for i:=0; i < width; i+=25 {
openvg.Circle(i, 200, r)
}
openvg.End()
openvg.Finish()
}
Code: Select all
void rotext(VGfloat x, VGfloat y, int w, int h, int n, VGfloat deg, char *s) {
int i;
VGfloat textcolor[4] = {0,0,0,1}, bgcolor[4] = {1,1,1,1};
VGfloat fade = (100.0/(VGfloat)n)/100.0;
Start(w, h, bgcolor);
Translate(x,y);
for (i=0; i < n; i++) {
Text(0,0, s, 256, textcolor, DejaVuSansPaths, DejaVuSans_characterMap, DejaVuSans_glyphAdvances, VG_FILL_PATH);
textcolor[3] -= fade;
Rotate(deg);
}
End();
}