Page 2 of 3

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

Posted: Tue Aug 14, 2012 12:29 am
by ajstarks
The library now supports images: https://github.com/ajstarks/openvg

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

Posted: Tue Aug 14, 2012 7:11 pm
by kulminaator
great work on openvg :)

i played around with the original program from the the top of the thread:

moved srand out from the rshapes() , threw the the rshapes inside of the while and added some timing stuff to make it last for 10 seconds and counting the frames during that ... whilst the drawing stuff isn't very optimized in the original code, it shows how anyone would design their code out of the box ... so it shows something :)

3000 shapes : 0.7fps
1000 shapes : 1.9fps
100 shapes: 18.7fps
50 shapes: 34.7fps
20 shapes: ~60fps
10 shapes: ~60fps (i guess the bottom line here is that at some point the fps just maxes out due to refresh rate or smth like that)

definitely enough for kids to pull off their first 2D games or animations (and with a little help from the tutor the framerate can improve a lot).

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

Posted: Tue Aug 14, 2012 10:37 pm
by ajstarks
@kulminaator care to share your code? Note that the code on https://github.com/ajstarks/openvg has changed a bit from the original.

Note that you may be seeing CPU vs. GPU limitations -- the time to compute the shape attributes vs. the time to display.

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

Posted: Thu Aug 16, 2012 3:05 pm
by kulminaator
i threw the modified code here :
http://pastebin.com/TuLTEqpq

* note that the time estimation is done on full seconds, so it's not extremely accurate, but accurate enough for reasonable tests.

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

Posted: Tue Aug 21, 2012 5:11 am
by ajstarks
In https://github.com/ajstarks/openvg

More API cleanup, added color and two new text functions.
Updated the documentation to include a "hello, world" example:

Code: Select all

//
// first OpenVG program
// Anthony Starks ([email protected])
//
// compile and run on the Raspberry Pi:
// cc -Wall -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -o hellovg hellovg.c -L/opt/vc/lib -lGLESv2 -ljpeg && ./hellovg
//
//
#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;
	init(&width, &height);     // OpenGL, etc 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
	TextMiddle(width/2, height/2, 
	"hello, world", SerifTypeface, width/10); // Greetings 
	End();                                    // End the picture

	while (getchar() != '\n')  // look at the pic, end with [RETURN]
		;

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


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

Posted: Mon Aug 27, 2012 9:52 am
by bloodline
Hi ajs,

I did a fresh checkout of your latest code, ran make and then ./shapdemo... but something must be wrong with the linking as the program errors with :

./shapedemo: error while loading shared libraries: libGLESv2.so: cannot open shared object file: No such file or directory

I don't really understand make so I can't see if anything is wrong there?

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

Posted: Mon Aug 27, 2012 10:02 am
by ajstarks
I saw this too. You need to update to the latest firmware. After running rpi-update all it well.
See: https://github.com/Hexxeh/rpi-update

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

Posted: Mon Aug 27, 2012 10:13 am
by bloodline
Nice One!

I haven't updated my firmware separately from the main distribution for ages!

Cheers

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

Posted: Mon Aug 27, 2012 10:26 am
by PeterO
Very useful !!

One point (that may have been made already) is that this won't work if you have the RAM for the GPU set to the lowest figure (32M). It needs at least 64M of GPU RAM to work.

PeterO

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

Posted: Mon Aug 27, 2012 10:36 am
by bloodline
Oops... rpi-update killed my pi...

Nothing but a flashing "OK" led :-(

I'll have to see what's wrong with the latest firmware...

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

Posted: Mon Aug 27, 2012 10:45 am
by ajstarks
@bloodline: very sorry to hear that. Did the process complete? It does take a while to run.

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

Posted: Mon Aug 27, 2012 10:50 am
by bloodline
Yeah, the process went through fine, no errors.

All the files on the boot partition look good (all updated to today's date).

Would you be kind enough to zip up your kernel.img and start.elf... I'll copy them over and see if that boots :) cheers

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

Posted: Mon Aug 27, 2012 2:56 pm
by pwinwood
I had this too. I had recently updated to the latest build (Friday Aug 24). I found that the executable bit for the .so files in /opt/vc/lib was not set. To fix this

cd /opt/vc/lib
sudo chmod +x *.so
sudo ldconfig

and all was well again.

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

Posted: Tue Aug 28, 2012 10:18 am
by bloodline
pwinwood wrote:I had this too. I had recently updated to the latest build (Friday Aug 24). I found that the executable bit for the .so files in /opt/vc/lib was not set. To fix this

cd /opt/vc/lib
sudo chmod +x *.so
sudo ldconfig

and all was well again.

Good advice! Cheers.

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

Posted: Tue Aug 28, 2012 11:09 am
by dom
pwinwood wrote:I had this too. I had recently updated to the latest build (Friday Aug 24). I found that the executable bit for the .so files in /opt/vc/lib was not set. To fix this

cd /opt/vc/lib
sudo chmod +x *.so
sudo ldconfig

and all was well again.
Sorry, don't agree. The shared objects in /opt/vc/lib have never had the execute bit set, and nor should they.

ldconfig may need to be run on occasion when the libs change, although rpi-update does that for you.

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

Posted: Tue Aug 28, 2012 11:27 am
by pwinwood
dom wrote:
pwinwood wrote:I had this too. I had recently updated to the latest build (Friday Aug 24). I found that the executable bit for the .so files in /opt/vc/lib was not set. To fix this

cd /opt/vc/lib
sudo chmod +x *.so
sudo ldconfig

and all was well again.
Sorry, don't agree. The shared objects in /opt/vc/lib have never had the execute bit set, and nor should they.

ldconfig may need to be run on occasion when the libs change, although rpi-update does that for you.
You are quite right, the execute bit did not need to be set. Something must have upset ldconfig.
I removed the execute bits again and all was still well.
Previously I had run apt-get update/upgrade and rpi-update.

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

Posted: Wed Aug 29, 2012 12:52 am
by ajstarks
Here is the Raspberry Pi self-portrait, drawn with OpenVG.

The picture:

http://www.flickr.com/photos/ajstarks/7 ... hotostream

The code:

Code: Select all

void makepi(VGfloat x, VGfloat y, int w, int h) {
	// dimensions
	VGfloat socw = h / 5,
	    compw = h / 5,
	    cjw = h / 10,
	    cjh = h / 8,
	    audw = h / 5,
	    aujw = h / 10,
	    aujh = cjh / 2,
	    hdw = w / 6,
	    hdh = w / 10,
	    gpw = w / 3,
	    gph = h / 8,
	    pw = h / 10,
	    usw = w / 5,
	    ush = h / 5,
	    etw = w / 5,
	    eth = h / 5,
	    sdw = w / 6, sdh = w / 4, 
            offset = (w / 2) / 10, 
            w34 = (w * 3) / 4, 
            w2 = w / 2, 
            h2 = h / 2, h40 = (h * 2) / 5;

	Fill(0, 128, 0, 1);
	Rect(x, y, w, h);	// board

	Fill(255, 255, 0, 1);
	Rect(x + w2, (y + h) - compw, compw, compw);	// composite
	Fill(192, 192, 192, 1);
	Rect(x + w2 + (cjw / 2), y + h, cjw, cjh);	// composite jack

	Fill(0, 0, 0, 1);
	Rect(x + w34, y + h - audw, audw, audw);	       // audio
	Rect(x + w34 + (aujw / 2), y + h, aujw, aujh);	       // audio jack

	Fill(192, 192, 192, 1);
	Rect(x + w2, y, hdw, hdh);	                                        // HDMI
	Rect((x + w) - etw, y, etw, eth);	                                // Ethernet
	Rect((x + w + offset) - usw, y + h40, usw, ush);	// USB
	Rect(x, y, pw, pw);	                                                // Power

	Fill(0, 0, 0, 1);
	Rect(x + (w * 2) / 5, y + h40, socw, socw);	        // SoC
	Rect(x, (y + h) - gph, gpw, gph);	                               // GPIO
	Fill(0, 0, 255, 1);
	Rect(x - sdw, (y + h2) - (sdh / 2), sdw, sdh);	      // SD card
}


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

Posted: Sat Sep 01, 2012 8:49 am
by bloodline
Just updated to latest kernel and now I'm getting another error...

oglinit.c:79: oglinit: Assertion `state->surface != ((EGLSurface)0)' failed.
Aborted

Lol, this is getting a bit frustrating... but I guess the Pi OS is still work in progress :)

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

Posted: Sat Sep 01, 2012 8:58 am
by bloodline
Hmmm, omxplayer is also failing, though more silently... Something is wrong with the openVG drivers :-/

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

Posted: Sat Sep 01, 2012 9:26 am
by dom
bloodline wrote:Hmmm, omxplayer is also failing, though more silently... Something is wrong with the openVG drivers :-/
Sound like you're on the wrong memory split.
You'll need 128M or 192M split to use GPU.

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

Posted: Sun Sep 09, 2012 8:08 pm
by Voidious
Another big thanks for help getting some graphics going on the Raspberry Pi. I'm having a lot more fun with it because of you. =)

I was wondering, do you have any license attached to all your Rpi OpenVG code? I couldn't find anything in the threads or GitHub. I've been using some code from your rshapes demo in a game I've been working on. I'm happy to give credit, but I tend to stick to permissive licenses or public domain, so if it's GPL I'll have to figure something else out.

Thanks!

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

Posted: Mon Sep 10, 2012 9:07 am
by ajstarks
The code is now MIT-licensed. Any form of attribution would be nice.

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

Posted: Mon Sep 10, 2012 9:43 am
by bloodline
I want to second, that! Many thanks again to Anthony for his work on this...

Unfortunately, my pi seems to fail during the POST when using the 32Meg Gfx start.elf it could just be me doing something wrong and I haven't had time to figure it out yet.

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

Posted: Thu Sep 13, 2012 3:41 am
by Voidious
Hmm... I'm seeing surprisingly low frame rate here when I'm drawing more than a few shapes. Like if I'm drawing 4 rectangles, 20 circles, and 20 line segments each time, I'm down to 20-something FPS. It's a solid 60 at 5 circles/5 lines. I'm at a 128/128 split atm but saw no difference vs 192/64. And 1920x1080 resolution.

Any idea if/how I could look into improving this? Is this just how it is with OpenVG on the Raspberry Pi? I'll live if that's so, but considering the frame rate folks are getting for things like Quake, it seems hard to believe. I'm trying to dig into it but all this graphics programming is pretty new to me.

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

Posted: Thu Sep 13, 2012 6:20 am
by Voidious
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.