User avatar
flypig
Posts: 6
Joined: Tue May 29, 2012 9:19 pm
Location: Liverpool
Contact: Website

OpenGL capabilties

Tue May 29, 2012 9:52 pm

I recently received a Raspberry Pi and the first thing I did was recompile an existing C program under Debian that uses OpenGL, freeglut, gtkglext and GLee.

I was pretty surprised when it compiled and ran first time. However, I was also a little confused: I know the Raspberry Pi supports OpenGL ES, but didn't expect it to work with the vanilla OpenGL code straight out of the box.

Based on other people's experiences, is this to be expected, have I just been lucky, or am I'm only using software rendering? Can anyone provide any advice about the kind of performance I should be getting from the device?

shirro
Posts: 248
Joined: Tue Jan 24, 2012 4:54 am

Re: OpenGL capabilties

Tue May 29, 2012 11:02 pm

If you don't have hardware acceleration OpenGL falls back to being software rendered with Mesa. It isn't the real deal.

Lately my Pi has been booting straight into a lightweight X environment with a fractal Julia set being transparently overlaid at full HD resolution using GLSL. It is kind of annoying but it uses 0% CPU and helps to remind me this isn't the machine I was using in the late 1990s and that while it may never be much good for web browsing it has a heap of potential in other areas.

User avatar
flypig
Posts: 6
Joined: Tue May 29, 2012 9:19 pm
Location: Liverpool
Contact: Website

Re: OpenGL capabilties

Wed May 30, 2012 9:47 am

Thanks for replying shirro. That explains a lot (performance-wise) and I guess I'll have to do a bit more work to convert to OpenGL ES then. Clearly the 3D and video performance are important qualities of the device, so I'm keen to get to grips with this.

To guarantee hardware acceleration I assume I just need to ensure only the GLES headers are included, as in the hello_triangle example? Probably this will need a re-write of gtkglext though. Do you know if anything like this is planned? I couldn't see anything on the Web about an GLES version of gtkglext, and in general it probably makes more sense to just use Qt, but in this case it would require a huge change to existing code.

Thanks again!

User avatar
redneon
Posts: 21
Joined: Mon May 21, 2012 11:14 am
Location: Rotherham, England
Contact: Website

Re: OpenGL capabilties

Thu May 31, 2012 10:59 am

If you're currently using the old OpenGL fixed-function stuff (glVertex3f, glRotate, glMatrixMode etc.) then you're in for a bit of a shock as that's all been deprecated now. Technically you CAN use them in standard OpenGL 3 and 4 but you really shouldn't as they'll be removed at some point. It's all about vertex arrays and (even better) vertex buffer objects now.

The reason I mention this is because, if you're already up to date with modern OpenGL, then there's very little difference (I've found) between standard OpenGL and GLES. I'm in the process of porting my own framework from OpenGL 4 and Cg to GLES 2 and GLSL for Pi and I'm finding it pretty much straightforward.

User avatar
flypig
Posts: 6
Joined: Tue May 29, 2012 9:19 pm
Location: Liverpool
Contact: Website

Re: OpenGL capabilties

Thu May 31, 2012 11:28 am

Hi Redneon, and thanks for the advice. The code I'm porting is all using VBOs rather than immediate mode for this reason, however I've not been pedantic about checking that everything's GLES compatible, so I may yet discover problems.

I'm glad to hear that you're finding the process straightforward though, which is encouraging. My main concern is still the interaction with GTK; can I ask how you're handling or plan to handle this? Do you have any code for your framework online/opensource to try out? I'd be interested to take a look if you do.

User avatar
redneon
Posts: 21
Joined: Mon May 21, 2012 11:14 am
Location: Rotherham, England
Contact: Website

Re: OpenGL capabilties

Thu May 31, 2012 11:47 am

Well, as X doesn't currently have accelerated graphics I'm just using the bcm_host lib to access the GPU directly so I'm doing no GUI stuff at all. My framework on desktop is currently using SDL 2.0 for the windowing but I'm going to have to rip that out for Pi. At the minute I'm still finishing off the migration from GL4 and Cg to GLES and GLSL, though.

To be honest, I find X far too slow to be usable on my Pi so I'm either coding on my desktop PC and using SSH to build and run on the Pi or I just use Emacs in the console on my Pi :)

My framework is hosted on Bitbucket but it's not public. If you've got a Bitbucket account I don't mind sharing the project with you once I've actually got it ported across.

User avatar
redneon
Posts: 21
Joined: Mon May 21, 2012 11:14 am
Location: Rotherham, England
Contact: Website

Re: OpenGL capabilties

Thu May 31, 2012 11:59 am

Also, just in case you haven't spotted it, there are some samples in /opt/vc/src/hello_pi which demonstrate using the bcm_host lib to do stuff directly. Have a look at the hello_triangle example for GLES.

theHetman
Posts: 88
Joined: Tue Jan 10, 2012 5:42 pm

Re: OpenGL capabilties

Thu May 31, 2012 1:24 pm

redneon wrote:Also, just in case you haven't spotted it, there are some samples in /opt/vc/src/hello_pi which demonstrate using the bcm_host lib to do stuff directly. Have a look at the hello_triangle example for GLES.
That hello_triangle example seems to be the only one that shows you how to set up an OpenGL window. Note that that example uses OpenGL ES 1.1 and the call to create the context eglCreateContext has NULL for the last parameter. For ES 2.0 this need to be pointer to an attrib array:

EGLint attr[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };

This bit me and I wasted an hour tracking it down.

User avatar
redneon
Posts: 21
Joined: Mon May 21, 2012 11:14 am
Location: Rotherham, England
Contact: Website

Re: OpenGL capabilties

Thu May 31, 2012 1:41 pm

Ah, yeah. Sorry, I forgot about that.

Also, to quote dom from another thread: "Update firmware (e.g. with hexxeh's firmware updater) and you will get "hello_triangle2", a GL ES 2 example."

I haven't updated my firmware yet so I didn't know about this but it's a handy thing to know.

Return to “C/C++”