TheManWhoWas
Posts: 50
Joined: Thu Feb 09, 2012 9:11 pm

Re: 3D

Mon Apr 30, 2012 9:57 pm

What interfaces exist for getting at the 3D capabilities of the GPU on the RPi?

I presume there is a low level OpenGL ES library for C/C++, but are any of the following supported (or in development):


PyGame - accelerated 2D rather than software rendered
Panda3D - or any other Python 3D lib
WebGL - does Midori or whatever browser support this on the RPi?

Also, can you use PyGame / Panda3D / any other Python GFX lib without first starting up the LXDE desktop?

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23399
Joined: Sat Jul 30, 2011 7:41 pm

Re: 3D

Mon Apr 30, 2012 10:04 pm

I can only answer about the low level stuff. There are libraries supplied that are API compatible with the mesa 3D libraries on Linux. They are for OpenGLES, OpenVG and EGL. There's also an OpenMAX libraries, but there isn't a 'standard' for that on Linux IIRC.

If any of other libraries you mentioned use these libraries 'under the skin' then they should also work.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

TheManWhoWas
Posts: 50
Joined: Thu Feb 09, 2012 9:11 pm

Re: 3D

Tue May 01, 2012 2:52 pm

Thanks James, though surprised there are no other answers.

So outside of writing stuff in C/C++ there is no way to use the GPUs capabilities from Python or JavaScript or any other scripting language presently?

mole125
Posts: 228
Joined: Tue Jan 10, 2012 2:01 pm

Re: 3D

Tue May 01, 2012 3:00 pm

It may be worth people looking at kivy (http://kivy.org/#home), it is a python library built on top of pyGame (and other libraries) but with OpenGL ES support for UI and graphics (2d not 3d from what I can tell). I've no idea if anybody has tried compiling and running it on the RPi yet though.

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

Re: 3D

Tue May 01, 2012 3:07 pm

Raspberry Pi specific python bindings for opengles here:

https://github.com/peterderivaz/pyopengles

Includes a nice mandelbrot/julia set example.

User avatar
Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: 3D

Tue May 01, 2012 4:08 pm

Can someone provide an end-to-end description of running one of the canonical OpenGL demo examples (e.g., hello_triangle.py) in Python in an X window on the LXDE desktop on Debian on the Pi?  There have been statements that this should be possible, but, I haven't seen where anyone has actually done it.

I'll do the work of converting that description into a wiki article on  http://elinux.org/RaspberryPiBoard, complete with screenshots, descriptions that even a complete noob could understand, etc.  I'll then expand it to include all of the other canonical demos, a conversion of my spinning Earth WebGL example into OpenGL ES 2.0 running in Python in an X window in LXDE on Debian on the Pi, and then some simple game examples, etc.

Thanks!
The best things in life aren't things ... but, a Pi comes pretty darned close! :D
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

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

Re: 3D

Tue May 01, 2012 5:16 pm

@Jim You cannot create openGL ES content in an X window.

The best you can do is to render to an off screen surface and call glGetPixels and put those in the X window.

You will of course get much better performance running full screen.

TheManWhoWas
Posts: 50
Joined: Thu Feb 09, 2012 9:11 pm

Re: 3D

Tue May 01, 2012 8:43 pm

Let me just check my understanding of what's been said:

If you want to do any hardware accelerated 3D (or 2D) from a Python program, you will need to run it from the command line and access the OpenGL ES low level stuff directly.

Higher level libraries like PyGame or Panda3D need to run on LXDE (or do they?) and so will be software rendered (or I guess won't work in the case of Panda3D).

And WebGL also won't work for the same reason, because the browser needs to run on the desktop.

Is this right?

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

Re: 3D

Tue May 01, 2012 9:20 pm

TheManWhoWas said:

If you want to do any hardware accelerated 3D (or 2D) from a Python program, you will need to run it from the command line and access the OpenGL ES low level stuff directly.
You can launch it from X. The OpenGL ES app will run whilst X is running. However it will run in front of X, without interacting with the X windows. Compare to a 3D game in windows running full screen.


Higher level libraries like PyGame or Panda3D need to run on LXDE (or do they?) and so will be software rendered (or I guess won't work in the case of Panda3D).


Neither has been ported. If they are ported I'm imagine they would run full screen.


And WebGL also won't work for the same reason, because the browser needs to run on the desktop.


WebGL won't run because it hasn't been ported.

The hope is that we get an accelerated X, where the X window manager is a fullscreen OpenGL ES application, and each window renders to an offscreen surface which the WM composites. This will allow OpenGL ES apps to run windowed fairly efficiently, and WebGL etc to work.

User avatar
Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: 3D

Tue May 01, 2012 11:28 pm

dom said:


@Jim You cannot create openGL ES content in an X window.

The best you can do is to render to an off screen surface and call glGetPixels and put those in the X window.

You will of course get much better performance running full screen.


Whatever.  If someone can provide the end-to-end relevant working source for rendering OpenGL ES via Python to an off screen surface, calling glGetPixels, and putting that in an X window, I will write up a clear, noob-proof explanation in the wiki with all of the code formatted and commented sufficiently for a non-expert to follow it.  I could figure out how to do it, but, it would take time away from more important things I'm working on (including Real Life).  If someone already has all the pieces figured out, there's no need for me to reinvent the wheel.  If no one has actually done it, then maybe it's not as simple as it's being made out to be.

I don't expect full-screen performance, but, as I have already made extremely clear, I can't see full-screen anyway, since I'm accessing the Pi board via ssh and VNC.  Why is this so hard to understand?  This is like pulling teeth … by grabbing tendons in the toes.  Sheesh!

It's not helping that the board continues to crash at least once a day, even with nothing running beyond an xterm, on LXDE on Debian, that's not running anything when the crash occurs.  However, the owner has just replaced the power supply with something that provides 5 volts at 2.1 amps, so, if it was the power supply/cable, I'm hoping that problem has finally been solved.
The best things in life aren't things ... but, a Pi comes pretty darned close! :D
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

TheManWhoWas
Posts: 50
Joined: Thu Feb 09, 2012 9:11 pm

Re: 3D

Wed May 02, 2012 8:11 pm

@dom thanks for the clarifications, esp. about the relationship between running full screen 3D graphics and the desktop.

However, is anyone known to be actively trying to get something like Panda3D ported, as seems a bit of a hole at present if there is no way to access the power of the GPU from Python other than to use the low-level OpenGL ES calls?

Effectively means the RPi has a great graphics chip, but only expert programmers can do anything with it presently!

User avatar
ArborealSeer
Posts: 300
Joined: Tue Jan 24, 2012 9:48 am
Location: South West, UK

Re: 3D

Wed May 02, 2012 10:16 pm

unless there's a framework that exists on top of opengl es to simplify things, i guess thats the case.

since i last tinkered with opengl almost 10 years ago there is a lot more info online about it, plus a large amount of development being done with opengl es itself due to both iphones and android phones using it.

but there is a lot to learn and relearn, even for an experienced full-time c++ programmer like myself. fortunately i've learned some things in those 10 years
Pi Status > Farnell, Arrived 24/5- RS, Arrived 1/6

User avatar
Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: 3D

Thu May 03, 2012 6:43 am

TheManWhoWas said:


However, is anyone known to be actively trying to get something like Panda3D ported, as seems a bit of a hole at present if there is no way to access the power of the GPU from Python other than to use the low-level OpenGL ES calls?


We're looking at porting at least the Panda3D client for the Pi-finity! educational game that will help teach science, math, software development, and other technical skills.  It's not likely that the Panda3D server will be able to be ported to the Pi in toto, but, we may determine that a subset of its features may be able to be ported.  We're just in the nascent stages of learning how to use Panda3D on x86 hardware and, in theory, virtually all (if not all) of the client code should be able to be transitioned.


Effectively means the RPi has a great graphics chip, but only expert programmers can do anything with it presently!


In addition to the port, we would be documenting what we've done, and adding whatever might be needed to make things easier for less-expert people to use it on the Pi.  That will likely include world-building tools for creating Panda3D objects such as characters, scenes, props, etc.  We hope to be able to import models built using various existing 3-D creation and modification tools, although that appears to be the weakest link in all of the game engines we've examined, so far.

The complexity of creating and interactively manipulating 3-D graphics is not unique to the Pi – all 3-D graphics platforms present this challenge.  Since 3-D graphics often reflects the real world, potentially down to the smallest physical elements and behaviors, the complexity comes along for the ride (and many shortcuts are often taken for performance improvements).

The journey of 1,000 miles begins with but a single step …
The best things in life aren't things ... but, a Pi comes pretty darned close! :D
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

TheManWhoWas
Posts: 50
Joined: Thu Feb 09, 2012 9:11 pm

Re: 3D

Thu May 03, 2012 9:57 pm

Jim Manley said:


It"s not likely that the Panda3D server will be able to be ported to the Pi


I wasn't aware Panda3D had a server. Isn't it just a game engine which happens to also provide some networking support in its libraries?

Jim Manley said:


The complexity of creating and interactively manipulating 3-D graphics is not unique to the Pi – all 3-D graphics platforms present this challenge.


Sure, but using a game engine is much easier than having to write one entirely from scratch. With Panda3D you can get your animated panda moving around during the basic tutorial, which is a far cry from starting with a single untextured triangle using the low-level OpenGL ES calls.

My point is that the Pi needs a high-level graphics library like Panda3D ported pretty quick, else for most the power of the GPU will be locked away.

User avatar
Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: 3D

Fri May 04, 2012 12:36 am

We're well aware of the difference in effort between polygons and game engines.  We need to start with polygons in order to figure out how to port elements of a game engine like Panda3D into whatever will be needed to build Pi-Finity!

PeteX has taken on the Panda3D engine and assembled a simple starter version for the Pi-finity! development team to use to figure out what features we really need in our game system.  I should clarify that we're considering using the Panda3D engine as a point of departure for our game system, and we may use pieces of it on the Pi.  There does, indeed, need to be a game engine running on a Pi for the rendering of the game scenes.  However, one, or more, servers may be needed with substantial memory, storage, and bandwidth over networks from which Pi systems will obtain game data and services that include game 3-D models, textures, backgrounds, etc., along with the latest positions, velocity vectors, etc., of player characters, props, scenes, etc.  I realize you probably understand this, TheManWhoWas, and I'm being a bit pedantic for the thousands of people who have been following our project who aren't all computing experts.

Since the Pi may not be able to host the entire Panda3D game engine, not to mention the code for viewing and interacting with the game on the player's Pi, we've also been thinking about the possibility of distributing some of the engine functions among a number of Pi systems.  However, that's in the realm of very tenuous experimentation at the moment, and we won't know whether it's feasible until after the development team members all receive their Pi boards and can start trying out some ideas we've been pontificating in the most theoretical of terms, so far.

There are other alternatives to Panda3D, but, that seems to be the most logical candidate to try first, since it's well-known for being able to manipulate and render sophisticated models, scenes, etc., and already features Python APIs.  The latter is important so that our work will harmonize with the goals of the Foundation in selecting Python as one of the primary implementation languages to be used for education of students in software development.

A lot of questions will finally be able to be put to rest after we have Pi boards in-hand, but, until then, we can only speculate on what may be possible.
The best things in life aren't things ... but, a Pi comes pretty darned close! :D
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

User avatar
paddyg
Posts: 2340
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: 3D

Fri May 25, 2012 9:28 am

Hi,

Any progress or pointers to more information on Panda3D for raspberryPi? I am blithely coding away a sailing simulator for the raspberryPi (+ArduinoNano+3potentiometers+bits of wood+glue+screws->£50diy)
raspberryPi should arrive today!

Paddy
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

User avatar
Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: 3D

Sun May 27, 2012 9:29 am

I now have a Pi board and I've started prepping Panda3D for building it for the Pi. We're considering using Panda3D in part, or whole (if it can fit within the 128/128MB CPU/GPU split RAM configuration) as a game engine for Pi-finity!, a game system we're developing with a science, technology, engineering and math educational emphasis, including teaching software development. I've verified that Panda3D 1.7.x supports OGLES 2.0, so, the port-to-OGLES 2.0 monkey is off our back.

Pygame allegedly will run on the Pi using the ARM port, but, it's limited to Python 2.7, AIUI. I want to get that checked out sooner rather than later.
The best things in life aren't things ... but, a Pi comes pretty darned close! :D
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

User avatar
paddyg
Posts: 2340
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: 3D

Thu May 31, 2012 10:22 am

Hi

Any breakthroughs or advice on the Panda3d engine?

I now have my pi and I have started to try and compile the panda3d stuff. Here's a brief history so far:

1. tried the apt-get route suggested on panda3d site for debian squeeze but there were a couple of errors involving missing .../armel ... so there probably isn't a ready compiled version
2. downloaded source and followed the instructions for compiling. I started out using
python makepanda/installpanda.py --nothing --use-jpeg --use-png --use-python
however told me that jpeg, png, python and bison weren't there so I reduced it to just --nothing
3. installed bison: sudo apt-get install bison
4. something else not there so installed it (can't remember what it was but just did the same as for bison!)
5. it started making the application but after about 40 mins (11%) it said it couldn't get enough virtual memory and aborted. I hope this is swap space and not a ram limit??
6. rebooted the pi and didn't open anything else apart from a terminal window and it got to 39% (last compiled ok is pstatclient_composite.o about 130th file)
7. tried running the script straight from log in but also ran out of space. (At one point the script managed to not save the makepanda-dcache file properly so I had to copy over the makepanda-dcache-backup and start again from 11%!)

As I only have a 2GB SD card there isn't much room for swap space and the compiled files so I will get hold of a 8GB card and try again... Unless anyone has already gone through this pain and can provide an installer.

Paddy
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: 3D

Thu May 31, 2012 10:28 am

You could try putting swap on a USB disk instead of getting a larger SD card? USB-access might be faster than SD-access too?

User avatar
paddyg
Posts: 2340
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: 3D

Thu May 31, 2012 12:37 pm

paddyg wrote: python makepanda/installpanda.py --nothing --use-jpeg --use-png --use-python
...
4. something else not there so installed it (can't remember what it was but just did the same as for bison!)
That should have been "python makepanda/makepanda.py --nothing.." of course. (I checked the instruction to make sure I wrote the right thing and looked at the wrong line)

The other missing application was flex
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

User avatar
paddyg
Posts: 2340
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: 3D

Thu May 31, 2012 12:38 pm

Andrew, good idea thanks. I will have a go.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

User avatar
paddyg
Posts: 2340
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: 3D

Thu May 31, 2012 7:47 pm

AndrewS wrote:You could try putting swap on a USB disk instead of getting a larger SD card? USB-access might be faster than SD-access too?
Well the little pi has got past its previous bottleneck at 39% so putting the swap on a USB disk seems to have done something.

However the process wasn't completely obvious (at least to us 'Ubuntu softies') In case anyone else wants to do something similar, or even just wants to access a USB stick, this is what I did:

started the rPi with a usb stick in one and the keyboard in the other
logged on pi/raspberry then ran
dmesg
this gave pages of information and (luckily near the end) it had information that matched the usb stick I had put in (make, name, size etc) and in amongst it said sda: sda1 from which I could deduce the device was know to the rPi as /dev/sda1
I then ran
sudo mount /dev/sda1 /mnt
after which everything that was on the usb stick could be accessed i.e.
ls /mnt
gave a file list of what was on it. I suspect that running startx would have mounted the drive but it would have been tricky to use the graphical interface without a mouse!
I then created a swap file
sudo dd if=/dev/zero of=/mnt/myswap.swp bs=1k count=500000
it was a four GB usb stick so I allocated 500MB
I then created the file as a swap file (whatever that does)
sudo mkswap /mnt/myswap.swp
and switched file swap space on
sudo swapon /mnt/myswap.swp

Hope this is helpful to someone (I suppose it's the kind of thing that could go on the wiki)

PS actually when I ran
free
before and after the above steps I noticed that there was no swap set up before hand so it might be possible to use
sudo swapon /dev/whateverthepartionsetupasswapspaceiscalled
so make it compile ok
mount
is also a useful command to see what things are called
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

User avatar
Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: 3D

Fri Jun 01, 2012 12:54 am

Even if you had managed to get everything to compile, it wouldn't have been built with OpenGL ES 2.0 GPU support. I'm working on a script that will build the whole shebang, including python OGLES GPU support, checking for max CPU RAM and min GPU RAM in /boot/config.txt (during build), swap enabled (preferably on a USB hard drive - at least 20 ~ 50 times faster than the slowest SD cards, and USB flash drives are 5 ~ 20 times faster than the slowest SD cards), etc.

There are some other things that also need to be optimized, but, it's undetermined if the Panda3D engine will even fit in the Pi RAM, much less support rendering anything beyond a mono-color triangle. The problem is that the GPU probably needs max RAM, and the Debian OS alone eats about 80 MB in the stock configuration (that's part of the optimization I'm working on - carving out the OS parts not needed to run Panda3D). It may be necessary to trim Panda 3D down in functionality in order to run reasonably within the tight Pi RAM constraints.

It will be much easier to just post an SD card image with everything configured and built for the proper CPU/GPU RAM split for GPU-accelerated Panda3D, minimal OS resources loading into CPU RAM, optimal swap space, etc. That's going to take a few weeks working on it part-time along with other Pi-finity! educational game system experiments, Pi configuration optimization, etc., (e.g., I'm still wrestling with flaky WiFi issues, USB hub power, building a reasonably robust case with built-in USB hub and 5v power, etc.).

BTW, swap space bigger than twice the CPU RAM in Linux versions from the past few years generally results in increasingly poor performance if lots of swapping is actually occurring, especially to a non-hard disk, which is typically at least twice as fast as the fastest USB flash drives, and upwards of ten times as fast as slower USB flash drives. The upper limit to any drive on the USB bus is going to be less than about 50 MByte/sec sustained, even with a faster hard drive, due to the 480 Mbit/sec USB 2.0 instantaneous max burst speed, and depending on the number of USB devices on the bus and Ethernet and/or WiFi activity that will likely be going on along with everything else.

Oh, and we're not going to be running Panda3D with any kind of windowing system, as there just isn't any spare CPU RAM for that, not to mention no GPU-accelerated X window server (yet), anyway, even if there were enough RAM. That's OK, though, as we want to fill large screen HDTVs with gorgeous 40,000,000 polygon/second animated 3-D images in 1080p video, anyway :)
The best things in life aren't things ... but, a Pi comes pretty darned close! :D
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

User avatar
paddyg
Posts: 2340
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: 3D

Fri Jun 01, 2012 9:26 am

Jim, you are right. I did manage to get "--nothing" to compile, after 4 and a half hours! Seemed to install ok as per the instructions and I eventually managed to successfully compile the first of the introduction c++ programs (as no python support in --nothing) which should just bring up a grey window (couldn't find -lp3direct during build but that was only complaint).

However on running it said -no graphics pipe available. Your Config.prc must have at least one valid panda display library via load-display or aux-display
Changing Config.prc to try all the available options didn't work

The sensible thing is for me to wait for you to finish your script though if there's anything I can help with let me know.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

tokyostormdrain
Posts: 14
Joined: Wed May 30, 2012 6:11 pm

Re: 3D

Mon Jun 11, 2012 9:04 pm

Hi, any more success with this?
Just been looking at panda3d and seems a nice well supported rendering api to get into, if only it can be stuffed in the pi it seems.

After seeing that it would need compiling for the pi I thought to see if someone else had already done it.
Looks like no easy task unfortunately.

Thanks for any updates and good luck with your efforts.

Return to “General discussion”