[FIXED] Same background color for PC and Android

If there is something important you think is missing in the current version of ZGameEditor then you can post a feature request here!

Moderator: Moderators

Post Reply
User avatar
Ats
Posts: 762
Joined: Fri Sep 28, 2012 10:05 am
Contact:

[FIXED] Same background color for PC and Android

Post 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.
Last edited by Ats on Tue Jul 06, 2021 7:38 am, edited 1 time in total.
User avatar
VilleK
Site Admin
Posts: 2355
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Same background color for PC and Android

Post 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.
User avatar
Ats
Posts: 762
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Same background color for PC and Android

Post 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.
User avatar
Kjell
Posts: 1915
Joined: Sat Feb 23, 2008 11:15 pm

Re: Same background color for PC and Android

Post 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
User avatar
Ats
Posts: 762
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Same background color for PC and Android

Post 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?
User avatar
Kjell
Posts: 1915
Joined: Sat Feb 23, 2008 11:15 pm

Re: Same background color for PC and Android

Post 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
User avatar
Ats
Posts: 762
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Same background color for PC and Android

Post 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.
User avatar
Kjell
Posts: 1915
Joined: Sat Feb 23, 2008 11:15 pm

Re: Same background color for PC and Android

Post 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
User avatar
Ats
Posts: 762
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Same background color for PC and Android

Post 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:
User avatar
Kjell
Posts: 1915
Joined: Sat Feb 23, 2008 11:15 pm

Re: Same background color for PC and Android

Post 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
Post Reply