user1405328
user1405328

Reputation: 33

Android GLSurfaceView OpenGL ES with linear-gradient background?

with this code, I can clear the background and add a color:

gl.glEnable(GL10.GL_DEPTH_TEST);    
gl.glClearColor(0.0f, 0.25f, 0.35f, 1.0f);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

How can i change this to have a linear-gradient Background? e.g. White color at the top and blue color at the bottom?

Upvotes: 2

Views: 1712

Answers (1)

Tim
Tim

Reputation: 35933

There's no method to clear to a gradient, but I'd just draw a colored quad instead of clearing the color:

void drawFrame() {
   glDisable(GL_DEPTH_TEST);
   //draw screen aligned quad with color gradient 
   //    (top two vertices white, bottom two blue)
   drawGradientQuad();

   glClear(GL_DEPTH_BUFFER_BIT); //no need to clear color

   glEnable(GL_DEPTH_TEST);
   //draw rest of scene
}

Upvotes: 1

Related Questions