jPCT-AE 3D engine Wrapper

alhowiriny

Member
Licensed User
Longtime User
jPCT is a 3D engine for desktop Java and Google's Android. It will work on Windows, Linux, Mac OS X, Solaris x86...and on your mobile phone or your Android tablet. It supports OpenGL via LWJGL and JOGL and uses OpenGL ES 1.x and ES 2.0 on Android. jPCT supports Android 1.5 and higher and can be used with OpenGL ES 1.x as well as with OpenGL ES 2.0. It offers shader support for ES 2.0 and uses a set of default shaders that mimic the behaviour of 1.x in a 2.0 context. So you can use 2.0 without being forced to write your own shaders.

More Info:
jPCT-AE - a mobile 3D engine for Google's Android

Projects:
An overview of some 3D Java and Android projects using the jPCT and jPCT-AE framework.

attachment.php


This's full wrapper of the engine, plus addon classes which are not part of the engine, such as glsurfaceview wrapper with rendring implementation, multitouch/gestures/scale implementation, 5 Interfaces implementation ..etc.

The wrapper contains about 47 classes, the javadoc of the 3d engine is embedded inside the wrapper, so it will show as tool-tip when you type in basic4android.

Using this 3D library requires you have basic understanding of 3D. I have created 6 examples to help understand the engine (the above image is taken from these examples), you should take a look at 'HelloWorld' example which's a convert of the Java 'helloworld', it also has enough comments to get you started, all the other examples assume you've understood the 'hello world' example. The examples run on OpenGL 1, The engine is capable of running on OpenGL 2 provided you know how write Shaders.

The examples don't show the perfect way of using this engine, nor show a good programming practice in b4a, rather they show my own understanding and practice.

Since i don't have time/energy to maintain this project, the full source code of the wrapper is available as an (eclipse project). If there's bugs, errors .. you have the source, so you get to fix it. note, that i didn't test all the engine's features.

How to use:
- Extract "JPCT-AE (Lib+Wrapper).zip".
- Copy the 3 files into your basic4android library's folder.
- Open 'HelloWorld' example.
- Make sure the engine is loaded from within Libs tab, the name of the engine will be "JPCT-AE (alhowiriny)" before loading, and "JPCT-AE (version 1.0)" after loading.

I've tested the engine/examples with basic4android version 2.52, on 2 devices, both have mali400GPU. works fine for me.

JPCT-AE B4a Wrapper
JPCT-AE (Lib+Wrapper).zip

JPCT-AE Examples
jPCT-AE Examples.zip

JPCT-AE Wrapper Source (Eclipse Project)
jPCT-AE Wrapper(Eclipse Project).zip
 

Attachments

  • jpct.jpg
    jpct.jpg
    81.3 KB · Views: 2,132

Stulish

Active Member
Licensed User
Longtime User
Wow

WoW they look amazing, the only problem i had was getting the hello world B4A project to work, i get:

java.lang.Exception: Sub rendrerfps was not found.


at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA$3.run(BA.java:307)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
java.lang.Exception: Sub rendrerfps was not found.

There is defiantly a sub there:

B4X:
Sub RendrerFPS(Data As Object)
   fps.Text = Data&" FPS" '<- Data = fpsCounter
End Sub

so not sure what is going on, all the other projects run fine

Stu
 

alhowiriny

Member
Licensed User
Longtime User
Waw! I haven't been able to take a deeper look into it but at first glance this looks amazing alhowiriny. I had seen the original lib before but never had the time to convert it for b4a. Truly a great job and thank you!

Thank you. :)

WoW they look amazing, the only problem i had was getting the hello world B4A project to work, i get:



There is defiantly a sub there:

B4X:
Sub RendrerFPS(Data As Object)
   fps.Text = Data&" FPS" '<- Data = fpsCounter
End Sub

so not sure what is going on, all the other projects run fine

Stu

Probably you're using older version of Basic4Android.

in "HelloWorld" example, under Jpct_SurfaceDraw, comment
the line where it says:

Jpct.SendDataTo("RendrerFPS", fpsCounter)

Or replace it with this, if you want fpsCounter logged
Log(fpsCounter)

Jpct.SendDataTo..., uses (BA.raiseEventFromDifferentThread), its the only method that uses it, which sends fpsCounter's value from the rendreing thread to the main (B4A) thread, to show the value inside a label.

The rest of the examples don't use SendDataTo, so they worked.
 

Stulish

Active Member
Licensed User
Longtime User
The Saga Continues

I commented out the 'Jpct.SendDataTo("RendrerFPS", fpsCounter)' and it worked fine.

I then added Log(fpsCounter) and the phone reset with the following logged error:

B4X:
@@@ ABORTING: INVALID HEAP ADDRESS IN dlfree addr=0x671e1000
Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 2356 (er.ServerThread)

After the reset the app runs fine and diaplays the FPS in the log

So not sure what happened.

Oh yeah i am using B4A 2.7
 

alhowiriny

Member
Licensed User
Longtime User
I dont know what that msg means, but i'm guessing its threading issue.

Don't use B4A native Log, Use JPCT Log instead. somthing like:

B4X:
Dim Logger As JpctLogger '<- put this under Process_Globals

Logger.Initialize '<- put this under Activity_Create

Logger.Log(fpsCounter) '<- put this under Jpct_SurfaceDraw, replace it with Log(fpsCounter)


now before compiling make sure you untick 'Filter' under Logs tab, and when you run the example, wait untill all the garbage in the Log tab go away, and you should see something like this:

attachment.php


Now, this's not what i'm intrested in. what i want to understand is why the sub rendrerfps isn't found when using SendDataTo. i've tested it with B4A 2.7 on 2 devices 4.0.3 and it works fine.

Would you please rename Sub RendrerFPS... to lowercase somthing like : Sub rendrerfps(Data As Object) and dont forget to uncomment Jpct.SendDataTo ..

does it find it?
 

Attachments

  • fps.jpg
    fps.jpg
    79.8 KB · Views: 1,797

Stulish

Active Member
Licensed User
Longtime User
I done everything you listed and the FPS did show in the Log (amongst everything else)

I changed to lowercase with the same result and then put your new library in the Additional Libs folder and now it wont compile:

Parsing code. 0.01
Compiling code. 0.01

ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code. 0.00
Generating R file. 0.12
Compiling generated Java code. Error
B4A line: 190
Jpct.SendDataTo(\
javac 1.7.0_21
src\b4a\example\main.java:410: error: method SendDataTo in class JGLSurfaceView cannot be applied to given types;
mostCurrent._v0.SendDataTo("RendrerFPS",(Object)(_vvv2));
^
required: BA,String,Object
found: String,Object
reason: actual and formal argument lists differ in length
1 error

Just so you know this is running on Samsung G3 with JB version 4.1.2
 

alhowiriny

Member
Licensed User
Longtime User
I see you're using jdk 1.7.0_21, while i'm using 1.6.0_31. maybe this's why it won't compile.

attached an apk i just compiled.


This's the method SendDataTo:
If someone can see anything wrong, please inform me.
B4X:
    /**
      * Send Data (Single Object) To UI thread
      * SubName: Name of the Sub to send to, ie. "MySub"
      * Data: The Data Object you need to send
      */
     public void SendDataTo(String SubName, Object Data) { 
        ba.raiseEventFromDifferentThread(getObject(),
                   null, 0, (SubName).toLowerCase(BA.cul), true, new Object[] {Data});
     }
 

Attachments

  • helloworld.apk
    364.4 KB · Views: 441

Stulish

Active Member
Licensed User
Longtime User
The APK installed and Ran fine, with the FPS displayed at the top

Not sure what my problem is, like you said maybe jdk?

Thanks

stu
 

alhowiriny

Member
Licensed User
Longtime User
The last log you posted shows you're using jdk 1.7.0_21, probably its bugged or there's issue with it & b4a libs. if you install jdk6 then from b4a IDE you can change to it.

I have deleted my previous post with the new lib, you should delete it too, and stick with the old one.
 

moster67

Expert
Licensed User
Longtime User
Thank you!

It is a bit out of my league and not something I will use in my current projects but nevertheless many thanks to you for sharing this with the B4A-community. I am sure it can be useful for many other users.
 

Informatix

Expert
Licensed User
Longtime User
The last log you posted shows you're using jdk 1.7.0_21, probably its bugged or there's issue with it & b4a libs. if you install jdk6 then from b4a IDE you can change to it.

I have deleted my previous post with the new lib, you should delete it too, and stick with the old one.

The problem is not the JDK version (it only matters when you compile under Eclipse), it's because the sub has a name not compatible with the obfuscation mode. If you rename it Rendrer_FPS, that's OK.
 
  • Like
Reactions: eps

PhilN

Member
Licensed User
Longtime User
Thanks dude! I'm gonna try it out... will let you know if I have any success! :sign0060:
 

ldb68

Member
Licensed User
Longtime User
Some questions.
How can I set an image backgroud?
What's the maximum size that can used for models? A 8 Mb 3ds model is not loaded.
Has anyone tried the demo on Andrdoid 4.3. On my nexus 7 pinch to zoom does not work.

thanks
 

peacemaker

Expert
Licensed User
Longtime User
And how (what software) to prepare 3D-models for using with this framework in b4a?
 

John.E

Member
Licensed User
Longtime User
And how (what software) to prepare 3D-models for using with this framework in b4a?

SketchUp (pain now it is PayWare) or you could try Blender (freebie and a full fledge design package that will allow you to do loads, just don't ask me for help, I am still learning to use it) :)

Oh, and while I remember ... Thanks for the wrapper alhowiriny :)
 
Last edited:

cbass

New Member
Licensed User
Longtime User
Does this Lib work with the Rapid debugger?

I've been playing with the tutorials successfully with the legacy debugger, but when switching to the rapid debugger, the project compiles, installs, and the activity starts, but then it throws this exception and never fully starts.

Ignoring event: jpct_surfacedraw. Raised from the wrong thread.

Nexus 7, and I tried the Tools - clean project command with no success.
 
Top