User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1665
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Open GL ES z buffer setup help needed

Mon Aug 20, 2012 10:00 pm

Hey folks;

I am playing around with reverse engineering the hello_triangle (link) example program that comes with the Pi and I want to add a proper depth buffer. I think I need to modify something in the init_ogl function but I am not exactly sure what to do. I have added calls to the following EGL methods in my set up view function;

Code: Select all

glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LEQUAL);
glDepthRange(0.0f, 1.0f);
In my draw view method I am calling the methods below just before I set up my vertex and colour pointers and call into glDrawElements, but despite this the depth buffering in my scene doesn't actually work. So this is why I think it's something in the init_ogl function.

Here is a short video of the problem (link), ignore the mad colours - they're just for testing purposes.

Code: Select all

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
So this is why I think it's something in the init_ogl function. If anyone could point me in the right direction I would be really grateful.

Cheers!
Dave

User avatar
Paeryn
Posts: 2952
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Open GL ES z buffer setup help needed

Tue Aug 21, 2012 1:50 am

Have you asked for a depth buffer? In the config attributes for EGL you want something like this:

Code: Select all

static const EGLint attribute_list[] =
   {
      EGL_RED_SIZE, 8,
      EGL_GREEN_SIZE, 8,
      EGL_BLUE_SIZE, 8,
      EGL_ALPHA_SIZE, 8,
      EGL_DEPTH_SIZE, 16,   // You need this line for depth buffering to work
      EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
      EGL_NONE
   };
She who travels light — forgot something.

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1665
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: Open GL ES z buffer setup help needed

Tue Aug 21, 2012 8:11 am

Ahh, that is different to what I have... this is what my code has, which is straight out of the demo code;

Code: Select all

static const EGLint attribute_list[] =
	{
		EGL_RED_SIZE, 8,
		EGL_GREEN_SIZE, 8,
		EGL_BLUE_SIZE, 8,
		EGL_ALPHA_SIZE, 8,
		EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
		EGL_NONE
	};
I'll give it a try this evening and report back, thanks for the help! :)

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1665
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: Open GL ES z buffer setup help needed

Tue Aug 21, 2012 5:24 pm

Paeryn wrote:Have you asked for a depth buffer? In the config attributes for EGL you want something like this:
This did the trick, thank you so much.

User avatar
avatar1337
Posts: 78
Joined: Sun Jan 27, 2013 3:14 pm

Re: Open GL ES z buffer setup help needed

Wed Feb 13, 2013 12:17 pm

Yes! Helped me aswell =)
The creator of the Raspberry Pi Configuration Manager (PiCon)

Return to “OpenGLES”