问题
Is there any way to make an entire Android OpenGL ES scene transparent? This would be useful for widgets and wallpapers.
There is one Android-specific answer here. But my understanding is that this technique creates a transparent background, upon which one could furthermore draw transparent shapes.
I am looking for a way to make the entire scene transparent after it has been drawn. For instance, is there any way to change the alpha of the entire color buffer after the scene has been drawn?
回答1:
Yes, and it's quite easy. You need to blend the values in the color buffer, by covering the whole view with a quad using the right color and blending function. I think this will do the trick:
- Draw your scene as normal
- set
glBlendFunc(GL10.GL_ZERO, GL10.GL_SRC_COLOR) - Draw an untextured colored quad that covers the whole view with (R,G,B,A) = (1,1,1,a) where a is your desired opacity
This should scale the alpha of the colorbuffer with a, which I think is what you want.
回答2:
If you can require API 14 (Android 4.0) then there's a new class that addresses this very issue: TextureView. There's some info about it in this Android Developers blog post. Unfortunately I don't think there's an easy way to do this in previous versions of Android.
来源:https://stackoverflow.com/questions/8249362/any-way-to-make-an-entire-android-opengl-es-scene-transparent