Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set background colour on Open GL ES Android

I am currently playing about with lesson 08 here

http://insanitydesign.com/wp/projects/nehe-android-ports/

I would like to change the background colour from black to white. In order to do this at the start of onDrawFrame() I have called

gl.glClearColor(1.0f, 0.0f, 0.0f, 0.0f);

This does indeed set a white background screen, but also results in nothing else showing up on the screen! Clearly this is therefore an incorrect method, but why, and how do I fix it?!

Many thanks in advance.

Edit (5 days later): Does nobody know at all?!!

like image 329
user455141 Avatar asked Sep 27 '10 17:09

user455141


People also ask

How do I change the background color in OpenGL?

glClearColor(0,0,1,0); then recompile the program and run it. The background of the OpenGL window should be blue. Colors in OpenGL are typically represented in RGB or RGBA mode.

Does Android use OpenGL es?

Android includes support for high performance 2D and 3D graphics with the Open Graphics Library (OpenGL®), specifically, the OpenGL ES API. OpenGL is a cross-platform graphics API that specifies a standard software interface for 3D graphics processing hardware.


2 Answers

The white screen is because you have set the alpha value to 0.0f.

The parameter signature is:- gl.glClearColor(float red, float green, float blue, float alpha) where floats are any value between 0.0 to 1.0.

More the float value of alpha more opaque the screen is.

like image 82
Debopam Mitra Avatar answered Sep 21 '22 13:09

Debopam Mitra


After you call gl.glClearColor(), redraw everything else. gl.glClearColor() does not change background color, it simply fills the screen with white color (which in effect erases everything you've previously drawn).

like image 23
Lie Ryan Avatar answered Sep 18 '22 13:09

Lie Ryan