Voidious
Posts: 15
Joined: Mon Aug 20, 2012 8:05 pm

Re: Example program to draw random shapes using the C compil

Fri Sep 14, 2012 6:01 am

Ok, so the answer seems obvious after getting more familiar with all this OpenVG stuff... The real fast way to do things is to create paths for the shapes I want to use up front, then use transformations to translate / rotate / scale a path each time I want to draw one of it. Unfortunately this means doing almost everything manually with the OpenVG API instead of having the luxury of ajstarks' awesome library functions ;), but it also means the order of magnitude speed increase I was looking for.

User avatar
kulminaator
Posts: 23
Joined: Mon Aug 06, 2012 8:55 am
Location: estonia

Re: Example program to draw random shapes using the C compil

Fri Sep 14, 2012 7:46 am

spot on Voidious ... ajstarks library is nice for prototyping, but for speed you need a different approach


(ps. if you can, unhook/make abstract the bcm/rpi specifics as much as you can in your code, so the developers on other arm implementations could reuse and recompile your code to run on theirs with minor modifications (the openvg lib interface itself is the same for other arm platforms, just the screen initialization differs))

Chinasaur
Posts: 116
Joined: Tue Sep 11, 2012 10:15 pm

Re: Example program to draw random shapes using the C compil

Tue Sep 18, 2012 9:28 pm

The vgfont library provided in hello_pi handles fonts by building a memory cache of the different font sizes that have run so far; you could do a similar thing with shapes you want to use. The vgfont cache gets built on demand each time you use a new font size; I believe that's why in the hello_font example the first time through it runs more slowly and then on subsequent loops it is fast. So you might need to precache some things rather than lazy cache them.

Chinasaur
Posts: 116
Joined: Tue Sep 11, 2012 10:15 pm

Re: Example program to draw random shapes using the C compil

Wed Sep 19, 2012 1:43 am

Hmm, but this brings up the question: wouldn't it be better to just cache one font size and use transformations to do the different sizes? I'm planning to dig into the font stuff a little anyway, so will take a look.

Chinasaur
Posts: 116
Joined: Tue Sep 11, 2012 10:15 pm

Re: Example program to draw random shapes using the C compil

Wed Sep 19, 2012 1:45 am

Voidious wrote:The real fast way to do things is to create paths for the shapes I want to use up front, then use transformations to translate / rotate / scale a path each time I want to draw one of it. Unfortunately this means doing almost everything manually with the OpenVG API instead of having the luxury of ajstarks' awesome library functions ;)
Seems like should be fine to make an updated library that uses the transformation approach?

Chinasaur
Posts: 116
Joined: Tue Sep 11, 2012 10:15 pm

Re: Example program to draw random shapes using the C compil

Wed Sep 19, 2012 3:58 am

Chinasaur wrote:Hmm, but this brings up the question: wouldn't it be better to just cache one font size and use transformations to do the different sizes? I'm planning to dig into the font stuff a little anyway, so will take a look.
Oh right, the caching of different sizes is supposed to be for font hinting ...

bloodline
Posts: 76
Joined: Sun Jun 10, 2012 8:44 pm
Location: London - England

Re: Example program to draw random shapes using the C compil

Tue Oct 02, 2012 10:31 am

Since the new (2012/09/19) Pi firmware, my Pi seems to be working much better and also runs 950Mhz! So I'm able to get back into some OpenVG stuff again.

Quick question, does the OpenVG lib support vertical blanking sync?

bloodline
Posts: 76
Joined: Sun Jun 10, 2012 8:44 pm
Location: London - England

Re: Example program to draw random shapes using the C compil

Tue Oct 02, 2012 3:07 pm

Chinasaur wrote:
Voidious wrote:The real fast way to do things is to create paths for the shapes I want to use up front, then use transformations to translate / rotate / scale a path each time I want to draw one of it. Unfortunately this means doing almost everything manually with the OpenVG API instead of having the luxury of ajstarks' awesome library functions ;)
Seems like should be fine to make an updated library that uses the transformation approach?
This is the approach I have been taking... but I clearly don't understand the pipeline properly as a path seems to be invlidated after it is rastorized... I can't figure it out :(

bloodline
Posts: 76
Joined: Sun Jun 10, 2012 8:44 pm
Location: London - England

Re: Example program to draw random shapes using the C compil

Tue Oct 02, 2012 3:45 pm

Actually the OpenVG error code I'm getting is 4096... not sure what that means? Why can I not find any documentation for OpenVG?!

bloodline
Posts: 76
Joined: Sun Jun 10, 2012 8:44 pm
Location: London - England

Re: Example program to draw random shapes using the C compil

Wed Oct 03, 2012 1:16 pm

Many appologies for spamming this topic. But I have managed to figure out where I was going wrong.

Once a path has been created, you can cache it and use it over and over again. With little performance penalty.

If you want to draw the path at another location, I can't see any translation functions to move all the points along the path? So one can do as Anthony has done and simply destroy the old path and create a new one. This is slow. A quicker way is to clear the path and put new points in it... But this is quicker, but is still not acceptable for highspeed animation.

My feeling is that one needs to use the paths to draw to a surface/texture and then move that around the screen.

Does that sound correct?

User avatar
ajstarks
Posts: 129
Joined: Fri Jun 22, 2012 2:14 am

Re: Example program to draw random shapes using the C compil

Thu Oct 04, 2012 12:02 am

A great source of information on OpenVG can be found on the Khronos website:

OpenVG Specification: http://www.khronos.org/registry/vg/specs/openvg-1.1.pdf
Reference Card: http://www.khronos.org/files/openvg-qui ... e-card.pdf

These should help your understanding of the details.

arturo777
Posts: 28
Joined: Sat Mar 24, 2012 10:02 am

Re: Example program to draw random shapes using the C compil

Thu Oct 04, 2012 8:06 am

I guess you probably want to change the transform matrix, using a combination of vgGetMatrix, vgTranslate (and maybe vgRotate and vgScale) and vgLoadMatrix. This should allow you to redraw the same path in a different location without changing the underlying path.

Drawing to a surface or texture would be more suitable for doing layering, e.g. working with different opacity levels.

User avatar
jwzumwalt
Posts: 44
Joined: Sun Aug 04, 2013 4:00 pm

Re: Example program to draw random shapes using the C compil

Thu Oct 10, 2013 6:54 am

ajstarks wrote:See: https://gist.github.com/3186193 for an example program that draws random shapes on the Raspberry Pi:
Thanks for the example this has been immensely helpful in seeing how VG handles basic geometric shapes.

User avatar
ajstarks
Posts: 129
Joined: Fri Jun 22, 2012 2:14 am

Re: Example program to draw random shapes using the C compil

Thu Oct 10, 2013 11:12 am

jwzumwalt wrote:
ajstarks wrote:See: https://gist.github.com/3186193 for an example program that draws random shapes on the Raspberry Pi:
Thanks for the example this has been immensely helpful in seeing how VG handles basic geometric shapes.
Also check out https://github.com/ajstarks/openvg for a library built from the example.

User avatar
jwzumwalt
Posts: 44
Joined: Sun Aug 04, 2013 4:00 pm

Re: Example program to draw random shapes using the C compil

Tue Oct 29, 2013 7:08 pm

Thanks ajstarks,

For anyone trying this code be aware that there is a misspelled file name with the source download.
Until the author fixes it...

The Git hub listing also has the wrong file name
font2opencv.cpp should be font2openvg.cpp

It's a great program!
ajstarks wrote:In this update:

https://gist.github.com/3196007

I've added more shapes (lines, polygon, polyline, cubic and quadratic bezier curves, arc, circles) and the ability to control the number of objects on the command line.

Here's the Makefile:

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 
to run it:

1) download the gist, save it as shapes.c
2) copy the Makefile to the same directory
3) make && ./shapes 100
4) just press [Enter] to clear the screen and return

During development, on my Mac sitting next the RasPi, I open two terminals and ssh into the RasPi with each. In one terminal, I edit the file, in the other, issue the make && ./shapes command to see the result.

User avatar
ajstarks
Posts: 129
Joined: Fri Jun 22, 2012 2:14 am

Re: Example program to draw random shapes using the C compil

Thu Oct 31, 2013 10:17 pm

sorry, I don't see the mis-spelling

User avatar
Paeryn
Posts: 2143
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Example program to draw random shapes using the C compil

Fri Nov 01, 2013 2:31 am

ajstarks wrote:sorry, I don't see the mis-spelling
The file that should be named font2openvg.cpp is incorrectly named font2opencv.cpp
When you download from the link given (https://gist.github.com/3196007) the four files in the archive are :-

DejaVuSans.inc
font2opencv.cpp
Makefile
shapes.c

This is only in the gist, not the full git
She who travels light — forgot something.


olso4539
Posts: 30
Joined: Mon Feb 03, 2014 9:02 pm

Re: Example program to draw random shapes using the C compil

Fri Jul 25, 2014 6:36 pm

Voidious wrote:Just finished quite a bit of fiddling. Got a ~10% gain from removing the red/green/blue/alpha size = 8 settings from the attribute_list for eglChooseConfig, and another ~15% by caching and re-using the VGPaths and VGPaints (also need to clear the VGPaths) instead of repeatedly creating and destroying them.

So I went from ~38 to ~47 FPS when I'm drawing 4 rectangles, 10 circles, and 10 line segments. Which I'm pretty happy about, but it still feels a few orders of magnitude from where it could be. =)

Edit: And further on up to ~51 FPS by eliminating a bunch of calls to setstroke / setfill / StrokeWidth, drawing the 10 same colored circles and then the 10 same colored line segments instead of alternating.
OpenVG on the raspberry pi is capable of much, much faster drawing. I'm working on a plotting application that draws around ~8000 line segments per frame at 60 fps. While the library that ajstarks built is pretty awesome, it can't compete with digging into the openVG specification and doing optimizations.
https://github.com/olso4539/HSDMPi

rodizio
Posts: 39
Joined: Sat May 07, 2016 2:40 am

Re: Example program to draw random shapes using the C compil

Fri Nov 04, 2016 2:33 pm

I'm using this code based on the OpenVG library to display an on screen display (text and graphical elements) on the Raspberry:
https://github.com/SamuelBrucksch/wifibroadcast_osd

Now I would like to rotate the whole OSD (i.e. everything) 270 degrees since I'm using a portrait mode 1080x1920 screen in landscape orientation. Is there a simple way to do that with OpenVG?

User avatar
Paeryn
Posts: 2143
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Example program to draw random shapes using the C compil

Fri Nov 04, 2016 5:13 pm

rodizio wrote:I'm using this code based on the OpenVG library to display an on screen display (text and graphical elements) on the Raspberry:
https://github.com/SamuelBrucksch/wifibroadcast_osd

Now I would like to rotate the whole OSD (i.e. everything) 270 degrees since I'm using a portrait mode 1080x1920 screen in landscape orientation. Is there a simple way to do that with OpenVG?
You can use vgRotate(angle); to set a rotation, all subsequent drawing will have the transformation applied until the transform matrix gets reset. Note that there are 5 separate transform matricies, the three main ones are VG_MATRIX_PATH_USER_TO_SURFACE, VG_MATRIX_IMAGE_USER_TO_SURFACE, VG_MATRIX_GLYPH_USER_TO_SURFACE, by default you will be manipulating the path matrix, you change which matrix to modify with vgSeti (VG_MATRIX_MODE, matrix);. You can reset the matrix back to default with vgLoadIdentity().

PATH affects paths, IMAGE affects images and GLYPH affects fonts. So if you draw shapes and images you need to rotate both matricies, similarly if you draw fonts with the glyph routines you need to rotate the glyph matrix.

Rotation happens around (0,0) so you may need to translate with vgTranslate (x,y,z) as well.
She who travels light — forgot something.

rodizio
Posts: 39
Joined: Sat May 07, 2016 2:40 am

Re: Example program to draw random shapes using the C compil

Sat Nov 05, 2016 3:19 pm

Thanks for the good explanation, will give it a try. The thing with the rotation around 0,0 probably explains why stuff didn't show up anymore with my failed attempts so far, I rotated it off the screen :)

User avatar
Paeryn
Posts: 2143
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Example program to draw random shapes using the C compil

Sat Nov 05, 2016 4:13 pm

rodizio wrote:Thanks for the good explanation, will give it a try. The thing with the rotation around 0,0 probably explains why stuff didn't show up anymore with my failed attempts so far, I rotated it off the screen :)
If you want to rotate around a given point (like the centre of the screen) you need to translate before and after the rotate, something like

Code: Select all

vgTranslate(width/2.0f, height/2.0f);
vgRotate(270); // or 90 depending on which way
vgTranslate(-width/2.0f, -height/2.0f);
She who travels light — forgot something.

Return to “OpenVG”

Who is online

Users browsing this forum: No registered users and 1 guest