I'm making a sky gradient in OpenGL by drawing with glColorPointer and glDrawArrays. I would like to be able to change the sky colour from morning to daytime to evening etc. I can either:
- Make a number of sprites and fade them in with my framework
- Somehow tween the color vector in openGL over time and use a single sprite
The second one seems like a more efficient option, but my framework doesn't pass the time delta into the draw method for me to decide how far I've progressed into fading.
Here's my current code:
glDisable(GL_BLEND);
glDisable(GL_DITHER);
glDisable(GL_FOG);
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
CGSize size = [[CCDirector sharedDirector] winSize];
float w = size.width;
float h = size.height;
const GLfloat vertices[] = {
0, 0,
w, 0,
0, h/3,
w, h/3,
0, h*2/3,
w, h*2/3,
0, h,
w, h,
};
const GLubyte colors[] = {
254,255,134,255,
254,255,134,255,
230,157,0,255,
230,157,0,255,
230,60,0,255,
230,60,0,255,
167,0,86,255,
167,0,86,255,
};
glVertexPointer(2, GL_FLOAT, 0, vertices);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 8);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glEnable(GL_TEXTURE_2D);
Which gives me:

