Adding the Skybox to Our Scene

Now that we have the cube model and shader code written up, let’s add the skybox to our scene. Open up ParticlesRenderer, and add the following members to the top of the class:

Skybox/src/com/particles/android/ParticlesRenderer.java
 
private​ SkyboxShaderProgram skyboxProgram;
 
private​ Skybox skybox;
 
private​ ​int​ skyboxTexture;

At the same time, rename the existing texture member variable from the last chapter to particleTexture. Bring in any missing imports, and then we’ll initialize these new variables in onSurfaceCreated with the following code:

Skybox/src/com/particles/android/ParticlesRenderer.java
 
skyboxProgram = ​new​ SkyboxShaderProgram(context);
 
skybox = ​new​ Skybox();
 
skyboxTexture = TextureHelper.loadCubeMap(context, ...

Get OpenGL ES 2 for Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.