Lazarus

Announcements => Lazarus => Topic started by: felipemdc on November 11, 2011, 05:52:50 am

Title: New OpenGL Android Example
Post by: felipemdc on November 11, 2011, 05:52:50 am
Hello,

There is a new Android NDK example in the Lazarus CCR. The most important thing that this example adds is that there are precise step-by-step instructions for the entire process and also a full project structure for building it. The instructions cover from configuring the cross-compiler up to installing the APK in the telephone:

http://wiki.lazarus.freepascal.org/Android_Interface/Android_Programming#Build_the_NDK_OpenGL_example

The example itself is very simple, and just processes some touch screen inputs and draws some colors in the screen.

It uses JNI and the NativeActivity so it runs on all phones with Android 2.3+ (because the cross-compiler uses soft-float). In this example there is zero Java source code, the NativeActivity does everything that we need. This method is fully sponsored by Google, so applications built like that are really on the safe side.

I am no OpenGL expert, so I don't know yet much about this part, so I just reused older examples for that, but what really amazed me is that I was able to create a project which correctly links to Android native libraries from the NDK, so I gained some knowledge here which I tought people might find useful:

1> Copying .so libraries from the device to link to them is not required, just link against the .so files which are in the NDK
2> Specifying the path to the .so files with -Fl works nicely as described in the example instructions
3> I previously heard from someone that FPC had some initialization issues in Android libs, but I haven't found any in this project (I still have to check if it doesn't appear if I added more units to the uses clause)
4> It is possible to write an application which uses OpenGL and touch screen input with zero Java code =D
5> You need at least ant 1.8 to use the latest Android SDK, so you might need to upgrade your Linux (I had to upgrade from Mandriva 2010 to Mageia 1 for this)

I hope you enjoy,
Title: Re: New OpenGL Android Example
Post by: Stoney on November 12, 2011, 04:45:29 pm
This is awesome. Thank you so much. Haven't had a chance to try this yet, but I will very soon.
Title: Re: New OpenGL Android Example
Post by: Leledumbo on November 12, 2011, 11:53:27 pm
First problem, I got error regarding missing /lib/ld-linux.so.3, that's easy to fix looking at another thread (http://www.lazarus.freepascal.org/index.php/topic,15108.15.html). Second one, I got this:
Quote
C:\fpc\bin\i386-win32\arm-linux-ld.exe: warning: E:\Sources\lazarus-fpc\android-ndk\examples\opengltest\android\libs\armeabi\link.res contains output sections; did you forget -T?
E:\Sources\lazarus-fpc\android-ndk\examples\opengltest\lib\arm-linux\ndkopengltest.o: In function `FPC_SHARED_LIB_START':
ndkopengltest.pas:(.text.n_p$ndkopengltest_$$_fpc_shared_lib_start+0x0): multiple definition of `FPC_SHARED_LIB_START'
C:\fpc\units\arm-linux\rtl\dllprt0.o:dllprt0.as:(.text+0x0): first defined here
ndkopengltest.pas(255,37) Error: Error while linking
For this one, I have no idea...
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 13, 2011, 02:41:48 pm
For this one, I have no idea...

I had tested it with my FPC 2.5 snapshot and some things changed in the compiler in the mean time. Do svn update, it should be fixed now.
Title: Re: New OpenGL Android Example
Post by: Laksen on November 13, 2011, 03:14:08 pm
felipemdc, the problem with FPC_SHARED_LIB_START has been fixed in svn trunk, so it should be removed from the example

Specifically this should be removed:
Code: [Select]
procedure PASCALMAIN; external name 'PASCALMAIN';

procedure FPC_SHARED_LIB_START; [public, alias: 'FPC_SHARED_LIB_START'];
begin
   PASCALMAIN;
end;
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 13, 2011, 04:33:34 pm
felipemdc, the problem with FPC_SHARED_LIB_START has been fixed in svn trunk, so it should be removed from the example

I already fixed that. That's what I ment on Reply #3 on: Today at 09:41:48 am »
Title: Re: New OpenGL Android Example
Post by: Leledumbo on November 14, 2011, 04:09:52 pm
OK, compiled. But got exception when running:
Quote
E/AndroidRuntime(15688): FATAL EXCEPTION: main
E/AndroidRuntime(15688): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pascal.opengltest/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/data/com.pascal.opengltest/lib/libmain.so
Any reason why? I have android-10 for the SDK and android-9 for the NDK (I have no idea why the NDK skips version 10, it jumps over to 14).
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 14, 2011, 04:25:11 pm
OK, compiled. But got exception when running:
E/AndroidRuntime(15688): FATAL EXCEPTION: main
E/AndroidRuntime(15688): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pascal.opengltest/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/data/com.pascal.opengltest/lib/libmain.so

Another person had exactly the same error, and he was also trying to do it from Windows.

I had no problem in Linux.

some ideas:
1> Did you configure the binutils for eabi=5?
2> Did you compile your cross-compiler with software floating point?

Quote
I have android-10 for the SDK and android-9 for the NDK (I have no idea why the NDK skips version 10, it jumps over to 14).

I think they jumped because they didn't change anything in the NDK between these versions, it should be no problem. For me it worked fine
Title: Re: New OpenGL Android Example
Post by: Gintas on November 14, 2011, 09:26:43 pm
Gee,too bad it only runs on Android 2.3+ .  :(
I thought about testing it on a real hardware.
Title: Re: New OpenGL Android Example
Post by: Laksen on November 14, 2011, 10:51:17 pm
A related entry has surfaced over at pascalgamedevelopment here: http://www.pascalgamedevelopment.com/showthread.php?11624-Android-game-FoembJump-now-opensourced

BeRo has opensourced an Android game which apparently works in more version
Title: Re: New OpenGL Android Example
Post by: Leledumbo on November 15, 2011, 12:35:47 am
Quote
Another person had exactly the same error, and he was also trying to do it from Windows.

I had no problem in Linux.
Hmm... that seems weird, I'll try on Linux tonight.
Quote
Did you configure the binutils for eabi=5?
Uhuh, I did it by renaming the original assembler to arm-linux-as.orig.exe and create a wrapper program named arm-linux-as.exe with this contents:
Code: [Select]
program arm_linux_as;

uses
  SysUtils;
var
  Params: array of AnsiString;
  i: Word;
begin
  SetLength(Params,ParamCount + 1);
  Params[0] := '-meabi=5';
  for i := 1 to ParamCount do
    Params[i] := ParamStr(i);
  ExecuteProcess(IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0))) +
    'arm-linux-as.orig.exe',Params);
end.
Quote
Did you compile your cross-compiler with software floating point?
I'm not sure about this one, I only pass -dFPC_ARMEL when building.
Title: Re: New OpenGL Android Example
Post by: Rustam Asmandiarov on November 16, 2011, 05:42:35 am
Thank you so much! This is very cool!
But I noticed that you download the OpenGL statically. How do I compile android app loading OpenGL dynamically via dynlibs, that is, through LoadLibrary and GetProcedureAddress?
I use FPC 2.7.1 and your demo has not tried to run me just interested in the source code

Огромнейшее спасибо!!! Это очень клево!
Но я заметил что вы загружаете OpenGL статически. Как мне скомпилировать Андроид приложение загружая OpenGL динамически через dynlibs, то есть через LoadLibrary и GetProcedureAddress?
Я использую FPC 2.7.1 и ваше демо еще не пробовал запускать мне просто интересен исходный код.
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 16, 2011, 07:09:14 am
Thank you so much! This is very cool!
But I noticed that you download the OpenGL statically. How do I compile android app loading OpenGL dynamically via dynlibs, that is, through LoadLibrary and GetProcedureAddress?

What for? The demo requires Android 2.3+ for multiple reasons, not just OpenGL. It also uses NativeActivity extensively. So if you can accept that it runs on 2.3+ only then you don't need to dynamically load anything because the existence of the required libraries is 100% guaranteed in Android.

Quote
I use FPC 2.7.1 and your demo has not tried to run me just interested in the source code

That's probably a bad idea to use 2.7 for Android, there were multiple breaks in 2.7 in the Android cross-compiler, you can even work around that by changing some parts of the compiler source code, but I still think that people would save themselves a lot of work by just using my Linux snapshot pre-compiled compiler, as described in the step-by-step instructions.
Title: Re: New OpenGL Android Example
Post by: herux on November 16, 2011, 07:34:27 am
Quote
How do I compile android app loading OpenGL dynamically via dynlibs, that is, through LoadLibrary and GetProcedureAddress?

I've tried to compile it using dynlib, but an error like the following link http://www.lazarus.freepascal.org/index.php?topic=12585.0

I have not tried it again, there's new?
Title: Re: New OpenGL Android Example
Post by: Rustam Asmandiarov on November 16, 2011, 07:55:05 am
I ported GLScene 1.2 for Android. GLScene completely based on the dynamic link library and uses dynlibs which produces an error when connecting.
Just GLScene 1.2 uses the C # naming style modules, such as GLScene.Base.OpenGL.Tokens.pas it's only available in 2.7.1, if you add in 2.5.1 the same opportunity that would be great!

Я портирую GLScene 1.2 на Android. GLScene Полностью основан на динамически загружаемой библиотеке и использует dynlibs которая выдает ошибки при подключении.
Так же GLScene 1.2 использует С# стиль именования модулей, например GLScene.Base.OpenGL.Tokens.pas а он доступен только в 2.7.1, если вы добавите в 2.5.1 такую же возможность это будет замечательно!
Title: Re: New OpenGL Android Example
Post by: Jonathan on November 17, 2011, 07:25:31 am
Hi  felipemdc,At the Step 4,build the project using Lazarus,An error happens,thank you!
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 17, 2011, 07:30:26 am
Did you really do everything described in step 4?

Please post a screenshot of your project options->paths
Title: Re: New OpenGL Android Example
Post by: Jonathan on November 17, 2011, 08:04:25 am
Do I have to download the lastest  lazarus SVN???  I use the crosscompiler as I did in the "  First steps of LCL-Android are ready"
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 17, 2011, 08:06:56 am
Your "Messages" screenshot is cutted, please paste here the full messages.

Also a screenshot of Project Options -> Code Generation would be good.
Title: Re: New OpenGL Android Example
Post by: Rustam Asmandiarov on November 17, 2011, 08:15:03 am
felipemdc what you think about my previous post?
Title: Re: New OpenGL Android Example
Post by: Jonathan on November 17, 2011, 08:18:07 am
Do I have to download the lastest  lazarus SVN???  I use the crosscompiler,lazarus,fpc as I did in the "  First steps of LCL-Android are ready" the same!

AS pictures show:       
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 17, 2011, 08:24:30 am
Just GLScene 1.2 uses the C # naming style modules, such as GLScene.Base.OpenGL.Tokens.pas it's only available in 2.7.1, if you add in 2.5.1 the same opportunity that would be great!

The work for doing this is huge, one would have to branch out a FPC 2.5.1 from aprox. 19th January and then merge things which added this feature hoping that there will be no incompatibilities and test everything. No chance I'm doing this huge work.

Your best change is to either:

1> Wait until 2.7 is fixed for Android
or
2> to modify GLScene so that it doesn't use the points in filenames. Why did they do that anyway? That breaks compatibility with released FPC versions.
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 17, 2011, 08:27:24 am
Do I have to download the lastest  lazarus SVN???

I don't know, I tested this with Lazarus SVN, I simply don't know if something will fail in Lazarus 0.9.30

Quote
AS pictures show:       

Ah, not this Messages, but the same one which you already posted a screenshot for in your first message when you wrote this:

> Hi  felipemdc,At the Step 4,build the project using Lazarus,An error happens,thank you!

There are 2 linker errors, the first is a Warning. I cannot read the warning till the end of the line in your screenshot.
Title: Re: New OpenGL Android Example
Post by: Rustam Asmandiarov on November 17, 2011, 08:28:48 am
Just GLScene 1.2 uses the C # naming style modules, such as GLScene.Base.OpenGL.Tokens.pas it's only available in 2.7.1, if you add in 2.5.1 the same opportunity that would be great!

The work for doing this is huge, one would have to branch out a FPC 2.5.1 from aprox. 19th January and then merge things which added this feature hoping that there will be no incompatibilities and test everything. No chance I'm doing this huge work.

Your best change is to either:

1> Wait until 2.7 is fixed for Android
or
2> to modify GLScene so that it doesn't use the points in filenames. Why did they do that anyway? That breaks compatibility with released FPC versions.

Thank you, I consulted with the developers how best to do it!
Prompt please link to the repository Compiler 2.5.1

Спасибо, я посовещаюсь с разработчиками как лучше сделать!
Подскажите пожалуйста ссылку на репозиторий компилятора 2.5.1
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 17, 2011, 08:38:44 am
Prompt please link to the repository Compiler 2.5.1

2.5.1 from 19th January is the Free Pascal Trunk from 19th January:

http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/

Here you can check which revisions match it. For example this one matches it:

http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&revision=16750

You can download this with these commands:

svn checkout http://svn.freepascal.org/svn/fpc/trunk fpctrunk
cd fpctrunk
svn up -r 16750

In the beginning of February a Android break was introduced, so I would only use revision from January as a starting point.

After you download the sources from January to need to modify them in your local copy or copy them to a new repository of your own to work on them, which you can open for example in sourceforge.
Title: Re: New OpenGL Android Example
Post by: Jonathan on November 17, 2011, 08:39:11 am
ah ah  ah!  sorry! These 2 errors as the follows:
Code: [Select]
ndkopengltest.pas(37,11) Note: Local variable "dummy" not used
ndkopengltest.pas(204,19) Hint: Local variable "engine" does not seem to be initialized
ndkopengltest.pas(194,11) Hint: Local proc "android_main" is not used
/home/hotcyy/lazarus/fpc/binutils/ld: warning: /home/hotcyy/lazarus-ccr/bindings/android-ndk/examples/opengltest/android/libs/armeabi/link.res contains output sections; did you forget -T?
/home/hotcyy/lazarus/fpc/binutils/ld: cannot find -lGLESv1_CM
ndkopengltest.pas(36,1) Error: Error while linking
ndkopengltest.pas(36,1) Fatal: There were 1 errors compiling module, stopping
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 17, 2011, 08:43:39 am
Does your -Fl directory really exist? Could you show what is inside it?
Title: Re: New OpenGL Android Example
Post by: Jonathan on November 17, 2011, 09:17:47 am
I download the lastest svn and try again,but meet the same errors!   The  lib includes "libGLESv1_CM.so".....
Title: Re: New OpenGL Android Example
Post by: Rustam Asmandiarov on November 17, 2011, 10:18:42 am
And what about dynlibs whether it will work in android with openGL? At the moment he calls the error:

/usr/local/bin/arm-linux-ld: warning: link.res contains output sections; did you forget -T?
/usr/local/bin/arm-linux-ld: skipping incompatible /usr/lib/crti.o when searching for /usr/lib/crti.o
/usr/local/bin/arm-linux-ld: cannot find /usr/lib/crti.o

Even with the compiler 2.5.1
I understand that the need for dynlibs it's silly, but it is needed for a project in which the module header record is 6000 lines of code and redo it all for android is even more foolish.

А что насчет dynlibs будет ли он работать в android с openGL? на данный момент он вызывает ошибки:
--------
Даже с компилятором 2.5.1
Я понимаю что надобность в dynlibs это глупо, но он нужен для проекта в котором модуль с заголовочными записями занимает 6 тысяч строчек кода и переделывать все это для андроида еще глупее.
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 17, 2011, 10:52:35 am
I download the lastest svn and try again,but meet the same errors!   The  lib includes "libGLESv1_CM.so".....

Strange, here it works in my Mageia 1 Linux. Which Linux are you using? Are you using my pre-compiled compiler?

If you right click the messages window and select "Copy all shown and hidden messages to clipboard" does it show more messages?

Another idea is to try to build in the command line to see if more messages appear. You can see which options Lazarus is using to call fpc by going to Project Options->Show Options

then copy that and try a command line build and see if more messages appear from the linker.

One idea also might be trying to remove the last "/lib" from the -Fl no idea if it will work, however
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 17, 2011, 10:53:37 am
And what about dynlibs whether it will work in android with openGL? At the moment he calls the error:

/usr/local/bin/arm-linux-ld: warning: link.res contains output sections; did you forget -T?
/usr/local/bin/arm-linux-ld: skipping incompatible /usr/lib/crti.o when searching for /usr/lib/crti.o
/usr/local/bin/arm-linux-ld: cannot find /usr/lib/crti.o

Please start a separate thread about your problems, since they are not related to the OpenGL example. There you can post a minimal test case to reproduce your issue and detail more about it.
Title: Re: New OpenGL Android Example
Post by: Jonathan on November 17, 2011, 11:16:27 am
The last part of the more error messages is that :
Code: [Select]
Assembling ndkopengltest
Linking /home/hotcyy/lazarus-ccr/bindings/android-ndk/examples/opengltest/android/libs/armeabi/libmain.so
/home/hotcyy/lazarus/fpc/binutils/ld: warning: /home/hotcyy/lazarus-ccr/bindings/android-ndk/examples/opengltest/android/libs/armeabi/link.res contains output sections; did you forget -T?
/home/hotcyy/lazarus/fpc/binutils/ld: cannot find -lGLESv1_CM
ndkopengltest.pas(36,1) Error: Error while linking
/home/hotcyy/lazarus/fpc/binutils/ld: warning: /home/hotcyy/lazarus-ccr/bindings/android-ndk/examples/opengltest/android/libs/armeabi/link.res contains output sections; did you forget -T?
/home/hotcyy/lazarus/fpc/binutils/ld: cannot find -lGLESv1_CM
ndkopengltest.pas(36,1) Error: Error while linking
ndkopengltest.pas(36,1) Fatal: There were 1 errors compiling module, stopping

the libs paths is not correct.. Is it????
Title: Re: New OpenGL Android Example
Post by: Rustam Asmandiarov on November 17, 2011, 01:03:43 pm
And what about dynlibs whether it will work in android with openGL? At the moment he calls the error:

/usr/local/bin/arm-linux-ld: warning: link.res contains output sections; did you forget -T?
/usr/local/bin/arm-linux-ld: skipping incompatible /usr/lib/crti.o when searching for /usr/lib/crti.o
/usr/local/bin/arm-linux-ld: cannot find /usr/lib/crti.o

Please start a separate thread about your problems, since they are not related to the OpenGL example. There you can post a minimal test case to reproduce your issue and detail more about it.
I wrote all here!
http://lazarus.freepascal.org/index.php/topic,15193.msg81702/topicseen.html#new
Title: Re: New OpenGL Android Example
Post by: YarUnderoaker on November 17, 2011, 01:24:17 pm
2> to modify GLScene so that it doesn't use the points in filenames. Why did they do that anyway? That breaks compatibility with released FPC versions.
No, no! GLScene has over 300 units - rename back will be hard and useless task.
Furthermore we work at new release and can break compatibility with old FPC until new one comes.
Also we like C# naming style which is promote in new latest Delphi and Lazarus - it clearly improves the readability and structuring :)
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 17, 2011, 02:07:29 pm
No, no! GLScene has over 300 units - rename back will be hard and useless task.
Furthermore we work at new release and can break compatibility with old FPC until new one comes.

Then it is your choice to break compatibility with existing FPC compilers like the Android cross-compiler. So you can explain to your users why it will be hard to get GLScene working on Android.

Quote
Also we like C# naming style which is promote in new latest Delphi and Lazarus - it clearly improves the readability and structuring :)

It is not "promoted" in Lazarus. Some support does not equate to "promoting"
Title: Re: New OpenGL Android Example
Post by: YarUnderoaker on November 17, 2011, 03:00:55 pm
Why are you so aggressively tuned, I'm not blaming anyone, and do not claim to do the work for me? I said something wrong?
We just need couple features and spend free time to do open source project without any own profit for many users which can use Lazarus too, so indirectly by participating in its popularization.
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 17, 2011, 03:13:47 pm
Why are you so aggressively tuned, I'm not blaming anyone, and do not claim to do the work for me?

Ok, sorry, I think I need vacations =D
Title: Re: New OpenGL Android Example
Post by: Jonathan on November 18, 2011, 03:38:48 am
Hi felipemdc,I'm sorry to trouble you again.At last I find the libs path is not correct ,so I copy all the files of lib to the opengltest directory to fix the problem(why the -Fl  doesnot work? I am confused) ,but another error shows .please do me a favor!
Code: [Select]
Assembling android_native_app_glue
ndkopengltest.pas(37,11) Note: Local variable "dummy" not used
ndkopengltest.pas(204,19) Hint: Local variable "engine" does not seem to be initialized
ndkopengltest.pas(194,11) Hint: Local proc "android_main" is not used
ndkopengltest.pas(4,21) Hint: Unit "native_activity" not used in ndkopengltest
Assembling ndkopengltest
Linking /home/hotcyy/lazarus-ccr/bindings/android-ndk/examples/opengltest/android/libs/armeabi/libmain.so
/home/hotcyy/lazarus/fpc/binutils/ld: warning: /home/hotcyy/lazarus-ccr/bindings/android-ndk/examples/opengltest/android/libs/armeabi/link.res contains output sections; did you forget -T?
ndkopengltest.pas(36,1) Error: Util /home/hotcyy/lazarus/fpc/binutils/strip not found, switching to external linking
ndkopengltest.pas(36,1) Fatal: There were 1 errors compiling module, stopping
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 18, 2011, 07:09:44 am
Strip is called after the binary was fully generated, so you can just ignore the error if you got your libmain.so file now and move to the next step.

You can check in Project Options in the Linking tab. Disable strip symbols there. But it is strange that it is active, I think it is disabled in the test project.

About the -Fl problem, I have no idea, you could try asking in the free pascal mailling list.
Title: Re: New OpenGL Android Example
Post by: Andru on November 21, 2011, 06:32:57 pm
Quote
In the beginning of February a Android break was introduced, so I would only use revision from January as a starting point.
Hmm, and what was broken? This branch - http://svn.freepascal.org/svn/fpc/branches/fixes_2_6/ works for me, but there are some problems like using unit Unix or math will crash your app. Doest it work with old versions of FPC?
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 21, 2011, 06:42:32 pm
Quote
In the beginning of February a Android break was introduced, so I would only use revision from January as a starting point.
Hmm, and what was broken? This branch - http://svn.freepascal.org/svn/fpc/branches/fixes_2_6/ works for me, but there are some problems like including unit Unix or math will crash your app. Doest it work with old versions of FPC?

does sysutils work for you or de they crash too?
Title: Re: New OpenGL Android Example
Post by: Andru on November 21, 2011, 06:59:35 pm
Quote
does sysutils work for you or de they crash too?
SysUtils, what is this? I have never used them :) But I tried and yes, SysUtils in uses clause make my engine crash at start... Seems now I see where my problems come from. I will try to use static linking with some libraries on older version of FPC, thanks :)
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 21, 2011, 08:06:00 pm
SysUtils, what is this? I have never used them :) But I tried and yes, SysUtils in uses clause make my engine crash at start... Seems now I see where my problems come from. I will try to use static linking with some libraries on older version of FPC, thanks :)

Ok, so that's it then. SysUtils works fine in my cross-compiler from 19th January 2011. This breakage was introduced in February and is present in 2.6. See:

http://bugs.freepascal.org/view.php?id=18833

Another break was introduced very recently. See:

http://bugs.freepascal.org/view.php?id=20726

I'm amazed that you didn't know SysUtils, it is probably the most important unit in Object Pascal, after System and Classes.
Title: Re: New OpenGL Android Example
Post by: Andru on November 21, 2011, 08:31:22 pm
Quote
I'm amazed that you didn't know SysUtils
That was a joke :) I know about this unit, but it makes my programs too fat, so I always avoid using it on every platform(Linux, Windows/WinCE, MacOS, iOS and currently on Android).
Title: Re: New OpenGL Android Example
Post by: Andru on November 21, 2011, 09:12:55 pm
Hmm, revision 1650 doesn't work at all for ZenGL and Chipmunk... And seems this is because of bug with calling functions via references on ARMv5, which was fixed later. And without JNI this is not interesting to play around Android 2.3+...

update: this patch (http://bugs.freepascal.org/view.php?id=18819) didn't help, so seems there are some other troubles.
Title: Re: New OpenGL Android Example
Post by: Laksen on November 21, 2011, 09:46:28 pm
Do you have an example showing the offending code. Can you get a precise pointer value of the function that you are calling? That would indicate whether it's a problem with calling Thumb code or whether the problem lies elsewhere
Title: Re: New OpenGL Android Example
Post by: Andru on November 22, 2011, 08:35:22 am
Quote
Do you have an example showing the offending code.
Nope... ZenGL is quite big to use it as an example, so it will be impossible to find out where it doesn't work with older version of FreePascal. And I didn't see any debug messages of ZenGL initialization, so seems libZenGL.so wasn't loaded or "crashed" at start. I will try to remove static linking with libzip and linking with libchipmunk.so for physics and look again.
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 22, 2011, 09:02:20 am
static dynamic link to shared objects should work around January 19th. After all, my OpenGL example does use a number of native shared objects. Just to start with, it uses OpenGL and JNI.

Maybe you are using dynamic loading the shared object?

Or maybe you are using hardware floating point in a device which has no FPU?

I suppose that one interresting test would be simply using my pre-compiled compiler and see if things improve:

http://sourceforge.net/projects/p-tools/files/Free%20Pascal%20for%20ARM/

It is a Linux x86->Android-arm cross-compiler
Title: Re: New OpenGL Android Example
Post by: Andru on November 22, 2011, 09:47:48 am
Quote
Maybe you are using dynamic loading the shared object?
Only for GLES libraries, and this is works with new FPC.

Quote
Or maybe you are using hardware floating point in a device which has no FPU?
I use only soft-float currently, but my device support ARMv6 with VFP. Even so, why newer FPC works?

Quote
I suppose that one interresting test would be simply using my pre-compiled compiler and see if things improve:
Ok, I will try it. And can you show your make options for it?
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 22, 2011, 10:49:30 am
Quote
Maybe you are using dynamic loading the shared object?
Only for GLES libraries, and this is works with new FPC.

Are you sure that you understood what I said? dynamically loading means using GetProcAddress and LoadLibrary. Thats unusual for basic bindings like OpenGL.

Quote
Even so, why newer FPC works?

I think that the most interresting question here is why it fails for you but it works correctly for me with my 19th January compiler.

Quote
And can you show your make options for it?

I built it 10 months ago, so I can't be sure, but I think it was:

make crossinstall CPU_TARGET=arm OS_TARGET=linux CROSSBINDIR=/home/felipe/Programas/fpctrunk/binutils OPT=-dFPC_ARMEL INSTALL_PREFIX=/usr/
Title: Re: New OpenGL Android Example
Post by: Andru on November 22, 2011, 11:35:00 am
Quote
Are you sure that you understood what I said? dynamically loading means using GetProcAddress and LoadLibrary. Thats unusual for basic bindings like OpenGL.
Yes, I'm sure and I'm using dynamic loading for GL/GLES libraries via dlopen/dlsym(or LoadLibrary/GetProcAddress under Windows) and OS specific glxGetProcAddress/wglGetProcAddress/eglGetProcAddress because of many reasons.

Quote
I think that the most interresting question here is why it fails for you but it works correctly for me with my 19th January compiler.
Maybe because of different code :) When I get home I will test simple library without all my code. Also maybe there is a difference in version/etc. of binutils.
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 22, 2011, 11:41:23 am
Yes, I'm sure and I'm using dynamic loading for GL/GLES libraries via dlopen/dlsym(or LoadLibrary/GetProcAddress under Windows) because of many reasons.

Ok, so now we found the problem. 2 things you should know about:

1> Free Pascal has no support at all for dynamic loading in Android. Not in my pre-compiled snapshot and also not in trunk. In trunk this support was added for generic arm-linux which simply broke the compilation of Android projects because the Android uses a completely different dynamic linker.

2> The Android dynamic linker is very different from the Linux one and even has some bugs, see for example this thread:

http://groups.google.com/group/android-ndk/browse_thread/thread/2779732b85fef9b3

So summing up I would really recommend statically linking all shared objects that you need in Android.
Title: Re: New OpenGL Android Example
Post by: Andru on November 22, 2011, 12:41:53 pm
Quote
Free Pascal has no support at all for dynamic loading in Android.
So how it works for me with FreePascal 2.5.1 from fixes_2_6 branch? O_o Maybe you confuse it with dynamic loading of libraries which are inside apk?
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 22, 2011, 01:31:52 pm
So how it works for me with FreePascal 2.5.1 from fixes_2_6 branch?

I never tried it, since I don't use this, I just wrote what I understood from the commits I read and bug reports, so I could be saying something wrong.

Plus it seams that you use something non-standard, I was refering to the standard way of doing this: dynlibs unit from Free Pascal, which has LoadLibrary (don't confuse it with Windows.LoadLibrary, they are named the same and do the same but are not the same). But it seams that you use a non-standard method: directly calling dlopen from the linker?

So what exactly fails here for you and how do you know that dynamic loading works? I though that you previously said that your project does not work in Android at the moment.

Quote
O_o Maybe you confuse it with dynamic loading of libraries which are inside apk?

Does it matter the location of the libraries?
Title: Re: New OpenGL Android Example
Post by: Andru on November 22, 2011, 02:07:11 pm
Quote
something non-standard
Before saying this just learn about API's in different OS'es... dlopen and dlsym are standard functions from libc :)

Quote
I though that you previously said that your project does not work in Android at the moment.
It works (http://zengl.org/history/TestZenGL.apk), but not all things which I want... E.g. static linking(I mean linking with objects files, not with shared object) with chipmunk doesn't work. Also I have some troubles with libjpeg.so, but maybe this is because of my own function inside it... And as I wrote before - units like math, Unix and SysUtils makes my library unloadable, but this is because of known bug as you mentioned.

Quote
Does it matter the location of the libraries?
Of course, when your library is inside apk you can't load it(without hacks like extracting it to /sdcard and loading). You can use only linking with shared object with previous loading it in your Java code(Syste.loadLibrary).
Title: Re: New OpenGL Android Example
Post by: Andru on November 22, 2011, 05:24:36 pm
So... seems I just forgot about FPC_SHARED_LIB_START. Also your build needs one patch which I mentioned before(without it I can't call any JNI function via JNIEnv on my device). But even with it my problems the same - static linking with object files of chipmunk doesn't work(but maybe this is because of unknown requirements... the worst thing on Android is that I can compile shared object with unresolved externals and got no errors >_<), so no matter can I include SysUtils or not.
Title: Re: New OpenGL Android Example
Post by: Laksen on November 22, 2011, 07:05:42 pm
FPC_SHARED_LIB_START should be in the RTL. If it is not there you probably have a too old RTL
Title: Re: New OpenGL Android Example
Post by: Andru on November 22, 2011, 08:04:23 pm
Laksen
We talk about some old revision(16750) here, so yes, it wasn't there I think :)

PS: unit chreads wants pthread instead of libc... so many problems should be solved >_<
Title: Re: New OpenGL Android Example
Post by: Jonathan on November 23, 2011, 03:59:59 am
Hi felipemdc,finally I got the apk(size:155k),but when I installed into android 2.3 machine and the emulator,it didnot work!as the picture shows.  so I try to  check  libmain.so,I do not find anything wrong.
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 23, 2011, 07:08:05 am
What does "adb logcat" say about it?

Are you using my pre-compiled snapshot compiler or did you build your own?
Title: Re: New OpenGL Android Example
Post by: Jonathan on November 23, 2011, 08:05:42 am
Quote
What does "adb logcat" say about it?

There are too many ,I donnt know how to do. The last piece of 'adb logcat' is:

Code: [Select]
I/ActivityThread(  325): Pub com.svox.pico.providers.SettingsProvider: com.svox.pico.providers.SettingsProvider
D/dalvikvm(   60): GC_EXPLICIT freed 619K, 46% free 4186K/7687K, external 3125K/3903K, paused 161ms
D/AndroidRuntime(  306): Shutting down VM
I/AndroidRuntime(  306): NOTE: attach of thread 'Binder Thread #3' failed
D/dalvikvm(  306): GC_CONCURRENT freed 100K, 72% free 293K/1024K, external 0K/0K, paused 1ms+8ms
D/jdwp    (  306): adbd disconnected
D/dalvikvm(  255): GC_EXPLICIT freed 9K, 55% free 2597K/5703K, external 1625K/2137K, paused 122ms
D/SntpClient(   60): request time failed: java.net.SocketException: Address family not supported by protocol
I/dalvikvm(  123): Total arena pages for JIT: 11
D/dalvikvm(  119): GC_CONCURRENT freed 491K, 52% free 2928K/6087K, external 1625K/2137K, paused 8ms+6ms

I used the cross-compiler I build by myself  not the pre-compiler!!
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 23, 2011, 08:10:50 am
There are too many ,I donnt know how to do. The last piece of 'adb logcat' is:

What you pasted does not show the crash. Copy to adb logcat output to a file and attach here.

Quote
I used the cross-compiler I build by myself  not the pre-compiler!!

From which branch and revision date? There are at least 2 known breakages introduced this year in Android support in the compiler. We have someone working on that, but no idea when it will be repaired. See: http://bugs.freepascal.org/view.php?id=20726

My pre-compiled compiler was created in 19th January so before the breakages, so it should work much better.
Title: Re: New OpenGL Android Example
Post by: Jonathan on November 23, 2011, 08:42:25 am
the file of " adb logcat" ..

I build the compiler as  http://wiki.lazarus.freepascal.org/Setup_Cross_Compile_For_ARM says.lazarus  is lastest ,fpc :2.4.2;binutils:2.20
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 23, 2011, 10:06:03 am
Try my snapshot compiler then.
Title: Re: New OpenGL Android Example
Post by: Jonathan on November 23, 2011, 10:15:12 am
Quote
Try my snapshot compiler then.

Sorry ,I do not get the point!  it is  the lastest lazarus svn 33718 ???
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 23, 2011, 11:14:30 am
Sorry ,I do not get the point!  it is  the lastest lazarus svn 33718 ???

No, it is a pre-compiled FPC Android cross-compiler. Read this:

http://wiki.lazarus.freepascal.org/Android_Interface#Using_the_pre-compiled_compiler
http://sourceforge.net/projects/p-tools/files/Free%20Pascal%20for%20ARM/
Title: Re: New OpenGL Android Example
Post by: Nicola Gorlandi on November 23, 2011, 12:57:11 pm
I would like to use Lazarus for Windows to write some test apps for Android. Is this possible ?
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 23, 2011, 01:16:05 pm
I would like to use Lazarus for Windows to write some test apps for Android. Is this possible ?

Possible surely it is, I know someone that did it. But I think it is a lot more work then installing a Dual boot with Mageia Linux 1 and use the pre-compiled compiler.
Title: Re: New OpenGL Android Example
Post by: Nicola Gorlandi on November 23, 2011, 01:32:36 pm
Do you think that in the future will be available a Lazarus setup for cross compiling Android on Windows as the Arm-Wince one ?
Title: Re: New OpenGL Android Example
Post by: Andru on November 23, 2011, 05:04:30 pm
nicolagorlandi
felipemdc
CodeTyphon (http://www.pilotlogic.com/sitejoom/index.php/codetyphon) guys, CodeTyphon (http://www.pilotlogic.com/sitejoom/index.php/codetyphon)... but only if you are lazy :)
Title: Re: New OpenGL Android Example
Post by: Jonathan on November 24, 2011, 07:32:06 am
Hi  felipemdc,I try to use the pre-compile as you said .at the  Step 2 - Configure the cross-binutils,I remember I did When I setup cross-compiler for ARM,so I go to the Step 3 directly,finally I configured  the Step 4 correctly. But  When I build in the lazarus ,I meet another error:
Code: [Select]
Options changed, recompiling clean with -B
Hint: Start of reading config file /home/hotcyy/.fpc.cfg
Hint: Start of reading config file /etc/fpc.cfg
Hint: End of reading config file /etc/fpc.cfg
Hint: End of reading config file /home/hotcyy/.fpc.cfg
Free Pascal Compiler version 2.5.1 [2011/01/19] for arm
Copyright (c) 1993-2010 by Florian Klaempfl
Target OS: Linux for ARMEL
Compiling ndkopengltest.pas
Compiling /home/hotcyy/lazarus-ccr/bindings/android-ndk/gles.pas
Assembling gles
/home/hotcyy/lazarus-ccr/bindings/android-ndk/gles.pas(810) Error: Assembler /home/hotcyy/lazarus/fpc/binutils/as not found, switching to external assembling
/home/hotcyy/lazarus-ccr/bindings/android-ndk/gles.pas(810) Fatal: There were 1 errors compiling module, stopping

but the file "as "  (soft link) is exist and it could be opened[ "#!/bin/sh /usr/local/bin/arm-linux-as_org -meabi=5 $@"  ] .  tips:fpc :2.4.2  ;ppcrossarm:2.5.1.  I also check the file (.fpc.cfg) -XP path is correct (/home/hotcyy/lazarus/fpc/binutils/)..So I dont know why .Thank you !
Title: Re: New OpenGL Android Example
Post by: Laksen on November 24, 2011, 08:32:48 am
Did the as file have execute permissions?
Title: Re: New OpenGL Android Example
Post by: Jonathan on November 24, 2011, 08:42:48 am
Ye ,Of course! I did chmod +x
Title: Re: New OpenGL Android Example
Post by: herux on November 24, 2011, 10:32:15 am
I think, you should try execute your "/home/hotcyy/lazarus/fpc/binutils/as" first, from linux terminal.

and let see what happen.
Title: Re: New OpenGL Android Example
Post by: irfanbagus on November 25, 2011, 05:49:03 pm
after trying all day, finally i can compile the example on windows using fpc 2.7.1 from svn. working both on emulator and device. not trying anything else yet.
Title: Re: New OpenGL Android Example
Post by: Leledumbo on November 26, 2011, 01:01:29 pm
Quote
after trying all day, finally i can compile the example on windows using fpc 2.7.1 from svn. working both on emulator and device. not trying anything else yet.
which svn revision? my 2.7.1 about two weeks ago can't generate runnable app, the example crashes even before something is shown.
Title: Re: New OpenGL Android Example
Post by: irfanbagus on November 26, 2011, 04:37:49 pm
Quote
after trying all day, finally i can compile the example on windows using fpc 2.7.1 from svn. working both on emulator and device. not trying anything else yet.
which svn revision? my 2.7.1 about two weeks ago can't generate runnable app, the example crashes even before something is shown.
fpc rev 19673 and binutils 2.22. i did just like in http://wiki.lazarus.freepascal.org/Setup_Cross_Compile_For_ARM with small wrapper to pass option -meabi=5 to assembler (arm-linux-as.exe and as.exe).
Title: Re: New OpenGL Android Example
Post by: Jonathan on November 29, 2011, 10:27:32 am
fpc rev 19673 and binutils 2.22. i did just like in http://wiki.lazarus.freepascal.org/Setup_Cross_Compile_For_ARM with small wrapper to pass option -meabi=5 to assembler (arm-linux-as.exe and as.exe).

how to get fpc rev 19673 ??? But Now the rev is 19694...
Title: Re: New OpenGL Android Example
Post by: Andru on November 29, 2011, 11:26:40 am
Quote
how to get fpc rev 19763 ??? But Now the rev is 19694...
Code: [Select]
svn update -r 19763 your_working_copy_of_trunkor
Code: [Select]
svn co -r 19763 http://svn.freepascal.org/svn/fpc/trunk
Title: Re: New OpenGL Android Example
Post by: felipemdc on November 29, 2011, 11:27:59 am
I think you didn't get the point. Go to: http://svn.freepascal.org/cgi-bin/viewvc.cgi/?root=fpc

rev 19763 does not exist.
Title: Re: New OpenGL Android Example
Post by: Andru on November 29, 2011, 11:28:47 am
Oh... :)
Title: Re: New OpenGL Android Example
Post by: Jonathan on November 29, 2011, 11:36:27 am
 :)  Oh  。Sorry  ,I write the wrong fpc SVN rev.
Title: Re: New OpenGL Android Example
Post by: scept1c on November 30, 2011, 08:58:08 pm
Cool men
Title: Re: New OpenGL Android Example
Post by: Jonathan on December 01, 2011, 08:24:06 am
Finally I worked it out !  Fpc :2.6.0_rc1 .I build the the cross_compiler as http://wiki.freepascal.org/Setup_Cross_Compile_For_ARM.

I met the error :binutils/as connot found .I delete the -XP/home/$NAME/lazarus/fpc/binutils/ in the ./fpc.cfg , so it works!  I test it in the machine too!

TinyPortal © 2005-2018