As a beginner, I am following the "Building an OpenGLES environment" docs. I just want to draw a grey screen. I've written every step as suggested but Eclipse still gives me an error in the MyGLSurfaceView class and in MyRenderer class. Here they are
Main activity
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 class
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 class
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);
}
}
Errors pops in MyGLSurfaceView class at this line setRenderer (new My Renderer());
and in MyGLRenderer class at public class MyGLRenderer implements GLSurfaceView.Renderer
The methods you're using in your renderer are static methods: you need to do the following to make your code work:
import static android.opengl.GLES20.*
Then you can use these static functions without qualification:
public void onSurfaceChanged (GL10 unused, int width, int height) {
glViewport(0, 0, width, height); // this is a static method
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.