Implementing GLSurfaceView.Renderer Issues

匿名 (未验证) 提交于 2019-12-03 02:56:01

问题:

Code derived from the tutorial

I am beginning some OpenGL-ES 2.0 for the Android system. I took the following code from: http://developer.android.com/training/graphics/opengl/environment.html#renderer

public class MyRenderer 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);     } } 

I am receiving the following error

Gradle: error: MyRenderer is not abstract and does not override abstract method onSurfaceCreated(GL10,EGLConfig) in Renderer

Does anyone know how to proceed? I need to use the MyRenderer class to pass to the GLSurfaceView, so simply declaring it abstract is not a viable solution. Can anybody shed some light on my problem?

回答1:

Found the Issue!

The Incorrect version of the imports looked like this

import android.opengl.GLES20; import android.opengl.GLSurfaceView; import android.opengl.EGLConfig;  import javax.microedition.khronos.opengles.GL10; 

But GLSurfaceView.Renderer wanted the EGLConfig from the javax library

The following code is the Correct version of the imports

import android.opengl.GLES20; import android.opengl.GLSurfaceView;  import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; 

I discovered this after looking at the interface implementation

public static interface Renderer {     void onSurfaceCreated(javax.microedition.khronos.opengles.GL10 gl10, javax.microedition.khronos.egl.EGLConfig eglConfig);      void onSurfaceChanged(javax.microedition.khronos.opengles.GL10 gl10, int i, int i1);      void onDrawFrame(javax.microedition.khronos.opengles.GL10 gl10); } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!