nuttingcdef
Posts: 12
Joined: Sun May 27, 2012 9:36 am

OenGL ES Sample problem

Thu May 31, 2012 9:51 am

To introduce myself to OpenGL (having done more in the past with DrectX / XNA) I've grabbed the raspi version of the OpenGL ES 2.0 book samples from GitHub. They all build fine and most of them run / display as expected. But for (e.g.) the Chapter 8 / Simple_VertexShader sample I just get the black background with nothing else showing.

Has anyone else got this sample working?

hello_triangle builds / runs fine, so I'm fairly sure there is nothing fundamentally at fault with my pi configuration.

My guess is that there is some minor difference in the setup within the code between the sample and hello_triangle that kills the rendering in the sample. Any clues as to anything I might be doing wrong or what I might need to tweak in the code to sort it?

Many thanks for any assistance!

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

Re: OenGL ES Sample problem

Thu May 31, 2012 10:53 am

Yeah, I saw this too but I didn't look into it as I already have my own working code. I'm at work at the minute but if no-one else knows I'll have a look when I get home and see if I can find out what the issue is.

nuttingcdef
Posts: 12
Joined: Sun May 27, 2012 9:36 am

Re: OenGL ES Sample problem

Thu May 31, 2012 11:26 am

Not being an OpenGL expert I'm not sure what the implications are, but hello_triangle includes <GLES/gl.h> but the sample includes <GLES2/gl2.h>. Changing the sample include means it fails to build, so there are clearly GLES2 dependencies. I still haven't got this working, but does this give anyone a clue?

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

Re: OenGL ES Sample problem

Thu May 31, 2012 11:50 am

I'm only guessing but I'd assume gl2.h forces the use of non-deprecated fixed-functions pipeline functions.

nuttingcdef
Posts: 12
Joined: Sun May 27, 2012 9:36 am

Re: OenGL ES Sample problem

Thu May 31, 2012 12:20 pm

redneon

Agree that that sounds likely, though exactly what the differences would be I'm not sure. A few thoughts:

* Looking at which of the samples and which don't, I've a fairly strong hunch that this is down to issues with 3D stuff. As far as I can see, all the 2D samples work fine.

I've tried messing around with backface culling options, changing the 3D translations, near / far planes etc. to see if this is just a question of what is visible in the viewport, but without any joy.

* How does lighting work in OpenGL ES 2.0? glEnable(GL_LIGHTING) doesn't compile, so I guess it's been dropped. Could everything be black just because there isn't any ambient lighting enabled? How do you do that in ES 2.0?

* Or is there a general option that needs to be turned on to enable 3D at all?

Any thoughts from anyone much appreciated!

Gibble
Posts: 56
Joined: Wed May 09, 2012 9:52 am

Re: OenGL ES Sample problem

Thu May 31, 2012 12:53 pm

Is there any way you can nopaste up the code somewhere ?

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

Re: OenGL ES Sample problem

Thu May 31, 2012 12:59 pm

I've downloaded and compiled those demos but I've not run them all, only the hello_triangle and that worked fine.

It looks like the Pi has an OpenGL ES 1.x library. This must be written on top of ES 2.0 as we have been told that 2.0 is the only native 3D API that the Pi supports. ES 1.x and 2.0 are very different from each other with 1.x only implimenting the fixed pipeline from OpenGL 1.x and ES 2.0 only implimenting the shader based system from OpenGL 2.0 and removing the fixed pipline completely.

It should noted that the hello_triangle demo on the Pi image (in /opt/vc/src/hello_pi/hello_triangle) uses the ES 1.x library and there are no examples using ES 2.0 that come with the debian image.

As for lighting in ES 2.0 you have to write shader programs that do the transform and lighting. If you have that OpenGL 2.0 book then there are lighting examples in chapters 8 and 13, including a full transform and light program that impliments the fixed pipeline of ES 1.1

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

Re: OenGL ES Sample problem

Thu May 31, 2012 1:07 pm

theHetman wrote: It should noted that the hello_triangle demo on the Pi image (in /opt/vc/src/hello_pi/hello_triangle) uses the ES 1.x library and there are no examples using ES 2.0 that come with the debian image.
Update firmware (e.g. with hexxeh's firmware updater) and you will get "hello_triangle2", a GL ES 2 example.

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

Re: OenGL ES Sample problem

Thu May 31, 2012 1:11 pm

I've just thought of something that might be worth trying. I had problems with culling when I didn't specify a depth size in my attributes. I ended up using 8, 8, 8, 8, 24, 0 for Red, Green, Blue, Alpha, Depth and Stencil respectively. Might be worth given that a try?

nuttingcdef
Posts: 12
Joined: Sun May 27, 2012 9:36 am

Re: OenGL ES Sample problem

Thu May 31, 2012 2:02 pm

OK, this is weird!

Looks like the problem is with glDrawElements. If I do a kludge with glDrawArrays I get a rotating red image on the screen as expected (junk because vertex data isn't set up right to do it that way but it proves all the other rendering code / shaders etc. are working). Checked values of indices and numIndices and they all look good, so what's going on I'm not sure. Need to check it out in more detail later.

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

Re: OenGL ES Sample problem

Thu May 31, 2012 2:08 pm

It could be related to a similar issue I had last week. See this thread I posted here: http://www.raspberrypi.org/phpBB3/viewt ... =33&t=6360

I'd be interested to know what your eglConfig looks like. What attributes are you using?

nuttingcdef
Posts: 12
Joined: Sun May 27, 2012 9:36 am

Re: OenGL ES Sample problem

Thu May 31, 2012 4:43 pm

Solved! :D

The issue was with the indices being passed to glDrawElements. The sample code had these as GLuints - changing them (and all other relevant references etc.) to GLubyte got everything working.

There is a possible documentation issue here - documentation for glDrawElements at http://www.opengl.org/wiki/GLAPI/glDrawElements says indices can be GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT or GL_UNSIGNED_INT but at http://www.khronos.org/opengles/documen ... ments.html it says only GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT. I appreciate that these may relate to different versions of OpenGL ES but despite the fact that I'm linking to 2.0 it is the 1.0 documentation that seems to be right.

Hope this helps others if they encounter similar problems.

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

Re: OenGL ES Sample problem

Thu May 31, 2012 4:50 pm

Isn't the first link for OpenGL and the khronos one for OpenGL ES?
You should be using the khronos link for API. They are the standards we follow.

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

Re: OenGL ES Sample problem

Thu May 31, 2012 5:20 pm

Yup, and as he said, neither is the correct one for OpenGL ES 2.0..

The correct manual page is here http://www.khronos.org/opengles/sdk/doc ... ements.xml

however it does tally with his findings (says GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT)

as its probably useful.. the root of the OpenGL ES 2.0 manual is here http://www.khronos.org/opengles/sdk/docs/man/
Pi Status > Farnell, Arrived 24/5- RS, Arrived 1/6

nuttingcdef
Posts: 12
Joined: Sun May 27, 2012 9:36 am

Re: OenGL ES Sample problem

Thu May 31, 2012 6:11 pm

Thank you - as a newbie (to OpenGL), issues related to versions (of anything) never feel nice and clean. This one wouldn't have arisen if the sample code linked to the OpenGL ES 2.0 book on GitHub hadn't had a bug that appears to be related to which version of OpenGL is being used.

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

Re: OenGL ES Sample problem

Thu Nov 15, 2012 11:30 pm

GRRRR!!!!! I wish I had found this thread a few hours ago...... :(
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

terryspitz
Posts: 4
Joined: Fri Dec 28, 2012 9:23 am

Re: OenGL ES Sample problem

Fri Dec 28, 2012 9:30 am

works for me! so to be clear,
edit file
opengles-book-samples/Raspi/Chapter_8/Simple_VertexShader/Simple_VertexShader.c
from
glDrawElements( GL_TRIANGLES, userData->numIndices, GL_UNSIGNED_INT, userData->indices );
to
glDrawElements( GL_TRIANGLES, userData->numIndices, GL_UNSIGNED_SHORT, userData->indices );

then make again, then i get rotating red... things. now to make them say something... t.

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

Re: OenGL ES Sample problem

Sun Dec 30, 2012 8:21 am

There is a "fixed" version of the examples here -> https://github.com/benosteen/opengles-b ... ster/Raspi

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

Return to “OpenGLES”