Page 1 of 1

[FIXED] Same background color for PC and Android

Posted: Mon Jul 05, 2021 7:24 am
by Ats
If we do not set App.ClearColor on the project, screen is black on PC, but white on Android.
If we set a color to something else (ex: RED), it is red on both.
Then, if we set it to BLACK again, it's black on both.

So I suspect that the base background color isn't black, but full transparent.
I suggest that App.ClearColor is set to Black instead of transparent for new projects,
or we could modify the ZgeActivity.java so that the Activity color isn't white, but black by adding:

Code: Select all

import android.graphics.Color;
...
setContentView( zge );
getWindow().getDecorView().setBackgroundColor(Color.BLACK);

NB:
This doesn't solve the transparency problem on Android.

Re: Same background color for PC and Android

Posted: Mon Jul 05, 2021 8:01 am
by VilleK
Its been a long time since I looked at the ZGE Java code. Maybe the recommended way to initialize an OpenGL application is completely different now compared to when this code was written.

When I try searching for "Android transparent OpenGL surface" then the normal problem seems to be that the surface is not transparent by default.

I don't have a Android development environment so it is hard for me to try things. Please do some more investigations. I suspect the problem lies in the Java code somewhere.

Re: Same background color for PC and Android

Posted: Mon Jul 05, 2021 10:02 am
by Ats
After reading that: https://developer.android.com/training/ ... nvironment
I tried adding in zge.java :

Code: Select all

import android.opengl.GLES20;
...
public void onSurfaceCreated( GL10 gl, EGLConfig config )
{
   if(DEBUG) Log.i("ZgeAndroid", "SurfaceCreated: " + gl.glGetString( GL10.GL_VERSION ));

   // Set the background frame color
   GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

   NativeSurfaceCreated();
}
...
public void onDrawFrame( GL10 gl )
{
   GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
            
   if(NativeDrawFrame())
      IsDestroy=true;

   if ( IsDestroy )
      Finish();
}
and

<uses-feature android:glEsVersion="0x00020000" android:required="true" />
is already set in the AndroidManifest.xml

But it doesn't solve the Android transparency problem, nor the background color.

Re: Same background color for PC and Android

Posted: Mon Jul 05, 2021 10:27 am
by Kjell
Hi Ats,
Ats wrote: Mon Jul 05, 2021 7:24 amIf we do not set App.ClearColor on the project, screen is black on PC, but white on Android.
If we set a color to something else (ex: RED), it is red on both. Then, if we set it to BLACK again, it's black on both.
Keep in mind that by default App.ClearColor is {0,0,0,0} ( which matches the default glClearColor state of OpenGL ), but once you select black using the color picker you end up with {0,0,0,1}.

K

Re: Same background color for PC and Android

Posted: Mon Jul 05, 2021 12:37 pm
by Ats
That is what I suspected in my first post.
In which case it interesting to start with {0,0,0,0} since the exe can't be transparent?

Re: Same background color for PC and Android

Posted: Mon Jul 05, 2021 1:03 pm
by Kjell
Hi Ats,
Ats wrote: Mon Jul 05, 2021 12:37 pmThat is what I suspected in my first post.
If you start a new project and right-click on the color box of App.ClearColor you can see that its alpha value is 0 :wink:
Ats wrote: Mon Jul 05, 2021 12:37 pmIn which case it interesting to start with {0,0,0,0} since the exe can't be transparent?
You mean a Windows standalone executable? Since Windows Vista there's the option to ( easily ) make the background of a window (semi-)transparent, but it's not enabled by default.

The decision of OpenGL using {0,0,0,0} as default might come from early GLide / OpenGL GPUs being 3D add-on cards instead of standalone cards ( connected to a traditional / 2D GPU using a VGA-to-VGA passthrough cable ), but that's just a wild guess.

Image

K

Re: Same background color for PC and Android

Posted: Mon Jul 05, 2021 2:43 pm
by Ats
So the two lines of code in my first post solves the background color on Android, so it is the same as Windows when the ZGE app background color is transparent :wink:

The alpha problem on Android is another problem yet to solve. I'm going to make a little PR on github.

Re: Same background color for PC and Android

Posted: Mon Jul 05, 2021 3:49 pm
by Kjell
Hi Ats,

Setting the Android activity background to black is probably the easiest OS "solution" yea 8)

By the way, when you enable background transparency in Windows you actually get a semi-transparent result by default ( which is different from Linux ). Not that it matters, but just to indicate that these kind of differences are OS dependent, not OpenGL dependent.

Image

K

Re: Same background color for PC and Android

Posted: Mon Jul 05, 2021 4:27 pm
by Ats
Oh nice, I didn't know about that. Last time I saw something like that was with the good old Winamp skins :lol:

Re: Same background color for PC and Android

Posted: Mon Jul 05, 2021 6:40 pm
by Kjell
Hi Ats,
Ats wrote: Mon Jul 05, 2021 4:27 pmOh nice, I didn't know about that.
You can do fully transparent as well of course, which makes the behavior similar to Android / WebGL. Below is what a simple RenderParticles project looks like with the Spotify website in the background ( click image for short video ).

Image
Ats wrote: Mon Jul 05, 2021 4:27 pmLast time I saw something like that was with the good old Winamp skins :lol:
The WinAmp skins used a different technique, but yea .. transparent windows haven't been very popular on PC the last couple of decades :P

K