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

Tue Aug 14, 2012 7:11 pm

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).

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

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

Tue Aug 14, 2012 10:37 pm

@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.

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

Thu Aug 16, 2012 3:05 pm

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.

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

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

Tue Aug 21, 2012 5:11 am

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 (ajstarks@gmail.com)
//
// 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);
}


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

Mon Aug 27, 2012 9:52 am

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?

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

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

Mon Aug 27, 2012 10:02 am

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

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

Mon Aug 27, 2012 10:13 am

Nice One!

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

Cheers

User avatar
PeterO
Posts: 4164
Joined: Sun Jul 22, 2012 4:14 pm

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

Mon Aug 27, 2012 10:26 am

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
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

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

Mon Aug 27, 2012 10:36 am

Oops... rpi-update killed my pi...

Nothing but a flashing "OK" led :-(

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

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

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

Mon Aug 27, 2012 10:45 am

@bloodline: very sorry to hear that. Did the process complete? It does take a while to run.

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

Mon Aug 27, 2012 10:50 am

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

pwinwood
Posts: 74
Joined: Mon Jul 02, 2012 2:21 am
Location: Oxford, England

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

Mon Aug 27, 2012 2:56 pm

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.

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 Aug 28, 2012 10:18 am

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.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5140
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

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

Tue Aug 28, 2012 11:09 am

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.

pwinwood
Posts: 74
Joined: Mon Jul 02, 2012 2:21 am
Location: Oxford, England

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

Tue Aug 28, 2012 11:27 am

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.

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

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

Wed Aug 29, 2012 12:52 am

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
}


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

Sat Sep 01, 2012 8:49 am

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 :)

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

Sat Sep 01, 2012 8:58 am

Hmmm, omxplayer is also failing, though more silently... Something is wrong with the openVG drivers :-/

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5140
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

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

Sat Sep 01, 2012 9:26 am

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.

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

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

Sun Sep 09, 2012 8:08 pm

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!

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

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

Mon Sep 10, 2012 9:07 am

The code is now MIT-licensed. Any form of attribution would be nice.

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

Mon Sep 10, 2012 9:43 am

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.

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

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

Thu Sep 13, 2012 3:41 am

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.

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

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

Thu Sep 13, 2012 6:20 am

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.

Return to “OpenVG”

Who is online

Users browsing this forum: No registered users and 0 guests