Skip to content
pierreolivier edited this page Mar 12, 2012 · 15 revisions

Getting started

Environment Setup

Setting up your development environment.

Downloading sources

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

Import project into Eclipse

You must have Android 2.2 installed.

  1. File > Import...
  2. Select the root directory
  3. Uncheck "Copy projects into workspace" (easier to update later)
  4. 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

Import

Create your project

Use Android 2.2 minimum

Create project

Link sources and your project

Method 1 : Link Source...

  1. Right click on your project, Build Path > Link Source...
  2. Linked folder location : select the "src" folder of sources
  3. Folder name : other than "src"
  4. Click on Finish

Link

Method 2 : Use jar file

  1. Right click on source project, Export... > Java > JAR file
  2. Add this generated jar to your build path (example: Build Path > Add External Archives...)

Create the jar file

Create an Hello World

Create the main class

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
		
	}
}

Drawing a sprite

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

Loading the texture

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);
}

Create the main scene

// ...

@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 !!