rst
Posts: 370
Joined: Sat Apr 20, 2013 6:42 pm
Location: Germany

Depth buffer with OpenGL ES 1.1 on Raspberry Pi 3B+

Sat Feb 23, 2019 1:15 pm

I'm learning OpenGL ES at the moment and started with OpenGL ES 1.1. I programmed some rotating 3D model, derived from the hello_triangle sample in /opt/vc/src/hello_pi, which has multiple opaque colored 3D boxes (all alpha color values are 1.0f), which is basically working well, but I have a problem with hidden surfaces. The depth test does not work.

Does the Raspbery Pi implementation of OpenGL ES 1.1 running on a recent Raspbian system support the depth buffer? I have enabled the GL_DEPTH_TEST using glEnable() and cleared the depth buffer with glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) before calling glDrawArrays(). But even if I call glDepthFunc(GL_NEVER), all surfaces are drawn. Does somebody have an idea, what I may do wrong?
raspi.png
raspi.png (40.87 KiB) Viewed 1891 times
One can see, that the card slot and the RAM chip, which are below the printed board are visible. They should be hidden.

Brian Beuken
Posts: 177
Joined: Fri Jan 29, 2016 12:51 pm

Re: Depth buffer with OpenGL ES 1.1 on Raspberry Pi 3B+

Fri Mar 15, 2019 12:13 pm

setting the function to GL_NEVER means it will always fail, ie show everything,

So you need one of the other functions for testing which are the same as used by stencil

GL_NEVER
GL_LESS
GL_EQUAL
GL_LEQUAL
GL_GREATER
GL_NOTEQUAL
GL_GEQUAL
GL_ALWAYS

Try GL_LEQUAL
But to actually get depth functions to work you need to have a depth buffer, and thats set up when you get an EGL config, so you should also have a depth buffer enabled in your EGL config which may look something like this

static const EGLint attribute_list[] =
{
// these 1st 4, let us define the size of our colour components and from that the size of a pixel.
// In this case 32bits made up of 8xR, 8xG,8xB and 8xA
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,

EGL_SAMPLE_BUFFERS,1, // if you want anti alias at a slight fps cost, it won't make a huge difference on a 2D system
EGL_SAMPLES, 4, //keep these 2 lines

// These lines set up some basic internal features that help with depth sorting
EGL_DEPTH_SIZE, 8,

// These lines tell EGL how the surface is made up.
EGL_SURFACE_TYPE,
EGL_WINDOW_BIT,
EGL_NONE
};

I usually set up my OpenGL states like this
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glDepthMask(TRUE);
glDepthRangef(0.0f, 1.0f);
glClearDepthf(1.0f);
you may also need to consider
glCullFace(GL_BACK);
as it can make it look like things behind things are being seen

Btw, OpenGLES1.1 is basically outdated now, it does still work of course, but much better to move to OpenGLES2.0 when you get a grip on what that static pipeline is doing.. A lot of things like depth sorting work the same way so you're not losing anything by starting with 1.1
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

rst
Posts: 370
Joined: Sat Apr 20, 2013 6:42 pm
Location: Germany

Re: Depth buffer with OpenGL ES 1.1 on Raspberry Pi 3B+

Sat Mar 16, 2019 8:18 am

It's working now: :)
raspi.png
raspi.png (47.24 KiB) Viewed 1231 times
The card slot and RAM chip are not visible any more. The problem has been the missing "EGL_DEPTH_SIZE, 8" entry in the EGL attribute_list.

Thank you very much, also for your very interesting article series in The MagPi 65-77. It inspired me, to start with this. I will move over to OpenGL ES 2.0 later. I found it easier to start with OpenGL ES 1.1 for this 3D model, because there is this hello_triangle sample program in the /opt/vc tree, which displays a single rotating cube.

Brian Beuken
Posts: 177
Joined: Fri Jan 29, 2016 12:51 pm

Re: Depth buffer with OpenGL ES 1.1 on Raspberry Pi 3B+

Sun Mar 17, 2019 7:16 pm

Awesome, keep pluggin away
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
Wrote some book about coding Pi's and SBC's, it's out now...go get it!
http://www.scratchpadgames.net/

Return to “OpenGLES”