Author Topic: HelloWorld for Android  (Read 3318 times)

Offline gamedev-eo

  • byte
  • *
  • Posts: 3
    • View Profile
HelloWorld for Android
« on: August 11, 2016, 04:42:45 am »
Hello I am trying to follow this
http://www.jpct.net/wiki/index.php?title=Hello_World_for_Android

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.

Thanks.

Question also, why is the code using the khronos opengl includes rather than the android specific ones?
« Last Edit: August 11, 2016, 04:44:38 am by gamedev-eo »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: HelloWorld for Android
« Reply #1 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.

Offline gamedev-eo

  • byte
  • *
  • Posts: 3
    • View Profile
Re: HelloWorld for Android
« Reply #2 on: August 11, 2016, 10:55:17 am »
Apologies 

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
« Last Edit: August 11, 2016, 10:56:54 am by gamedev-eo »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: HelloWorld for Android
« Reply #3 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

Offline gamedev-eo

  • byte
  • *
  • Posts: 3
    • View Profile
Re: HelloWorld for Android
« Reply #4 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   :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: HelloWorld for Android
« Reply #5 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'.