问题描述
我收到一个叫未实现的OpenGL ES API的错误,试图在GLES20样品,由developer.android.com提供时。我修改了样本,但。究其原因,是因为我在GLSurfaceView.BaseConfigChooser.chooseconfig一个IllegalArgumentException,所以我代替 mGLSurfaceView.setEGLContextClientVersion(2);
I am getting a "Called unimplemented OpenGL ES API" error, when trying the GLES20 Sample, provided by developer.android.com. I modified the sample, though.The reason was becauseI got an IllegalArgumentException in GLSurfaceView.BaseConfigChooser.chooseconfig, so i replacedmGLSurfaceView.setEGLContextClientVersion( 2 );
新OnCreateMethod:
The new OnCreateMethod:
protected void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
mGLSurfaceView = new GLSurfaceView( this );
mGLSurfaceView.setEGLConfigChooser( new EGLConfigChooser()
{
@Override
public EGLConfig chooseConfig( EGL10 egl, EGLDisplay display )
{
EGLConfig[] configs = new EGLConfig[1];
int[] num_config = new int[1];
boolean check = false;
int[] configSpec = { EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE };
check = egl.eglInitialize( display, new int[] { 2, 0 } );
if ( !check )
return null;
check = false;
check = egl.eglChooseConfig( display, configSpec, configs, 1, num_config );
if ( !check )
return null;
return configs[0];
}
} );
mGLSurfaceView.setEGLContextFactory( new EGLContextFactory()
{
@Override
public void destroyContext( EGL10 egl, EGLDisplay display, EGLContext context )
{
egl.eglDestroyContext( display, context );
}
@Override
public EGLContext createContext( EGL10 egl, EGLDisplay display, EGLConfig eglConfig )
{
int[] attrib_list = new int[]{EGL10.EGL_VERSION, 2, EGL10.EGL_NONE};
EGLContext context = egl.eglCreateContext( display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list );
return context;
}
});
mGLSurfaceView.setRenderer( new GLES20TriangleRenderer( this ) );
setContentView( mGLSurfaceView );
}
时,会出现叫未实现的OpenGL ES API的错误,例如在 GLES20.glCreateShader;
或 GLES20.glShaderSource
。
The "Called unimplemented OpenGL ES API" error occurs for example atGLES20.glCreateShader;
or GLES20.glShaderSource
.
我想,也许检查版本,所以我打电话 gl.glGetString(GLES20.GL_VERSION);
的公共无效onSurfaceCreated(GL10 GL,EGLConfig配置)
。glGetString退换的OpenGL ES-CM 1.0。 OnSurfaceCreated被称为选择配置和创建上下文后,所以我真的不明白,为什么glGetString回报的OpenGL ES-CM 1.0。
I thought, maybe to check the version, so I calledgl.glGetString( GLES20.GL_VERSION );
inpublic void onSurfaceCreated( GL10 gl, EGLConfig config )
.glGetString returned "OpenGL ES-CM 1.0". OnSurfaceCreated is called after choosing the config and creating the context, so I really do not understand, why glGetString returns "OpenGL ES-CM 1.0".
我使用的是Android 2.2的API,并试图将样品上Android 2.2的虚拟设备,并在HTC野火,采用Android 2.2.1。
I am using Android 2.2 API and tried the sample on a Android 2.2 Virtual device and on a HTC Wildfire, with Android 2.2.1.
我AP preciate任何帮助
I appreciate any help
推荐答案
您需要启用OpenGL ES 2.0的在你的Android应用程序。
You need to enable OpenGL ES 2.0 in your Android app.
首先,在你的AndroidManifest.xml,确保您具备以下条件:
First, in your AndroidManifest.xml, ensure you have the following:
<uses-feature android:glEsVersion="0x00020000"></uses-feature>
<uses-sdk android:targetSdkVersion="8" android:minSdkVersion="8"></uses-sdk>
二,创建GLSurfaceView的子类是这样的:
Second, create a subclass of GLSurfaceView like this:
public class CustomView extends GLSurfaceView {
final CustomRenderer renderer;
CustomView(Context context) {
super(context);
setEGLContextClientVersion(2); // This is the important line
renderer = new CustomRenderer();
setRenderer(renderer);
}
}
这篇关于安卓:GLES20:调用未实现的OpenGL ES API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!