OpenGL ES on Raspberry Pi

When writing OpenGL ES programs on the Raspberry Pi for the first time, you may encounter these issues:

1) Shaders aren’t working properly; the colors don’t come out correctly.

My Fragment Shader code was this:

precision lowp float;
varying vec3 vv3colour;
void main() {
    gl_FragColor = vec4(vv3colour, 1.0);
}

My Vertex Shader code was this:

attribute vec4 av4position;
attribute vec3 av3colour;
uniform mat4 mvp;
varying vec3 vv3colour;
void main() {
    vv3colour = av3colour;
    gl_Position = mvp * av4position;
}

SOLUTION: In my case the EGL_ALPHA_SIZE was not set in the attribList when the call to eglChooseConfig was made. Once I set EGL_ALPHA_SIZE to 8, it worked!

2) You can see X through your application, ie, the background is transparent.

SOLUTION: change the glClearColor line to (0.0f, 0.0f, 0.0f, 1.0f). I don’t understand it but that worked for me.

Advertisements

2 thoughts on “OpenGL ES on Raspberry Pi

  1. Thank you!!!
    I’d been writing code based off of the Hello_Triangle.c file found here:
    https://github.com/benosteen/opengles-book-samples
    on the Raspberry Pi.
    Any colours I was trying to pass using a varying simply showed up as transparent. For anyone having the same specific issue, changing
    esCreateWindow ( &esContext, “ParticleSystem”, 640, 480, ES_WINDOW_RGB );
    to
    esCreateWindow ( &esContext, “ParticleSystem”, 640, 480, ES_WINDOW_RGB|ES_WINDOW_ALPHA );
    did the trick for me.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s