Raspberry Pi + OpenGL ES
OpenGL ES works on the Raspberry Pi!
How did I do it? Well, I…
- Grabbed vim with
sudo apt-get install vim
. - Grabbed my ~/.vimrc.
- Calmed down.
- Looked in /opt/vc/src and built and ran the examples there.
- Braced myself to plow through the EGL junk.
- Found pyopengles and downloaded it on my Raspberry Pi. Thanks, Mr. Divaz.
- Found http://benosteen.wordpress.com/2012/05/13/glsl-sandbox-on-the-raspberry-pi/. I based my first triangle off of one of the examples I found there. It renders a half-screen triangle, shaded according to its relative position on the screen. The code is:
from pyopengles import * context = EGL() vertexShader = """ attribute vec4 position; varying vec2 fposition; void main() { gl_Position = position; fposition = position.xy * 0.5 + 0.5; } """ fragmentShader = """ precision mediump float; varying vec2 fposition; void main() { gl_FragColor = vec4(vec3(fposition, 0.0), 1.0); } """ binding = ((0, 'position'),) program = context.get_program(vertexShader, fragmentShader, binding) opengles.glClearColor(eglfloat(0.45), eglfloat(0.35), eglfloat(0.15), eglfloat(1.0)) vertices = eglfloats((-1.0, -1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, -1.0, 1.0, 0.0, 1.0)) opengles.glViewport(0, 0, context.width, context.height); opengles.glClear(GL_COLOR_BUFFER_BIT) opengles.glUseProgram(program) opengles.glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, vertices) opengles.glEnableVertexAttribArray(0) opengles.glDrawArrays(GL_TRIANGLES, 0, 3) openegl.eglSwapBuffers(context.display, context.surface) time.sleep(5)