ZGameEditor & Android Setting

All topics about ZGameEditor goes here.

Moderator: Moderators

User avatar
VilleK
Site Admin
Posts: 1975
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: ZGameEditor & Android Setting

Post by VilleK » Tue Dec 11, 2018 7:14 pm

I tested your zpong apk here now on Samsung S9. The background and ball is full white while the textured bats look correct. Sound is correct too.

I have no guess so far why it would look like this.

User avatar
VilleK
Site Admin
Posts: 1975
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: ZGameEditor & Android Setting

Post by VilleK » Wed Dec 12, 2018 8:47 am

In ZPong, I see that BallMaterialTexture use "Generated" TexCoords, and I remember that Android (GL ES) does not support that. As for the white background, maybe try creating a project that animates App.ClearColor and see what happens? Something like "App.ClearColor.R=frac(App.Time*0.5);".

User avatar
Ats
Posts: 219
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: ZGameEditor & Android Setting

Post by Ats » Wed Dec 12, 2018 11:00 am

Changing the App.ClearColor isn't working either. In Omeganaut, the planet sky appears correctly, but it is shown using alpha transparency and its material have Blend="1".

Here's the 8 template folder if anyone wants to run tests with me.
Attachments
8 (API 26).zip
Template folder for API 26
(301.06 KiB) Downloaded 19 times
Last edited by Ats on Wed Dec 12, 2018 11:15 am, edited 1 time in total.

User avatar
Kjell
Posts: 1695
Joined: Sat Feb 23, 2008 11:15 pm

Re: ZGameEditor & Android Setting

Post by Kjell » Wed Dec 12, 2018 11:09 am

Hi guys,

Try clearing the screen using a alpha value of 1 ( instead of the default 0 ). Unfortunately you can't do this using App.ClearColor right now ( as the alpha value is ignored ), so you need to execute the following OpenGL calls ( after the screen is cleared by ZGE but before anything is rendered ).

Code: Select all

glClearColor(0, 0, 0, 1);
glClear(0x4100); // Clear color & depth bits
Perhaps Android uses the alpha channel of the frame-buffer as mask by default now .. so the default ( white ) composition below the OpenGL context ends up showing. Just a wild guess though.

K

User avatar
Ats
Posts: 219
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: ZGameEditor & Android Setting

Post by Ats » Wed Dec 12, 2018 4:39 pm

So I've played with the alpha of the ball generated texture:

Code: Select all

pixel.R = sin(sqrt(x*x + y*y)*16);
pixel.G = sin(sqrt(x + y*y)*25);
pixel.B = 0;
pixel.A = 1;
If pixel.A == 0 the ball is full white.
If pixel.A == 1 the ball is full black.

Then I made some tests with the OpenGL calls. If I put them in App.OnBeginRenderPass, nothing change.
But if I put them in App.OnRender (with App.RenderOrder = AppBeforeModels), the background is black, but the ball is still white.

Edit:
I just tried Omeganaut with App.RenderOrder = AppBeforeModels and OpenGL calls inside App.OnRender. It's better, but the models are still overexposed. I'm not sure that it'coming from the alpha...
Image

User avatar
Kjell
Posts: 1695
Joined: Sat Feb 23, 2008 11:15 pm

Re: ZGameEditor & Android Setting

Post by Kjell » Wed Dec 12, 2018 6:08 pm

Hi Ats,
Ats wrote:
Wed Dec 12, 2018 4:39 pm
Then I made some tests with the OpenGL calls. If I put them in App.OnBeginRenderPass, nothing change.
That's because when you use the OpenGL calls in OnBeginRenderPass, they get negated by the built-in clear calls shortly thereafter.
Ats wrote:
Wed Dec 12, 2018 4:39 pm
But if I put them in App.OnRender (with App.RenderOrder = AppBeforeModels), the background is black, but the ball is still white.
What blending mode are you using? Not every blending mode is supported by OpenGL ES.

K

User avatar
VilleK
Site Admin
Posts: 1975
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: ZGameEditor & Android Setting

Post by VilleK » Thu Dec 13, 2018 8:32 am

@Kjell: do you think I should change so that ZApplication use the alpha value of ClearColor?

User avatar
Kjell
Posts: 1695
Joined: Sat Feb 23, 2008 11:15 pm

Re: ZGameEditor & Android Setting

Post by Kjell » Thu Dec 13, 2018 9:17 pm

Hej Ville,
VilleK wrote:
Thu Dec 13, 2018 8:32 am
do you think I should change so that ZApplication use the alpha value of ClearColor?
Yea, i don't see how it could hurt really .. besides, the default alpha value is 0 anyway.

K

User avatar
VilleK
Site Admin
Posts: 1975
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: ZGameEditor & Android Setting

Post by VilleK » Fri Dec 14, 2018 8:07 am

Ok, committed change to Github so that ClearColor.A is used (both in App and RenderTarget).

@Ats: After updating and rebuilding, make sure to set A value in your project. It can be done like this in OnLoaded:

Code: Select all

if(ANDROID)
  App.ClearColor.A=1;

User avatar
Ats
Posts: 219
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: ZGameEditor & Android Setting

Post by Ats » Fri Dec 14, 2018 10:51 am

Here's the new libzgeandroid.so and a new APK for zpong. I'll try playing with the background color when I'll get home to see if everything's good for that.
Attachments
libzgeandroid.zip
(275.07 KiB) Downloaded 18 times
ZPong_api26 -debug.apk
(289.44 KiB) Downloaded 18 times

User avatar
VilleK
Site Admin
Posts: 1975
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: ZGameEditor & Android Setting

Post by VilleK » Mon Dec 17, 2018 1:45 pm

@Ats: I know you made notes already in this thread, but please also when you have time write a list of steps required to get latest Fpc for Android working with ZGE. So I can set this up myself later.

User avatar
Ats
Posts: 219
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: ZGameEditor & Android Setting

Post by Ats » Mon Dec 17, 2018 5:33 pm

Hahaha. That's a huge task. Luckily I wrote everything on a side note as I found how to do everything. Here's the tutorial. Maybe it can be optimized, but it should work.


JAVA

Install latest Java:
https://www.java.com/fr/download/

Install latest Java JDK:
https://www.oracle.com/technetwork/java ... index.html

Set environment variable JAVA_HOME C:\Program Files\Java\jdk1.8.0_191


ANDROID

Install Android NDK :
https://developer.android.com/ndk/downloads/
Unzip it inside c:\Android

Install Android SDK and Apache Ant:
Unfortunately, Android SDK is now included inside the HUGE Android Developer Studio. So the easiest way to get SDK and Ant is to install LazToApk:
https://sourceforge.net/projects/laztoapk/

And then retrieve those directories:
C:\laztoapk\downloads\android-sdk-windows
C:\laztoapk\downloads\apache-ant-1.10.3
Just copy/paste them inside C:\Android

Now you should have:
C:\Android\android-ndk-r18b
C:\Android\android-sdk-windows
C:\Android\apache-ant-1.10.3

And you can uninstall LazToApk.


Update Android SDK:
Launch C:\Android\android-sdk-windows\SDK Manager.exe

Here's what you need:
Tools \ Android SDK Tools
Tools \ Android SDK Platform-tools
Tools \ Android SDK Build-tools
Android 8.0.0 (API 26) \ SDK Platform
Android 4.1.2 (API 16) \ SDK Platform


FREE PASCAL

Install Free Pascal official release:
https://sourceforge.net/projects/freepa ... in32/3.0.4
fpc-3.0.4.i386-win32.exe
It should be installed to C:\FPC\3.0.4

Download Free Pascal Daily Source Snapshot of Development Tree (trunk):
https://www.freepascal.org/develop.var
Extract it to C:\FPC

Create the directory C:\FPC\trunk

Build Free Pascal trunk:
Inside C:\FPC\fpc, create make_i386.bat with:

Code: Select all

PATH=C:\FPC\3.0.4\bin\i386-win32;
SET FPC=C:\FPC\3.0.4\bin\i386-win32\fpc.exe
make.exe clean  distclean
make.exe all  OPT="-gw -godwarfset -O-1"  
make.exe install  INSTALL_PREFIX=c:\FPC\trunk  COPYTREE=echo 
Launch make_i386.bat and make some coffee.

Build Free Pascal cross Android Trunk:
Inside C:\FPC\fpc, create make_android.bat with:

Code: Select all

PATH=C:\FPC\3.0.4\bin\i386-win32;C:\Android\android-ndk-r18b\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin;
SET FPC=C:\FPC\3.0.4\bin\i386-win32\fpc.exe
make clean crossall crossinstall OS_TARGET=android CPU_TARGET=arm CROSSOPT="-dANDROID -CpARMv6 -CfVFPv2" INSTALL_PREFIX=C:\FPC\trunk
Launch make_android.bat and go outside for some fresh air.

Add C:\Android\android-ndk-r18b\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin
to your System environment variable Path


ZGAMEEDITOR

Download ZGameEditor source code:
https://github.com/VilleKrumlinde/zgameeditor

Here's my modified C:\zgameeditor-master\Build\android\m.bat with the correct folders:

Code: Select all

pushd "%~dp0"

if not exist "java\libs\armeabi\" mkdir java\libs\armeabi
if not exist "lib\arm-linux\" mkdir lib\arm-linux

C:\FPC\trunk\bin\i386-win32\ppcrossarm -B -MDelphi -Sghi -O3 -Tandroid -Parm -XXis -vw -Filib\arm-linux -FlC:\Android\android-ndk-r18b\platforms\android-26\arch-arm\usr\lib -Fu. -Fu..\.. -FUlib\arm-linux\ -FEjava\libs\armeabi\ -olibzgeandroid.so -dANDROID -dMINIMAL -Xd -CpARMV6 -CfVFPv2 zgeandroid.pas

IF %ERRORLEVEL% NEQ 0 GOTO error
cd java
call m.bat
cd ..
:error

popd

pause


And finally here's my modified AndroidManifest.xml:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="$package$"
    android:versionCode="$versionnumber$"
    android:versionName="$versionname$" >

    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
    <uses-feature android:name="android.hardware.gamepad" />

    <application
        android:icon="@drawable/icon"
        android:label="$title$" >

        <meta-data android:name="isGame" android:value="true" />
       
        <activity
            android:label="$title$"
            android:name="org.zgameeditor.ZgeActivity"
            android:configChanges="screenLayout|orientation|keyboardHidden|fontScale"
            android:screenOrientation="sensorLandscape" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
And the default.properties file:

Code: Select all

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
# 
# This file must be checked in Version Control Systems.
# 
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.

# Project target.
target=android-26
Last edited by Ats on Tue Jan 08, 2019 6:31 pm, edited 1 time in total.

User avatar
VilleK
Site Admin
Posts: 1975
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: ZGameEditor & Android Setting

Post by VilleK » Tue Dec 18, 2018 7:46 am

Thanks Ats :). Wow, that is indeed a lot of work.

User avatar
Ats
Posts: 219
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: ZGameEditor & Android Setting

Post by Ats » Thu Dec 20, 2018 10:31 am

I'm up to something!
In Omeganaut, I don't use textures. I prefer full colored shapes using MeshExpression. And it seems that when making an apk API 26, the alpha if the VertexColors is set to 0.5 (+/-) instead of 1. Or maybe the alpha value is divided by 10 at some point?

So if I set my color like that, everything is ok.

Code: Select all

C.R=1;
C.G=0;
C.B=0;
C.A=1;
I think it's the same for textured polygons. Maybe we should force that directly in ZGE sourcecode instead of setting the alpha on each and every meshes?

User avatar
VilleK
Site Admin
Posts: 1975
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: ZGameEditor & Android Setting

Post by VilleK » Thu Dec 20, 2018 12:17 pm

I checked the code and ZGE does not set any default values for the mesh colors so alpha can be any value (but most likely zero). What material do you render your mesh with? Does it use blending or not? For some reason I guess that on Android it uses blending but not on Windows.

Post Reply