I'm trying to create an android app using OpenGL ES, but having some trouble with the GLSurfaceView.Renderer.
Here's some of my code:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature (Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(new MainView(this));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
public class MainView extends GLSurfaceView {
private GLRenderer renderer;
public MainView(Context context) {
super(context);
setEGLContextClientVersion(2);
renderer = new GLRenderer (context, this);
setRenderer (renderer);
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
}
public class GLRenderer implements Renderer {
private MainView view;
private MainGame game; //This is where the game logic begins.
private GLRes gl20; //This is a class to initialise and store resources such as matrices and shaders
public GLRenderer (Context context, MainView view)
{
this.view = view;
gl20 = new GLRes (context);
}
@Override
public void onDrawFrame(GL10 gl) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
game.draw();
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height)
{
gl20.onSurfaceChanged(width, height);
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
gl20.onSurfaceCreated();
game = new MainGame (view, gl20);
game.setRunning(true);
game.start();
}
public void onSurfaceDestroyed ()
{
game.setRunning(false);
}
public void onTouchEvent (MotionEvent event)
{
game.handleTouchEvent(event);
}
}
The constructor of the Renderer is called as expected, but its onSurfaceCreated() is not, and therefore none of the other methods either, including onDrawFrame(). My GLSurfaceView's onSurfaceCreated is, however, called. This leads to me assume that I haven't set something up properly somewhere, regarding OpenGL and the Renderer, but I can't think what or where that could be.