我處於類似的情況。
我開始使用openGL的方式,首先查看非常基本的GLSurfaceView示例/演示。
開始,通過設置您的應用程序活動並設置基本畫布。
在副本島源代碼文件:GameRenderer.java中獲取如何使用適當的GL標誌設置2D(精靈)渲染的畫布。 你真的應該看看SpriteMethodTest通過副本島嶼的同一作者:http://code.google.com/p/apps-for-android/source/browse/trunk/SpriteMethodTest
看到這個問題,我貼我自己的代碼:Using OpenGL to replace Canvas - Android
你有你的畫布設置完畢後,您可以通過調用的東西開始如: gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
之後,您已準備好呈現精靈。 首先,你需要精靈加載到紋理:http://qdevarena.blogspot.com/2009/02/how-to-load-texture-in-android-opengl.html
然而,這真的幫了我與裝載精靈教程: http://tkcodesharing.blogspot.com/2008/05/working-with-textures-in-androids.html
這是我要做的事,我有一類名爲Texture.java:
public class Texture
{
/*Begin public declarations*/
public float x = 0;
public float y = 0;
public float z = 0;
public float width = 0;
public float height = 0;
/*Begin Private Declarations*/
private GL10 gl;
public int[] texture; //holds the texture in integer form
private int texture_name;
private int[] mCropWorkspace;
private final BitmapFactory.Options sBitmapOptions;
/*Begin Methods*/
public Texture(GL10 gl_obj)
{
gl = gl_obj;
texture = new int[1];
mCropWorkspace = new int[4];
sBitmapOptions = new BitmapFactory.Options();
sBitmapOptions.inPreferredConfig = Bitmap.Config.RGB_565;
//Log.d(TAG, "Initializing Texture Object");
}
public int get_texture_name()
{
return texture_name;
}
/*Loads the resource to memory*/
public boolean Load(Bitmap bitmap) //rename this to glLoad and don't have it as an initializer parameter
{
/*many thanks to sprite method test if this works*/
if (gl == null)
{
Log.e(TAG, "Failed to load resource. Context/GL is NULL");
return false;
}
int error;
int textureName = -1;
gl.glGenTextures(1, texture, 0);
textureName = texture[0];
//Log.d(TAG, "Generated texture: " + textureName);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureName);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
mCropWorkspace[0] = 0;
mCropWorkspace[1] = bitmap.getHeight();
mCropWorkspace[2] = bitmap.getWidth();
mCropWorkspace[3] = -bitmap.getHeight();
((GL11) gl).glTexParameteriv(GL10.GL_TEXTURE_2D,
GL11Ext.GL_TEXTURE_CROP_RECT_OES, mCropWorkspace, 0);
error = gl.glGetError();
if (error != GL10.GL_NO_ERROR)
{
Log.e(TAG, "GL Texture Load Error: " + error);
}
//Log.d(TAG, "Loaded texture: " + textureName);
return true;
}
}
然後在我的onDrawFrame()方法,我只是做:
Texture texture = ...
gl.glBindTexture(GL10.GL_TEXTURE_2D, texture.texture[0]);
((GL11Ext) gl).glDrawTexfOES((float)(draw_x + 0.5), (float)(draw_y + 0.5), 0, tile_width, tile_height);
這應該讓你在openGL畫布上繪製2D精靈。 我注意到這裏真的沒有簡單的教程。希望將來我會在我的開發博客中發佈一條:http://developingthedream.blogspot.com/
',我不願意學習它'這不是一個很好的方式在這裏開始一個問題 – Falmarri 2010-08-24 03:11:17
請閱讀我的整個問題,你採取了一個敏感的部分,並留下最重要的完成:「我不'已經知道OpenGL了,我不想學習它,我想直接學習OpenGL ES,因爲我的目標是我的開發到Android「 如果我只用OpenGL工作,學習OpenGL有什麼意義? ES在嵌入式設備上? Cheers – CoolStraw 2010-08-24 04:00:39
鑑於OpenGL ES主要是OpenGL的一個子集,我沒有看到說你不會學習OpenGL的觀點,因爲根據定義你將不得不這樣做。 – 2010-08-25 01:12:35