-
Notifications
You must be signed in to change notification settings - Fork 0
Getting started
Setting up your development environment.
You can download the repository as zip here : Zip Format
Or by cloning with Git : git clone https://github.com/pierreolivier/Simple-GL-Android-Engine.git
You must have Android 2.2 installed.
- File > Import...
- Select the root directory
- Uncheck "Copy projects into workspace" (easier to update later)
- Click on "Finish"
If you have an error like "Android requires compiler compliance level 5.0 or 6.0. Found '1.4' instead.". Use Android Tools > Fix Project Properties (Right click on the imported project).
Or like "xxx must override a superclass method". Change the java compiler from 1.5 to 1.6 (Right click on the imported project). Img
Use Android 2.2 minimum
- Right click on your project, Build Path > Link Source...
- Linked folder location : select the "src" folder of sources
- Folder name : other than "src"
- Click on Finish
- Right click on source project, Export... > Java > JAR file
- Add this generated jar to your build path (example: Build Path > Add External Archives...)
By default, the Android SDK make an onCreate method. Delete it. You have just to extends "SimpleGLEngineActivity" and to "Add unimplemented methods".
public class SimpleGLEngineDemoActivity extends SimpleGLEngineActivity {
@Override
public void onLoadRessources() {
// TODO Auto-generated method stub
}
@Override
public Scene onLoadScene() {
// TODO Auto-generated method stub
return null;
}
@Override
public void onLoadComplete() {
// TODO Auto-generated method stub
}
}
You need to create a texture file (like png) with a power of 2 for resolution. Example: 256x256, 512x1024, ... OpenGL only works with that.
I will work with this image : img
You MUST load your textures in this method. It is called during starting or resuming of the app to (re)load OpenGL textures.
// ...
private Texture mTexture;
private TextureRegion mSasuke;
// ...
@Override
public void onLoadRessources() {
// Load bitmap
Bitmap bitmap = BitmapTools.loadBitmapFromRessource(R.drawable.sasuke);
// Create the texture
this.mTexture = getTextureManager().loadTextureFromBitmap(bitmap);
// Create the texture region
this.mSasuke = getTextureManager().createTextureRegion(mTexture, 76, 11, 23, 45);
}
// ...
@Override
public Scene onLoadScene() {
// Create your scene
Scene scene = new Scene();
// Create the sprite
Sprite sprite = new Sprite(mSasuke, 50, 50);
// Attach your sprite to the scene
scene.attachChild(sprite);
// Return the created scene to the engine
return scene;
}
And voila !!