遵循简短教程http://developer.android.com/training/graphics/opengl/environment.html#glsurfaceview。我的示例在模拟器中不起作用。我希望有一个基本的opengl示例在模拟器中工作,但它仍然是一个问题,甚至开发人员的指令都无法工作。
我有三个班级:
package com.test.flushrummy;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity {
private GLSurfaceView m_GlView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
m_GlView = new MyGLSurfaceView(this);
setContentView(m_GlView);
}
}
package com.test.flushrummy;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView.Renderer;
public class MyGLRenderer implements Renderer {
public void onDrawFrame(GL10 unused) {
// Redraw background color
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
}
public void onSurfaceChanged(GL10 unused, int width, int height) {
GLES20.glViewport(0, 0, width, height);
}
@Override
public void onSurfaceCreated(GL10 gl,
javax.microedition.khronos.egl.EGLConfig config) {
// TODO Auto-generated method stub
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
}
package com.test.flushrummy;
import android.content.Context;
import android.opengl.GLSurfaceView;
class MyGLSurfaceView extends GLSurfaceView {
public MyGLSurfaceView(Context context) {
super(context);
setRenderer(new MyGLRenderer());
// Create an OpenGL ES 2.0 context
setEGLContextClientVersion(2);
// Render the view only when there is a change in the drawing data
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
}
我有我的证据。
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" />
project.properties:
target=android-19
“使用gpu host”在avd。
中被snabled答案 0 :(得分:1)
添加GPU仿真硬件属性,并在仿真中将其值设置为yes。添加它们并尝试它。
创建新虚拟设备时,有一个硬件部分。添加新的。有一个GPU模拟选项添加这个。
答案 1 :(得分:0)
我遇到了同样的问题,这就是错误的,所以也可能是你的问题:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//COMMENT OUT THIS COMMAND
//setContentView(R.layout.activity_main);
/*if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
*/
//Setup surface view in this activity
mView = new GLSurfaceView(this);
mView.setEGLContextClientVersion(2);
mView.setRenderer(new GraphicRenderer());
mView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
setContentView(mView);
}
模板代码setContentView()需要注释掉。然后它在加载时不会崩溃。