PDA

View Full Version : sdl2 windows and android



djoker
19-11-2013, 11:41 AM
hello friends,
in recent months I have worked with in sdl2 with freepascal on android compiled from (http://www.pilotlogic.com/sitejoom/index.php/codetyphon) this way came to the conclusion that Native give me better results than java.
I compiled sdl2 sdl2_image sdl2_mixer and sdl2_ttf all in one dll for Windows and separate (.so) for android.
the next step is to compile for Ubuntu .
on this pack i have one demo using sdl2 sd2_image and sdl2_ttf on my experia x8 have 55 fps ;)
and 20 on BlueStacks.

(DOWLOAD)
(windows dll with demo) https://app.box.com/s/wcvfaw1huwpa011t9re8
(andoid bin demo) https://app.box.com/s/906nasyoewfk6x96dpq4

my game (sdl + glEs) (200 particles and tile map) on my device i have 45 fps
http://s12.postimg.org/awbxgo8s9/image.jpg (http://postimg.org/image/awbxgo8s9/)

http://s8.postimg.org/fbrdaad75/image.jpg (http://postimg.org/image/fbrdaad75/)
http://s10.postimg.org/fc0n6nrzp/image.jpg (http://postimg.org/image/fc0n6nrzp/)

Cybermonkey
19-11-2013, 02:48 PM
Wow that's nice. I would like to know more about how to work with SDL2 and Android with Free Pascal. Maybe there is the chance for a how-to?

laggyluk
19-11-2013, 03:27 PM
me too

djoker
19-11-2013, 04:33 PM
hi folks , tank you for the feedback .
on my zip is 1 simple demo to show how to start

kotai
20-11-2013, 02:36 AM
Fantastic !!
I'm going crazy to try compile SDL2 with DelphiXE5 for android but I can not :(
When I add cdecl; external 'libSDL2.so' to any function app not run, say "application has stopped".
I test too many "libSDL2.so" and with all app not run

Kotai.

djoker
20-11-2013, 08:53 AM
kotai I prefer open source programs i have no money to buy delphiXE
and if you look to sdl you have to make some trick to work with delphi you have 2 ways
declare android hidden functions from sdl on delphi or expose the native code on delphi jni functions look to my demo.



procedure Java_org_libsdl_app_SDLActivity_nativeInit(env:JNI Env; cls:jclass; obj:jobject);stdcall;

begin
SDL_Android_Init(env,cls);
SDL_SetMainReady();
sdlMain();
logmsg('all ok Luis Santos AKA Djoker');
halt(0);
end;




exports
JNI_OnLoad,
JNI_OnUnload,
Java_org_libsdl_app_SDLActivity_nativeInit;

begin
end.

on the c++ you have the code android_main with this 2 calls look the source code.
and you have to see one point delphixe5 create native libs with 14,9 MB (15.713.020 bytes) on release mode???? man wtf . no way
goto freepascal :P


ps: check this site http://www.crossfpc.com/

sory mi English

djoker
20-11-2013, 09:49 AM
hi kotai i (download xe5) :( and try with the sdl2 but i think its not possible because with xe5 you don't have way to use java and sdl2 use java for video , audio and input.
but i think with xe5 you don't need sdl because with xe5 you have all the stuff like glES input ...

kotai
20-11-2013, 10:33 AM
Thanks for try it.

In delphi xe5 you have unit androidapi.jni with functions:
TJNI_OnLoad = function(PVM: PJavaVM; Reserved: Pointer): JNIInt; cdecl;
TJNI_OnUnload = procedure(PVM: PJavaVM; Reserved: Pointer); cdecl;

but I not how to use them.

I like more make android hidden functions from sdl on delphi like other platforms (win32, win64 and macos) and use same code for all platforms.
Later I prepare a simple example with only SDL_Init for test with android to see if you know the problem

Kotai.

djoker
20-11-2013, 10:59 AM
kontai i use my jni functions from freepscal is the same the problem and i don't see my exported functions from delphixe5 i use idaq to decompile .so libs and look the import/export functions
and the big problem from sdl is that you don't have access to Java i think.
jni is global system form compilers like delphi/c++ create native code to java jni is just the headers to communicate java/native on android or windows .


""
procedure Java_org_libsdl_app_SDLActivity_onNativeAccel(
env:JNIEnv; cls:jclass;
x:jfloat;y:jfloat; z:jfloat);stdcall;""

Java_org_libsdl_app_SDLActivity
org.libsdl.app is the package name
onNativeAccel the name of the function imported from java exported from delphi
SDLActivity is the name of the activity

now on java
"
public static native void nativeInit();/declare function

class SDLMain implements Runnable {
@Override
public void run() {
// Runs SDL_main()
SDLActivity.nativeInit();

Log.v("SDL", "SDL thread terminated");
}
}


"

kotai
20-11-2013, 01:02 PM
Hi again.

I make this ultra simple example for test SDL2 on Delphi XE5. It work perfect on Win32, Win64 and MacOSX but not in android (compile ok and deploy to phone, but when open say "application has stopped" and close it.)
For Android I add file "libSDL2.so" in menu deployment to folder "/lib"

SDL2Test.dpr :

program SDL2Test;


uses
System.SysUtils;


const
{$IFDEF MSWINDOWS}
SDL_LibName = 'SDL2.dll';
{$ENDIF}


{$IFDEF ANDROID}
SDL_LibName = 'libSDL2.so';
{$ENDIF}


{$IFDEF MACOS}
{$IFDEF IOS}
{$IFDEF CPUARM}
SDL_LibName = 'libSDL2.a';
{$ELSE}
SDL_LibName = 'libSDL2Simulator.a';
{$ENDIF}
{$ELSE}
SDL_LibName = 'SDL2';
{$ENDIF}
{$ENDIF}


function SDL_Init(flags: UInt32): LongInt cdecl; external SDL_LibName name 'SDL_Init';




begin
try
if SDL_Init(0) < 0 then
Writeln('Can not Init SDL')
else
Writeln('SDL Init OK');
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
repeat
until False;
end.


What is the problem ?

Kotai.

djoker
20-11-2013, 04:38 PM
Kotai the sdl2 4 android use java the graphics ,audio and input is build on java and not native look the source codes you need jni to start the sdl and java to pass the android pointers macos linux and windows use opengl and windows api
your code is fine 4 all you systems but 4 android you need eclipse to create the android apk or the command (android)

look this code

https://bitbucket.org/ntlucas/sdl2/src/718b49ec039eb31c651f04bd1bc318e217835eac/android-project/src/org/libsdl/app/SDLActivity.java?at=default

kotai
20-12-2013, 02:25 AM
Hi again.

I found next site on Paul Foster shared his experiences working with External Java libraries on Android with XE5 :

http://www.pclviewer.com/android/

and PDF: http://www.pclviewer.com/android/XE5.pdf

Do you think with this information would be used SDL2 on Android with Delphi XE5?

Thanks.

kotai
26-12-2013, 02:34 AM
Hi @joker


I found how use java in Android from DelphiXE5


I see your demo of SDL2 on Android for FPC in first message of this post, but I do not undertstand it.
Please, can you send me a simple example in FPC for make this:




program SDL2Test;
uses
System.SysUtils;


function SDL_Init(flags: UInt32): LongInt cdecl; external 'libSDL2.so' name 'SDL_Init';


begin
try
if SDL_Init(0) < 0 then
Writeln('Can not Init SDL')
else
Writeln('SDL Init OK');
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
repeat
until False;
end.


Please if you need other files (libraries .so or java) add it.
I would port my games make with DelphiXE5+SDL2 to Android.

Thanks.

kotai
16-01-2014, 12:05 PM
Hi @joker

please can you put or send me a simple example in FPC for make this:




program SDL2Test;
uses
System.SysUtils;


function SDL_Init(flags: UInt32): LongInt cdecl; external 'libSDL2.so' name 'SDL_Init';


begin
try
if SDL_Init(0) < 0 then
Writeln('Can not Init SDL')
else
Writeln('SDL Init OK');
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
repeat
until False;
end.


Thanks.

djoker
28-01-2014, 08:32 AM
hi KOTAI , plz don't waste time using sdl2 with delphix5, delphixe5 build android full projects this way its not possible use sdl2 or sdl1 , sdl its not full NATIVE (so) sdl use java
and 2 use sdl you need android full project with(AndroidManifest.xml,project.properties, and the most important SDLActivity.java) SDLActivity.java is all the magic.
KOTAI try the fcpcross with delphi7 .