请记住,我是Android新手,我没有使用过OpenGL的经验。 我跟着这个教训: http://developer.android.com/training/graphics/opengl/environment.html为什么我的OpenGL代码失败?
和我当前的代码是:
OpenGLESTestActivity.java:
package com.KML;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.opengl.*;
import com.KML.MyGLRenderer;
public class OpenGLESTestActivity extends Activity {
/** Called when the activity is first created. */
private GLSurfaceView mGLView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGLView = new MyGLSurfaceView(this);
setContentView(mGLView);
}
}
class MyGLSurfaceView extends GLSurfaceView {
public MyGLSurfaceView(Context context) {
super(context);
setRenderer(new MyGLRenderer());
this.setEGLContextClientVersion(2);
this.setRenderMode(RENDERMODE_WHEN_DIRTY);
}
}
在MyGLRenderer.java
:
package com.KML;
import android.opengl.GLES20;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView;
public class MyGLRenderer implements GLSurfaceView.Renderer {
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
}
public void onDrawFrame(GL10 unused) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
}
public void onSurfaceChanged(GL10 unused, int width, int height) {
GLES20.glViewport(0, 0, width, height);
}
}
这是给我的“不幸的是,OpenGLESTest停止了。“在我的Android设备上。
感谢
发表例外我亲爱的朋友! – Wroclai
可能是,您的设备不支持OpenGL ES 2.0,但请确保发送日志。 –
如果你正在使用模拟器,你可能没有激活图形渲染或OpenGL(类似的东西)。老版本的模拟器不支持OpenGL的东西。 –