jPCT - a 3d engine for Java => Support => Topic started by: gamedev-eo on August 11, 2016, 04:42:45 am

Title: HelloWorld for Android
Post by: gamedev-eo on August 11, 2016, 04:42:45 am
Hello I am trying to follow this

It seems to be very old code using deprecated features of Android and OpenGL ES 1.0, but the main issue I have is regarding the BitmapHelper class.

I try import com.threed.jpct.util.BitmapHelper; but it does not exist and Android Studio reports that it cannot resolve symbol wherever the class objects are used.

It would be very useful if someone could modernise the Hello World example seeing as it is the first place someone new to JPCT will be heading, and as it stands now, it does not seem to work.

I'm new to Android and Java, but I'm trying to work around to resolve the issues with this code, but due to my inexperience, this is quite difficult.

I would appreciate the help.


Question also, why is the code using the khronos opengl includes rather than the android specific ones?
Title: Re: HelloWorld for Android
Post by: EgonOlsen on August 11, 2016, 07:17:11 am
The BitmapHelper is still where it had always been. Maybe you've downloaded/used the wrong distribution? There's a desktop version (jPCT) and an Android version (jPCT-AE). Make sure to use the right one.
Which deprecated features does it use? And there's nothing wrong with OpenGL 1.x IMHO. The HelloWorld example is supposed to be as simple as it gets and OpenGL 1.x fits there nicely.
Title: Re: HelloWorld for Android
Post by: gamedev-eo on August 11, 2016, 10:55:17 am

I was working in Ubuntu and had forgotten to download the specific android package ::)

The deprecated thing is to do with drawables (I'm at work so will have to check at home to be more exact).

I mentioned Open GLES 2 mostly because I will targeting that for what I want to achieve with a demo I am building, and also because from what I have seen, it is the entry level for many developers and Android packages built today and it's quite different from 1.0.

I was mostly just looking to find how to alternatively initialise an OpenGLES 2 context with jpct, but I will try to figure this out.

Thanks your help, and so far this engine looks to be fantastic and easy to use so thanks for that.

It reminds me a little of AMOS from back in the day, but obviously much more powerful  ;D
Title: Re: HelloWorld for Android
Post by: EgonOlsen on August 11, 2016, 04:09:50 pm
Yes ES 2.0 is very different from 1.x on the API level, but jPCT-AE hides that from you. All you have to do is to change two lines: http://www.jpct.net/wiki/index.php?title=OpenGL_ES_2.0_support (http://www.jpct.net/wiki/index.php?title=OpenGL_ES_2.0_support)
Title: Re: HelloWorld for Android
Post by: gamedev-eo on August 16, 2016, 08:26:02 pm
Which deprecated features does it use?

Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.icon)), 64, 64));

Android Studio reports 'getDrawable(int) is deprecated'

Do I need those import javax.microedition.khronos.opengles.GL10; statements or can I use an Android opengles library and an Android egl rather than the JDK versions?

If possible, could you help me modify this to be more modern Android best practice friendly. You said yourself you are doing things like

mGLView.setEGLConfigChooser(new GLSurfaceView.EGLConfigChooser() {
         public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {...

To support a very old Android device and things like this are no longer necessary.

Sorry if this is asking too much...I would just like to see a version of the code written in a more modern way.  I'm trying to do this myself, but would appreciate something from someone with far more experience.

Thank you for a great project   :)
Title: Re: HelloWorld for Android
Post by: EgonOlsen on August 16, 2016, 11:46:22 pm
getDrawable is deprecated since Android 5.1.  You should be able to replace it by getDrawable(...., null), which is the exact same thing but keeps the compiler happy.
However, I wouldn't worry about it too much. This line would never appear in a real world application. It's just a quick way for the HelloWorld example to create a texture out of the icon. No real app would do that.
I'm not sure about your khronos question. That's just where the GL10 interface is packaged. It's not 'old' or anything... Unless you consider GL1.x old... Then, you can simply use ES 2.0 instead as mentioned above.
And if you don't want to use the compatibility tweak with the ConfigChooser, then just remove these lines completely.
The thing is: jPCT-AE isn't responsible for initializing the GL context. That's up to the app and the HelloWorld example shows just one way. If you don't want that and use another way instead, you are free to do so. The HelloWorld example should just get you started. It's not meant to be a 'perfect example'.