我也有类似情况。
我从看待最基本的GLSurfaceView样本/演示开始,就开始使用openGL。
首先,设置您的应用活动,然后设置基本画布。
在副本岛源代码文件:GameRenderer.java中进行掠夺,以了解如何使用适当的GL标志为2D(精灵)渲染设置画布。您应该真正看看副本岛的同一位作者的SpriteMethodTest:http : //code.google.com/p/apps-for-android/source/browse/trunk/SpriteMethodTest
在我张贴自己的代码的地方看到这个问题:使用OpenGL替换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/
and I'm not willing to learn it
这不是在这里提出问题的好方法