Page 1 of 1

OenGL ES Sample problem

Posted: Thu May 31, 2012 9:51 am
by nuttingcdef
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!

Re: OenGL ES Sample problem

Posted: Thu May 31, 2012 10:53 am
by redneon
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.

Re: OenGL ES Sample problem

Posted: Thu May 31, 2012 11:26 am
by nuttingcdef
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?

Re: OenGL ES Sample problem

Posted: Thu May 31, 2012 11:50 am
by redneon
I'm only guessing but I'd assume gl2.h forces the use of non-deprecated fixed-functions pipeline functions.

Re: OenGL ES Sample problem

Posted: Thu May 31, 2012 12:20 pm
by nuttingcdef
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!

Re: OenGL ES Sample problem

Posted: Thu May 31, 2012 12:53 pm
by Gibble
Is there any way you can nopaste up the code somewhere ?

Re: OenGL ES Sample problem

Posted: Thu May 31, 2012 12:59 pm
by theHetman
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

Re: OenGL ES Sample problem

Posted: Thu May 31, 2012 1:07 pm
by dom
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.

Re: OenGL ES Sample problem

Posted: Thu May 31, 2012 1:11 pm
by redneon
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?

Re: OenGL ES Sample problem

Posted: Thu May 31, 2012 2:02 pm
by nuttingcdef
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.

Re: OenGL ES Sample problem

Posted: Thu May 31, 2012 2:08 pm
by redneon
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?

Re: OenGL ES Sample problem

Posted: Thu May 31, 2012 4:43 pm
by nuttingcdef
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.

Re: OenGL ES Sample problem

Posted: Thu May 31, 2012 4:50 pm
by dom
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.

Re: OenGL ES Sample problem

Posted: Thu May 31, 2012 5:20 pm
by ArborealSeer
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/

Re: OenGL ES Sample problem

Posted: Thu May 31, 2012 6:11 pm
by nuttingcdef
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.

Re: OenGL ES Sample problem

Posted: Thu Nov 15, 2012 11:30 pm
by PeterO
GRRRR!!!!! I wish I had found this thread a few hours ago...... :(
PeterO

Re: OenGL ES Sample problem

Posted: Fri Dec 28, 2012 9:30 am
by terryspitz
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.

Re: OenGL ES Sample problem

Posted: Sun Dec 30, 2012 8:21 am
by PeterO
There is a "fixed" version of the examples here -> https://github.com/benosteen/opengles-b ... ster/Raspi

PeterO