Upgrade to Pro — share decks privately, control downloads, hide ads and more …

OpenGL, a noob's guide for Android developers

OpenGL, a noob's guide for Android developers

Presentation given at Android Makers 2017 in Paris.

OpenGL is often regarded as too complex, obscur or even too low level to be considered when developing an application. Most people will even try to go around it and develop what they want using Views and Canvas to avoid developing with it. Nevertheless, it's not always possible nor the best solution. As someone who have been going through all the learning of OpenGL recently, I have encountered a lot of frustration but also a lot of “aha!“ moment. In this talk, I will try to demystified OpenGL and share the basics of what it is and how to use it in Android to make applications perform better. Also, I will share all the pitfalls and key concepts that you should know when starting with OpenGL.

Benjamin Monjoie

April 10, 2017
Tweet

More Decks by Benjamin Monjoie

Other Decks in Programming

Transcript

  1. Roadmap • What is OpenGL ? • What about with

    Android ? • OpenGL’s internals • Shaders • Enter the matrix • Advices • Bonus
  2. Roadmap • What is OpenGL ? • What about with

    Android ? • OpenGL’s internals • Shaders • Enter the matrix • Advices • Bonus
  3. OpenGL & Android • OpenGL ES 1.0 & 1.1 since

    Android 1.0 (API 4) • OpenGL ES 2.0 since Android 2.2 (API 8)
  4. OpenGL & Android • OpenGL ES 1.0 & 1.1 since

    Android 1.0 (API 4) • OpenGL ES 2.0 since Android 2.2 (API 8) • OpenGL ES 3.0 since Android 4.3 (API 18) (almost)
  5. OpenGL & Android • OpenGL ES 1.0 & 1.1 since

    Android 1.0 (API 4) • OpenGL ES 2.0 since Android 2.2 (API 8) • OpenGL ES 3.0 since Android 4.3 (API 18) (almost) • OpenGL ES 3.1 since Android 5.0 (API 21)
  6. OpenGL & Android • OpenGL ES 1.0 & 1.1 since

    Android 1.0 (API 4) • OpenGL ES 2.0 since Android 2.2 (API 8) • OpenGL ES 3.0 since Android 4.3 (API 18) (almost) • OpenGL ES 3.1 since Android 5.0 (API 21)
  7. Roadmap • What is OpenGL ? • What about with

    Android ? • OpenGL’s internals • Shaders • Enter the matrix • Advices • Bonus
  8. What about with Android ? GLSurfaceView & GLSurfaceView.Renderer onSurfaceCreated (GL10

    gl, EGLConfig config) onSurfaceChanged (GL10 gl, int width, int height) onDrawFrame (GL10 gl)
  9. Roadmap • What is OpenGL ? • What about with

    Android ? • OpenGL’s internals • Shaders • Enter the matrix • Advices • Bonus
  10. Roadmap • What is OpenGL ? • What about with

    Android ? • OpenGL’s internals • Shaders • Enter the matrix • Advices • Bonus
  11. Vertex shader - Example precision mediump float; uniform mat4 uMVPMatrix;

    attribute vec4 vPosition; attribute vec4 vTextureCoordinate; varying vec2 position; void main() { gl_Position = uMVPMatrix * vPosition; position = vTextureCoordinate.xy; }
  12. Vertex shader - Example precision mediump float; uniform mat4 uMVPMatrix;

    attribute vec4 vPosition; attribute vec4 vTextureCoordinate; varying vec2 position; void main() { gl_Position = uMVPMatrix * vPosition; position = vTextureCoordinate.xy; }
  13. Vertex shader - Example precision mediump float; uniform mat4 uMVPMatrix;

    attribute vec4 vPosition; attribute vec4 vTextureCoordinate; varying vec2 position; void main() { gl_Position = uMVPMatrix * vPosition; position = vTextureCoordinate.xy; }
  14. Vertex shader - Example precision mediump float; uniform mat4 uMVPMatrix;

    attribute vec4 vPosition; attribute vec4 vTextureCoordinate; varying vec2 position; void main() { gl_Position = uMVPMatrix * vPosition; position = vTextureCoordinate.xy; }
  15. Vertex shader - Example precision mediump float; uniform mat4 uMVPMatrix;

    attribute vec4 vPosition; attribute vec4 vTextureCoordinate; varying vec2 position; void main() { gl_Position = uMVPMatrix * vPosition; position = vTextureCoordinate.xy; }
  16. Fragment shader - Example precision mediump float; uniform sampler2D uTexture;

    varying vec2 position; void main() { gl_FragColor = texture2D(uTexture, position); }
  17. Fragment shader - Example precision mediump float; uniform sampler2D uTexture;

    varying vec2 position; void main() { gl_FragColor = texture2D(uTexture, position); }
  18. Fragment shader - Example precision mediump float; uniform sampler2D uTexture;

    varying vec2 position; void main() { gl_FragColor = texture2D(uTexture, position); }
  19. Fragment shader - Example precision mediump float; uniform sampler2D uTexture;

    varying vec2 position; void main() { gl_FragColor = texture2D(uTexture, position); }
  20. Roadmap • What is OpenGL ? • What about with

    Android ? • OpenGL’s internals • Shaders • Enter the matrix • Advices • Bonus
  21. The strip POSITION_MATRIX = { -1,-1, 1, // X1,Y1,Z1 1,-1,

    1, // X2,Y2,Z2 -1, 1, 1, // X3,Y3,Z3 1, 1, 1, // X4,Y4,Z4 }; TEXTURE_COORDS[] = { 0, 1, // X1,Y1 1, 1, // X2,Y2 0, 0, // X3,Y3 1, 0, // X4,Y4 };
  22. Roadmap • What is OpenGL ? • What about with

    Android ? • OpenGL’s internals • Shaders • Enter the matrix • Advices • Bonus
  23. Advices • Abstract as much as possible • Crash often

    but crash well ! • Test, a lot ! • Use Google’s Play Store’s Alpha & Beta channels
  24. Roadmap • What is OpenGL ? • What about with

    Android ? • OpenGL’s internals • Shaders • Enter the matrix • Advices • Bonus
  25. OpenGL A noob's guide for Android developers https://plus.google.com/+BenjaminMonjoieXzan https://medium.com/@Xzan https://twitter.com/Xzan

    https://twitter.com/android_leaks https://medium.com/@xzan/opengl-le-guide-du-noob-pour-développeur-android