作为初学者,我正在关注“构建OpenGLES环境”文档。我只是想画一个灰色的屏幕。我按照建议编写了每一步,但Eclipse仍然在MyGLSurfaceView类和MyRenderer类中给出了错误。他们在这里
主要活动
package com.example.testopengl;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.app.Activity;
public class OpenGLES20Activity extends Activity {
private GLSurfaceView mGLView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGLView = new MyGLSurfaceView(this);
setContentView (mGLView);
}
}
MyGLSurfaceView类
package com.example.testopengl;
import android.content.Context;
import android.opengl.GLSurfaceView;
public class MyGLSurfaceView extends GLSurfaceView {
public MyGLSurfaceView (Context context) {
super (context);
setEGLContextClientVersion(2);
setRenderer(new MyRenderer());
setRenderMode (GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
}
MyGLRenderer类
package com.example.testopengl;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.EGLConfig;
import android.opengl.GLES20;
public class MyGLRenderer implements GLSurfaceView.Renderer {
public void onSurfaceCreated (GL10 unused, EGLConfig config) {
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 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);
}
}
在此行setRenderer(new My Renderer())MyGLSurfaceView类中弹出错误;
在公共类的MyGLRenderer类中MyGLRenderer实现GLSurfaceView.Renderer
答案 0 :(得分:0)
您在渲染器中使用的方法是静态方法:您需要执行以下操作才能使代码正常工作:
import static android.opengl.GLES20.*
然后您可以无限制地使用这些静态函数:
public void onSurfaceChanged (GL10 unused, int width, int height) {
glViewport(0, 0, width, height); // this is a static method
}