1

I'm developing cross-platform OpenGL game for computer and Android.

For computer platform i use LWJGL:

import static org.lwjgl.opengl.GL20.*;

For Android platform i use:

import static android.opengl.GLES20.*;

I don't want create interface GL and wrap these functions and i don't want write same classes twice with different imports. I know it's possible, because Java is compiled into native when it's launched.

kravemir
  • 10,636
  • 17
  • 64
  • 111
  • 6
    Java is not an interpreted language. – JB Nizet May 31 '12 at 07:27
  • I guess wrapping would be the solution I would go to. It seems most intuitive and easy on fellow developer's brain than any specific tweaking. Good question BTW. – Nishant May 31 '12 at 07:27
  • @JBNizet I do not know a lot about the fine lines, but see http://en.wikipedia.org/wiki/Interpreted_language I guess scripting and interpreted has fine line – Nishant May 31 '12 at 07:30
  • @JBNizet Yes. I know. I was little be sleepy when i wrote this question :) – kravemir May 31 '12 at 07:59
  • @Nishant Yes. Wrapping is the easiest method, but also takes a lot of time to write all wrapped methods and i'll need to rewrite all gl functions to gl.gl* instead of gl* :/ – kravemir May 31 '12 at 08:04

1 Answers1

0

I see two solution for your problem:

  • First one, is the wrapping (which you don't want). And the injection of the right class or instance at runtime.

  • Second one, is using some macro preprocessing or some scripting at compile time to specify which import you want to use depending on the target platform. It can render the compilation more complicated and you are likely to have to explicitly use org.lwjgl.opengl.GL20.* during the development phase.
    So, the simplest thing to do, would be to create a script to replaceorg.lwjgl.opengl.GL20.* by android.opengl.GLES20.* when the target platform is Android.

Mesop
  • 5,187
  • 4
  • 25
  • 42