## HDMI graphic lib: openvg syntax questions

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

### HDMI graphic lib: openvg syntax questions

hey,
I have some questions about openvg syntax and more.

https://github.com/ajstarks/openvg

My first question is about outlined geometric shapes and filled shapes.

by
Background(0, 0, 0);
Fill(255,255,255,1);
Circle(50, 40, 10);

I get a white filled circle on a black background,
but how do I get just a white circle line, or outlined by different colors?, inside of the circle still Background=black?

Sort of Circle opposite to FillCircle?

The same it's about Rect opp. to FillRect and so on?
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

Paeryn
Posts: 2783
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

### Re: HDMI graphic lib: openvg syntax questions

You set the stroke (outline) colour with Stroke(); the same way as you set the fill colour with Fill(); but you still need a circle (or ellipse) function that only draws the stroke and not the fill.
ajstarks' Ellipse function (Circle just calls Ellipse with the same width as height) is

Code: Select all

``````void Ellipse(VGfloat x, VGfloat y, VGfloat w, VGfloat h) {
VGPath path = newpath();
vguEllipse(path, x, y, w, h);
vgDrawPath(path, VG_FILL_PATH | VG_STROKE_PATH);
vgDestroyPath(path);
}``````
So you would need to write an equivalent ellipse function that calls the vgDrawPath() with VG_STROKE_PATH set only, e.g.

Code: Select all

``````void EllipseOutline(VGfloat x, VGfloat y, VGfloat w, VGfloat h) {
VGPath path = newpath();
vguEllipse(path, x, y, w, h);
vgDrawPath(path, VG_STROKE_PATH);
vgDestroyPath(path);
}

void CircleOutline(VGfloat x, VGfloat y, VGfloat r) {
EllipseOutline(x, y, r, r);
}
``````
The same goes for rectangles and any other shapes you want.

Edit:
Just noticed that the Ellipse() function calls newpath() which is local to ajstarks' library so if you aren't adding the functions to the library you need the newpath() function as well.

Code: Select all

``````VGPath newpath() {
return vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL);
}``````
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

### Re: HDMI graphic lib: openvg syntax questions

Unfortunately my English is very poor, e.g. I know the meaning of "stroke" only as "apoplexy" or "beat" or "shock" - what do you mean by that?
Also the rest of your explanation is quite complicated, the meaning is not quite clear in the end as I am also only very new to C and Linux (I was using the Arduino IDE so far which is very easy compared to the complicated Raspi C libs).

But aside from the meaning of words - what do I have to do? Just use the word "stroke" instead of "fill"?
I didn't want to rewrite ajstarks lib, I just wanted to use it for draw-circle and fill-circle and so on.

For fill-circle it's clear (also for fill-rect):
Background(0, 0, 0);
Fill(255,255,255,1); // (not sure what the "1" is for)
Circle(50, 40, 10);

now what do you mean what I have to do for draw (outline) circle? this one?
Background(0, 0, 0);
Stroke(255,255,255,1); // (not sure what the "1" is for)
Circle(50, 40, 10);

#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

Paeryn
Posts: 2783
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

### Re: HDMI graphic lib: openvg syntax questions

Unfortunately my English is very poor, e.g. I know the meaning of "stroke" only as "apoplexy" or "beat" or "shock" - what do you mean by that?
Stroke as in the stroke of ink left by by a pen or brush, basically a line drawn.
davenull wrote:Also the rest of your explanation is quite complicated, the meaning is not quite clear in the end as I am also only very new to C and Linux (I was using the Arduino IDE so far which is very easy compared to the complicated Raspi C libs).

But aside from the meaning of words - what do I have to do? Just use the word "stroke" instead of "fill"?
I didn't want to rewrite ajstarks lib, I just wanted to use it for draw-circle and fill-circle and so on.
Fill sets the colour that the shape will be filled in with, Stroke sets the colour of the edge of the shape. Unfortunately ajstarks' library only defines functions that draws filled shapes (apart from the generic Polygon which does have a non-filled version, Polyline). So you'll have to either write the functions in your own code, add the functions to the library yourself or ask ajstarks to add them to the library.
davenull wrote:For fill-circle it's clear (also for fill-rect):
Background(0, 0, 0);
Fill(255,255,255,1); // (not sure what the "1" is for)
Circle(50, 40, 10);

now what do you mean what I have to do for draw (outline) circle? this one?
Background(0, 0, 0);
Stroke(255,255,255,1); // (not sure what the "1" is for)
Circle(50, 40, 10);

The 1 in the colours is for alpha, or how translucent the colour is. A value of 1 means the colour of the pixels drawn will be 100% of the colour given, 0.5 would mean each pixel will be 50% the colour given and 50% of whatever the original colour of the pixel on screen was.
You might get away with setting the fill colour to have 0 alpha (openvg will still fill the shape but with a transparent colour), it won't be as quick as not filling but if you are not drawing many then you probably won't notice.

Code: Select all

``````Background (0, 0, 0);
Fill (0, 0, 0, 0);  // 0 alpha so should be transparent
Stroke (255, 255, 255, 1);
Circle (50, 40, 10);
``````
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

### Re: HDMI graphic lib: openvg syntax questions

now I understood it, and fill shape by (0,0,0,0) is a good workaround.
thank you very much!
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

### Re: HDMI graphic lib: openvg syntax questions

1) you always need Init() and Finish()
2) you can have Start(), it must be paired with End().
Given one has a program which is using both the console window for printf() and the graphis window for drawing:

Code: Select all

``````// start
char s[3];
float val1, val2;

printf("starting...\n");

// do some calculation
val1 = foo();
val2 = bas();
// print the result on stdout:
printf("%f\n", val1);
printf("%f\n", val2);
fgets(s, 2, stdin);   // wait for key press
// now output as a graph line  on a canvas
Line(0, val1, 0, val2);
fgets(s, 2, stdin);  // wait for key press

// do some new calculation
val1 = foo();
val2 = bas();
// print the result on stdout:
printf("%f\n", val1);
printf("%f\n", val2);
fgets(s, 2, stdin);  // wait for key press
// now output as a graph line on a canvas
Line(1, val1, 1, val2);
fgets(s, 2, stdin);  // wait for key press

// and so on
//...
printf("program ended...press key to quit"\n");
fgets(s, 2, stdin);   // wait for key press ``````
I don't see in the moment how to set the Init/Finish and Start/End commands in order
to see both the graphic screen(canvas) and the terminal window alternatively
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

Paeryn
Posts: 2783
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

### Re: HDMI graphic lib: openvg syntax questions

Just thought of a way - when you want to show the terminal you can clear the openvg window with a fully transparent colour, then the linux framebuffer below will show through. Calling Start() will make it visible again, albeit cleared so if you wanted to show what was there before you hid it you would have to re-draw it.

Code: Select all

``````    VGfloat clear_colour[4] = {0, 0, 0, 0};
vgSetfv(VG_CLEAR_COLOUR, 4, clear_colour);
vfClear(0, 0, width, height); // width and height are your window's width and height
// The openVG window is now transparent
// Next time you call Start() the window will be opaque again because it resets the clear colour.
``````
The only other way I can think of is by altering oglinit.c in the library to give you access to the dispman window, and when you want to hide the window you'd have to tell dispman to either push the layer behind the framebuffer layer or force it to be globally transparent, then put it back to how it was when you want to show it again. That would solve the problem of not having to clear the window, but is a bit more involved.
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

### Re: HDMI graphic lib: openvg syntax questions

thank you -
as you might have guessed I actually thought this feature about switching the windows had been already implemented...

now having a new display function

Code: Select all

``````void vghidewindow() {
VGfloat clear_colour[4] = {0, 0, 0, 0};
vgSetfv(VG_CLEAR_COLOUR, 4, clear_colour);
vfClear(0, 0, width, height); // width and height are your window's width and height
}``````
where would then start/end and init/finish have to be set?

Code: Select all

``````
#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() {
char s[3];
float val1, val2;
int width, height;

init(&width, &height);       // Graphics initialization
Start(width, height);       // Start the picture

vghidewindow();       // Hide  the picture  <<<<<<<<<<<<<<<<<<<<<<<<<<

printf("starting...\n");

// do some calculation
val1 = foo();
val2 = bas();
// print the result on stdout:
printf("%f\n", val1);
printf("%f\n", val2);
fgets(s, 2, stdin);   // wait for key press

// now output as a graph line  on a canvas
Start(width, height);     // Start the picture  <<<<<<<<<<<<<<<< visible again  : where is "End" ?

Line(0, val1, 0, val2);
fgets(s, 2, stdin);  // wait for key press

// do some new calculation
vghidewindow();       // Hide  the picture  <<<<<<<<<<<<<<<<<<<<<<<<<<
val1 = foo();
val2 = bas();
// print the result on stdout:
printf("%f\n", val1);
printf("%f\n", val2);
fgets(s, 2, stdin);  // wait for key press

// now output as a graph line on a canvas
Start(width, height);     // Start the picture  <<<<<<<<<<<<<<<< visible again:  where is "End" ?
Line(1, val1, 1, val2);
fgets(s, 2, stdin);  // wait for key press

// and so on
//...
printf("program ended...press key to quit"\n");
fgets(s, 2, stdin);   // wait for key press

End();           // End the picture

finish();          // Graphics cleanup
exit(0);
}
:?:

``````
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

Paeryn
Posts: 2783
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

### Re: HDMI graphic lib: openvg syntax questions

Init() is called at the start to create the window and Finish() is called when you have finished with the window. Typically right at the start, and right at the end.

Start() is called before you draw each scene, it clears the window ready for your drawing.
End() is called when you've drawn your scene, it draws all the queued drawing commands and shows it in your window. You won't see things being drawn as you draw them - only when you call End(). By the looks of the way ajstarks is doing things you can call End() multiple times to show things up to that point as the back buffer is preserved. But not when using the hide code, as that effectively clears the window (and you need to call Start() again to make it visible).

I forgot to put that you'll need to call End(); after the hide window code or call then needed eglSwapBuffers(); (that's really all End(); does) to copy it to the screen.

Code: Select all

``````void hidevgwindow() {
VGfloat clear_colour[4] = {0, 0, 0, 0};
vgSetfv(VG_CLEAR_COLOUR, 4, clear_colour);
vfClear(0, 0, width, height); // width and height are your window's width and height
End(); // You need this (or call eglSwapBuffers) to update the window.
// The openVG window is now transparent
// Next time you call Start() the window will be opaque again because it resets the clear colour, though the window won't appear until End() is called after the Start().
}
``````
So from your code, something along the lines of ...

Code: Select all

``````#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() {
char s[3];
float val1, val2;
int width, height;

init(&width, &height);       // Graphics initialization

// Start(width, height); // Not strictly needed here as hidevgwindow() does it's own start/end.
hidevgwindow();       // Hide  the picture

printf("starting...\n");

// do some calculation
val1 = foo();
val2 = bas();
// print the result on stdout:
printf("%f\n", val1);
printf("%f\n", val2);
fgets(s, 2, stdin);   // wait for key press

// now output as a graph line  on a canvas
Start(width, height);     // Start the picture  <<<<<<<<<<<<<<<< visible again <<< will be when End is called.

Line(0, val1, 0, val2);

End();  // Draw it to the window

fgets(s, 2, stdin);  // wait for key press

// If you want to display all lines later on you'll need to save the values so you can re-draw them.

// do some new calculation
val1 = foo();
val2 = bas();
// print the result on stdout:
printf("%f\n", val1);
printf("%f\n", val2);

hidevgwindow();  // Hide the window so you can see what was printed on the terminal

fgets(s, 2, stdin);  // wait for key press

Start(width, height); // Clear the VG window (won't be immediately visible, but will when End() is called).
// Previous image will have been lost so if you wanted both you would have had to have saved the previously drawn coordinates and draw them again.
// now output as a graph line on a canvas

// If you want the previous line displayed as well you'll need to re-draw it as it will have been removed by the hide.
Line(1, val1, 1, val2);

End();  // Draw the scene to the window.
fgets(s, 2, stdin);  // wait for key press

// and so on
//...
printf("program ended...press key to quit"\n");

hidevgwindow(); // Hide the window so we can see the message on the terminal
fgets(s, 2, stdin);   // wait for key press

// End();           // Not needed as you are finishing straight after.

finish();          // Graphics cleanup
exit(0);
}
``````
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

### Re: HDMI graphic lib: openvg syntax questions

that's really great, thank you a lot for your explanations!

I'll port it and try it with my actualy code (instead oof foo and bas) and then will report my results.
Thanks again!
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

### Re: HDMI graphic lib: openvg syntax questions

hi,
I just encountered that after start it's not immediately visible what I am drawing, but I need to watch each single drawing action one by one by sort of "live viewing".

e.g., for a performance simulation

Code: Select all

``````long test_graphics(){
int y=0;

for(y=0;y<100;++y) {
Background(0, 0, 0);            // Black background, clear schreen

Fill (0, 0, 0, 0);              // outlined Circle
Stroke (255, 255, 255, 1);
Circle(50, 40, 10);

Fill(255,255,255, 1);            // fill shape Circle
Circle(30, 24, 10);

Line(10, 10, 60, 60);           // just 2 intersecting lines
Line(50, 20, 90, 70);

Fill (0, 0, 0, 0);              // outlined Rect
Stroke (255, 255, 255, 1);
Rect(20, 20, 40, 40);

Fill(255,255,255, 1);           // fill shape Rect
Rect(65, 25, 20, 30);

Fill (0, 0, 0, 0);              // outlined Ellipse
Stroke (255, 255, 255, 1);
Ellipse(70, 30, 15, 20);
}
return y;
}``````
I need to watch all the 100x8 = 800 drawing actions in the moment they are commanded.

After that, the console screen has to be reactivated to show results, waiting for keypress,
then the next graphic test is performed ("live"),
then again the console screen has to be reactivated to show results, waiting for keypress.

Code: Select all

``````int main() {

unsigned long time0, x, y;
float s;
char  buf[120];
int width, height;
char str[3];

printf("initializing..."); printf("\n");
char str[3];

init(&width, &height);       // Graphics initialization
hidevgwindow();       // Hide  the picture

printf("start: press key \n");
fgets(str, 2, stdin);   // wait for key press

// now output graph on a canvas
Start(width, height);     // Start the picture  <<<<<<<<<<<<<<<< visible again <<< will be when End is called.

time0=timer();    // stopwatch timer
s=(float)test_graphics();  // << now perform the real-time graphic test "live"

runtime[7]=timer()-time0;  // stop runtime

fgets(str, 2, stdin);   // wait for key press

// print the result on stdout:
vghidewindow();  // Hide the window so you can see what was printed on the terminal
printf("graphics:  %6d", runtime[7]);

printf("next: press key \n");
fgets(str, 2, stdin);   // wait for key press

//...

// and so on
//...

hidevgwindow(); // Hide the window so we can see the message on the terminal

printf("program ended...press key to quit"\n");
fgets(s, 2, stdin);   // wait for key press

Finish();          // Graphics cleanup
exit(0);
}``````
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

### Re: HDMI graphic lib: openvg syntax questions

update:
now I have the following errors about vghidewindow:

Code: Select all

``````//vghidewindow test
//

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <stdint.h>
#include <time.h>
#include <sys/time.h>

#include "VG/openvg.h"
#include "VG/vgu.h"
#include "fontinfo.h"
#include "shapes.h"

uint32_t timer()
{
struct timeval now;
uint32_t ticks;
gettimeofday(&now, NULL);
ticks=now.tv_sec*1000+now.tv_usec/1000;
return(ticks);
}

long test_graphics(){
int y=0;

for(y=0;y<100;++y) {
Background(0, 0, 0);            // Black background, clear schreen

Fill (0, 0, 0, 0);              // outlined Circle
Stroke (255, 255, 255, 1);
Circle(50, 40, 10);

Fill(255,255,255, 1);            // fill shape Circle
Circle(30, 24, 10);

Line(10, 10, 60, 60);           // just 2 intersecting lines
Line(50, 20, 90, 70);

Fill (0, 0, 0, 0);              // outlined Rect
Stroke (255, 255, 255, 1);
Rect(20, 20, 40, 40);

Fill(255,255,255, 1);           // fill shape Rect
Rect(65, 25, 20, 30);

Fill (0, 0, 0, 0);              // outlined Ellipse
Stroke (255, 255, 255, 1);
Ellipse(70, 30, 15, 20);
}
return y;
}

void vghidewindow(int width, int height) {
VGfloat clear_colour[4] = {0, 0, 0, 0};
vgSetfv(VG_CLEAR_COLOUR, 4, clear_colour);
vfClear(0, 0, width, height); // width and height are your window's width and height
End(); // You need this (or call eglSwapBuffers) to update the window.
// The openVG window is now transparent
// Next time you call Start() the window will be opaque again because it resets the clear colour, though the window won't appear until End() is called after the Start().
}

int main() {

unsigned long time0, runtime[10];
float s;
char  buf[120];
int width, height;
char str[3];

printf("initializing..."); printf("\n");

init(&width, &height);       // Graphics initialization
vghidewindow(width, height);       // Hide  the picture

printf("start: press key \n");
fgets(str, 2, stdin);   // wait for key press

// now output graph on a canvas
Start(width, height);     // Start the picture  <<<<<<<<<<<<<<<< visible again <<< will be when End is called.

time0=timer();    // stopwatch timer
s=(float)test_graphics();  // << now perform the real-time graphic test "live"

runtime[7]=timer()-time0;  // stop runtime

fgets(str, 2, stdin);   // wait for key press

// print the result on stdout:
vghidewindow(width, height);  // Hide the window so you can see what was printed on the terminal
printf("graphics:  %6ld", runtime[7]);

printf("next: press key \n");
fgets(str, 2, stdin);   // wait for key press

//...

// and so on
//...

vghidewindow(width, height); // Hide the window so we can see the message on the terminal

printf("program ended...press key to quit\n");
fgets(str, 2, stdin);   // wait for key press

finish();          // Graphics cleanup
exit(0);
}

``````
g++ -Wall -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -c "vghidetest001.c" -lshapes -lpthread -lrt -lwiringPi (im Verzeichnis: /home/pi/programs/openvg)
vghidetest001.c: In function ‘void vghidewindow(int, int)’:
vghidetest001.c:60:13: error: ‘VG_CLEAR_COLOUR’ was not declared in this scope
vgSetfv(VG_CLEAR_COLOUR, 4, clear_colour);
^
Kompilierung fehlgeschlagen.
vghidetest001.c:61:32: error: ‘vfClear’ was not declared in this scope
vfClear(0, 0, width, height); // width and height are your window's width and height
^

#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

Paeryn
Posts: 2783
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

### Re: HDMI graphic lib: openvg syntax questions

davenull wrote:update:
now I have the following errors about vghidewindow:

Code: Select all

``````void vghidewindow(int width, int height) {
VGfloat clear_colour[4] = {0, 0, 0, 0};
vgSetfv(VG_CLEAR_COLOUR, 4, clear_colour);
vfClear(0, 0, width, height); // width and height are your window's width and height
End(); // You need this (or call eglSwapBuffers) to update the window.
// The openVG window is now transparent
// Next time you call Start() the window will be opaque again because it resets the clear colour, though the window won't appear until End() is called after the Start().
}
``````
g++ -Wall -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -c "vghidetest001.c" -lshapes -lpthread -lrt -lwiringPi (im Verzeichnis: /home/pi/programs/openvg)
vghidetest001.c: In function ‘void vghidewindow(int, int)’:
vghidetest001.c:60:13: error: ‘VG_CLEAR_COLOUR’ was not declared in this scope
vgSetfv(VG_CLEAR_COLOUR, 4, clear_colour);
^
Kompilierung fehlgeschlagen.
vghidetest001.c:61:32: error: ‘vfClear’ was not declared in this scope
vfClear(0, 0, width, height); // width and height are your window's width and height
^
Sorry, that was a couple of typos on my part... VG_CLEAR_COLOUR should be VG_CLEAR_COLOR (stupid American spelling), and vfClear should be vgClear (I pressed the wrong key).

As to needing to see each drawing as it happens, you need to call End() each time you want the screen to update as all drawing is done onto a hidden buffer and only copied to the screen on an eglSwapBuffers() command (and drawing commands are usually queued up and not started until the eglSwapBuffers() rather then being drawn as you issue them).

Code: Select all

``````long test_graphics(){
int y=0;

for(y=0;y<100;++y) {
Background(0, 0, 0);            // Black background, clear schreen
End();

Fill (0, 0, 0, 0);              // outlined Circle
Stroke (255, 255, 255, 1);
Circle(50, 40, 10);
End();

Fill(255,255,255, 1);            // fill shape Circle
Circle(30, 24, 10);
End();

Line(10, 10, 60, 60);           // just 2 intersecting lines
End();
Line(50, 20, 90, 70);
End();

Fill (0, 0, 0, 0);              // outlined Rect
Stroke (255, 255, 255, 1);
Rect(20, 20, 40, 40);
End();

Fill(255,255,255, 1);           // fill shape Rect
Rect(65, 25, 20, 30);
End();

Fill (0, 0, 0, 0);              // outlined Ellipse
Stroke (255, 255, 255, 1);
Ellipse(70, 30, 15, 20);
End();
}
return y;
}
``````
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

### Re: HDMI graphic lib: openvg syntax questions

thanks, now I slowly understand... end is not actually an "end" but more sort of vgUpdateWindow, right?
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

### Re: HDMI graphic lib: openvg syntax questions

hey,
I corrected the source, nevertheless something's still going wrong:

Code: Select all

``````// vghidewindow test
//

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <stdint.h>
#include <time.h>
#include <sys/time.h>

#include "VG/openvg.h"
#include "VG/vgu.h"
#include "fontinfo.h"
#include "shapes.h"

uint32_t timer()
{
struct timeval now;
uint32_t ticks;
gettimeofday(&now, NULL);
ticks=now.tv_sec*1000+now.tv_usec/1000;
return(ticks);
}

long test_graphics(){
int y=0;

for(y=0;y<100;++y) {
Background(0, 0, 0);            // Black background, clear schreen
End();

Fill (0, 0, 0, 0);              // outlined Circle
Stroke (255, 255, 255, 1);
Circle(50, 40, 10);
End();

Fill(255,255,255, 1);            // fill shape Circle
Circle(30, 24, 10);
End();

Line(10, 10, 60, 60);           // just 2 intersecting lines
End();
Line(50, 20, 90, 70);
End();

Fill (0, 0, 0, 0);              // outlined Rect
Stroke (255, 255, 255, 1);
Rect(20, 20, 40, 40);
End();

Fill(255,255,255, 1);           // fill shape Rect
Rect(65, 25, 20, 30);
End();

Fill (0, 0, 0, 0);              // outlined Ellipse
Stroke (255, 255, 255, 1);
Ellipse(70, 30, 15, 20);
End();
}
return y;
}

void vghidewindow(int width, int height) {
VGfloat clear_color[4] = {0, 0, 0, 0};
vgSetfv(VG_CLEAR_COLOR, 4, clear_color);
vgClear(0, 0, width, height); // width and height are your window's width and height
End(); // You need this (or call eglSwapBuffers) to update the window.
// The openVG window is now transparent
// Next time you call Start() the window will be opaque again because it resets the clear colour, though the window won't appear until End() is called after the Start().
}

int main() {

unsigned long time0, runtime[10];
float s;
char  buf[120];
int width, height;
char str[3];

printf("initializing..."); printf("\n");

init(&width, &height);       // Graphics initialization
vghidewindow(width, height);       // Hide  the picture

printf("start: press key \n");
fgets(str, 2, stdin);   // wait for key press

// now output graph on a canvas
Start(width, height);     // Start the picture  <<<<<<<<<<<<<<<< visible again <<< will be when End is called.

time0=timer();    // stopwatch timer
s=(float)test_graphics();  // << now perform the real-time graphic test "live"

runtime[7]=timer()-time0;  // stop runtime

fgets(str, 2, stdin);   // wait for key press

// print the result on stdout:
vghidewindow(width, height);  // Hide the window so you can see what was printed on the terminal
printf("graphics:  %6ld", runtime[7]);

printf("next: press key \n");
fgets(str, 2, stdin);   // wait for key press

//...

// and so on
//...

vghidewindow(width, height); // Hide the window so we can see the message on the terminal

printf("program ended...press key to quit\n");
fgets(str, 2, stdin);   // wait for key press

finish();          // Graphics cleanup
exit(0);
}

``````
g++ -Wall -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -o "vghidetest001" "vghidetest001.c" -lshapes -lpthread -lrt -lwiringPi (im Verzeichnis: /home/pi/programs/openvg)

Kompilierung fehlgeschlagen.
/usr/bin/ld: /tmp/ccg6jhrN.o: undefined reference to symbol 'vgClear'
//opt/vc/lib/libEGL.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

Paeryn
Posts: 2783
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

### Re: HDMI graphic lib: openvg syntax questions

davenull wrote:thanks, now I slowly understand... end is not actually an "end" but more sort of vgUpdateWindow, right?
Yes, Start() is used to put the instructions to clear the buffer and set default colours into the gpu's instruction list.
All the drawing commands add more instructions to the gpu's list.
End() says to the gpu "I've finished giving you the list of instructions, now go away and execute them for me and show me the result."

The DSO error is because the linker isn't finding the vgClear symbol for your file (it gets them for the shapes library ok). You can correct it by adding -L/opt/vc/lib -lOpenVG -lEGL to the compile line (although it will work without the -lOpenVG so I assume vgClear is pulled in from EGL) :-

Code: Select all

``````g++ -Wall -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -L/opt/vc/lib -o "vghidetest001" "vghidetest001.c" -lshapes -lOpenVG -lEGL -lpthread -lrt -lwiringPi
``````
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

### Re: HDMI graphic lib: openvg syntax questions

edit:
now it works!
And now finally the compiler makefile parameter list has exceeded the length of my program!

but just the outlined shapes don't seem to be displayed yet...
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

Paeryn
Posts: 2783
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

### Re: HDMI graphic lib: openvg syntax questions

davenull wrote:edit:
now it works!
And now finally the compiler makefile parameter list has exceeded the length of my program!

but just the outlined shapes don't seem to be displayed yet...
Ahh.. In ajstark's library for some reason he sets the line width to be 0 in Start(). So after calling Start() you need to set it back to 1 (or larger if you want thicker lines) with

Code: Select all

``````  Start(width, height);
vgSetf(VG_STROKE_LINE_WIDTH, 1);
``````
Although that will affect the Background() call (it draws a filled rectangle) so you might want to either set the line width to 0 before using Background() and back to whatever you want after or set the stroke colour to be the same colour as you are passing to Background().
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

### Re: HDMI graphic lib: openvg syntax questions

I'm afraid, that will become now REALLY weird :-/

tbh, I would appreciate a real DrawFIGURE API which works out of the box, just drawing border lines, no fill or background or anything which will muddle all up in the end...

e.g.,

Code: Select all

``````SetColor()
SetBrushwidth()
DrawCircle()
DrawEllipse()
DrawRect()
DrawPoly()
... and so on...
``````
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

Paeryn
Posts: 2783
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

### Re: HDMI graphic lib: openvg syntax questions

You don't need to stick with the use of Start() or the drawing routines etc if they don't fit with your needs. If you look at the code for it you could easily write your own versions, the shape drawing routines are mostly a few lines each.

I've got to stay in tomorrow morning so I'll look into writing suitable versions that will work on top of ajstarks' libray for you if you want.

Would SDL be more suited to your needs?
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

### Re: HDMI graphic lib: openvg syntax questions

If you look at the code for it you could easily write your own versions, the shape drawing routines are mostly a few lines each.
no sorry, I'm not that smart
I'm just a simple end-user, just some basic experience in programming Lego NXTs and Arduino, no clue about Raspi, C/C++ libs, not even Linux or makefile - this is only a HUGE Mumbo Jumbo to me.

I'm only able to use libs which provide simple API functions and work out of the box, I don't see through anything of either code or OS or hardware levels below or beyond

So if anyone will be able and willing to write some additional functionality - : I would greatly appreciate this, of course!

about SDL - never heard so far...
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

Paeryn
Posts: 2783
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

### Re: HDMI graphic lib: openvg syntax questions

I decided to write it tonight... Hope this helps, it's basically a small library that is to be used with ajstark's, it provides extra shape functions that are outlines of the filled ones in libshapes, all the shapes have the word Outline after e.g. Rect() becomes RectOutline() to draw just the lines, no need to keep changing the fill to transparent.

ClearWindowRGB(int w, int h, int r, int g, int b) this clears the window and remembers the size and colour. Use this right at the start or whenever you want to change the background colour - no need to use Background() to set your own background colour anymore. Implicit alpha of 1.0 (opaque), use ClearWindowRGBA() if you really want to set the alpha. This function must be called before you can use ClearWindow() or HideWindow() otherwise they won't affect the display (as they won't know how big the window is).

ClearWindowRGBA(int w, int h, int r, int g, int b, float a) as above but allows you to set the background alpha - just in case you want to.

ClearWindow() to be used where Start() was used, it clears the window according to the colour and size set in ClearWindowRGB() and doesn't reset fill or stroke colours or line width like Start() does.

HideWindow() to be used to make the window invisible. All queued drawing instructions will be flushed and the window cleared, it does an implicit ClearWindow() so you can start drawing your new scene straight away, the window will come back the moment you call End()

Link to the files :- https://www.dropbox.com/s/h37po1q305eab ... ar.gz?dl=0
I modified your test program to use these new functions - that is demo.c
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

### Re: HDMI graphic lib: openvg syntax questions

thank you very much for your efforts!
As I'm completely new to C and Linux, just a couple of questions:

to load it down on my Raspi where I have no unzip or rar program AFAIK - how can I install it ?
I assume there will be no way by apt-get install, or is it?
(my Raspi screen is very small for navigating in the internet though!)
When finally downloaded and unzipped: Can I copy the files into my VG directory to have all them at 1 place?
Will the paths then be detected correctly if I call the new functions from my programs from my different working and project directories?

Finally:
Do I have to add even more extra parameter settings in my Geany IDE additionally ?

And last, but not least: is it possible to simplify the whole Geany parameters/properties for compile and make with respect to the whole openvg features?
Already it's extremely much to write:

Code: Select all

``````Geany settings for compile:

Geany settings for make:
g++ -Wall -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -o "%e" "%f" -lshapes -L/opt/vc/lib -lOpenVG -lEGL -lpthread -lrt -lwiringPi``````
like for pigpio, just one
-lpigpio
in the make parameter list
and just one
#include <pigpio>
in my programs should fit - that would be fine, if possible.
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

Paeryn
Posts: 2783
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

### Re: HDMI graphic lib: openvg syntax questions

davenull wrote:thank you very much for your efforts!
As I'm completely new to C and Linux, just a couple of questions:

to load it down on my Raspi where I have no unzip or rar program AFAIK - how can I install it ?
I assume there will be no way by apt-get install, or is it?
(my Raspi screen is very small for navigating in the internet though!)
When finally downloaded and unzipped: Can I copy the files into my VG directory to have all them at 1 place?
Will the paths then be detected correctly if I call the new functions from my programs from my different working and project directories?
Sorry, standard linux tools used :-

Code: Select all

``````tar xjvf shapes_plus.tar.gz
``````
will create a new directory in the current one calles shapes_plus and extract the files there.
There is a Makefile that does exactly the same as the one in ajstarks', except the library is called libshapes_plus. Running make will build it (it's only one source file and one header). You can copy the resultant libshapes_plus.so and the header file shaple_plus.h to the same directory as the rest of your program, or do the sudo make install to copy the library and include file to the usual directories so it will always be found.
davenull wrote:Finally:
Do I have to add even more extra parameter settings in my Geany IDE additionally ?

And last, but not least: is it possible to simplify the whole Geany parameters/properties for compile and make with respect to the whole openvg features?
Already it's extremely much to write:

Code: Select all

``````Geany settings for compile:

Geany settings for make:
g++ -Wall -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -o "%e" "%f" -lshapes -L/opt/vc/lib -lOpenVG -lEGL -lpthread -lrt -lwiringPi``````
like for pigpio, just one
-lpigpio
in the make parameter list
and just one
#include <pigpio>
in my programs should fit - that would be fine, if possible.
Yes, just an extra #include "shapes_plus.h" right after you already you #include "shapes.h" in your source file and -lshapes_plus right after -lshapes on the link line should do the trick. If you just copy the library to your source code directory then you'd need an extra -L. to tell the linker to look in the current directory.

You don't need to include library parameters (-lshapes -lpthread -lrt -lwiringPi) when compiling source code to object files as you aren't doing the linking.

Code: Select all

``````Geany settings for compile:
g++ -Wall -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -c "%f"

Geany settings for make:
g++ -Wall -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -o "%e" "%f" -lshapes -lshapes_plus -L/opt/vc/lib -lOpenVG -lEGL -lpthread -lrt -lwiringPi
``````
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

### Re: HDMI graphic lib: openvg syntax questions

thank you, but I don't understand what to do now, I'm lost in all those explanations, I really needed a step-by-step guide.
How do I get the files on my Raspi,
where to store,
then to apply tar, ok, but by which command exactly? for which name does xjvf stand for?
and then how to kick off all unneeded -lxxx and -Ixxx stuff and substitute by what?

all I am able to do so far is using
sudo apt-get
and
git clone
so far.
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}