I am currently working on a animated background wallpaper for my mobile iOS app (XCode6, iOS 7.1-8.4, OpenGL ES 2.0). The goal is to display in each view controller a gradient background (from light blue to dark blue) and some bubbles (*.png) that move from the bottom of the screen to the top of the screen.
Bubble-Sprites (Image 1)
For the bubbles, I took parts of the Ray Wenderlich tutorial on making a 2D-game with OpenGL ES (ie. Sprite-Class). This also works fine for its own.
Gradient-Background (Image 2)
I solved the gradient by using a fragment shader (took some code snippets from this tutorial). This works fine for its own.
Problem
So, currently the gradient is achieved by a fragment shader and the bubble sprites by using GLKBaseEffect. But when calling these two drawing functions subsequently, it display only the one or the other. There's something mixed up within the shaders.
- How can I combine a custom fragment shader with GLKBaseEffect ?
- Or how can I substitute the GLKBaseEffect with a custom shader (in order to display a 2D-texture as a sprite ?
Here's an illustration of the issue and the goal:
Please have a look at my sample application (I boiled it down to the essential parts):
Download-Link Sample App: AnimatedBackground.zip
Here's a short explanation of the involved classes:
Sprite.m: This is a wrapper for loading and drawing a texture from a *.png file (plus SRT, alpha blending, etc.)
BaseShader.m: This is the wrapper for loading and applying the shader files (Base.vsh & Gradient.fsh)
WallpaperController.m: This is a subclass of GLKViewController that I will use as base class for all of my UIViewController's. I defined the Sprite and Shader instances static, since I want to have a sole instance for all of my view controllers (the animation of the bubbles should move on constantly while transitioning between view controllers).
Toolkit.h: Some helper functions (random integers, etc.)