我在尝试使用developer.android.com提供的GLES20示例时遇到“调用未实现的OpenGL ES API”错误。我修改了样本。
原因是因为
我在GLSurfaceView.BaseConfigChooser.chooseconfig中得到了IllegalArgumentException,所以我换了
mGLSurfaceView.setEGLContextClientVersion( 2 );
新的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”错误,例如at
GLES20.glCreateShader;
或GLES20.glShaderSource
。
我想,也许要查看版本,所以我打电话
gl.glGetString( GLES20.GL_VERSION );
in
public void onSurfaceCreated( GL10 gl, EGLConfig config )
。
glGetString返回“OpenGL ES-CM 1.0”。在选择配置并创建上下文后调用OnSurfaceCreated,所以我真的不明白,为什么glGetString返回“OpenGL ES-CM 1.0”。
我正在使用Android 2.2 API并在Android 2.2虚拟设备和HTC Wildfire上使用Android 2.2.1尝试了该示例。
我感谢任何帮助
答案 0 :(得分:2)
看这篇文章 - triangle opengl in android
如前所述,模拟器不支持GL2,但正如该文章所提到的,它在实际设备上对我有用。
答案 1 :(得分:1)
这不是错误,而是一个声明。它只是告诉您目标不支持OpenGL ES 2.0版。
答案 2 :(得分:0)
可能是因为您正在使用我们在Renderer实现中的onSurfaceCreated(),onSurfaceChanged()和onDrawFrame()中获取的GL10实例。由于您打算使用OpenGL ES 2.0,我们可以也可能不使用该实例并使用替代方案。还有其他选择!这就是我们在网络中看到这些参数名称以及未使用或相似的原因!