public static class

RenderSurfaceView.Renderer

extends Object
implements GLSurfaceView.Renderer
java.lang.Object
   ↳ org.anddev.andengine.opengl.view.RenderSurfaceView.Renderer

Class Overview

(c) 2010 Nicolas Gramlich (c) 2011 Zynga Inc.

Summary

Public Constructors
RenderSurfaceView.Renderer(Engine pEngine)
Public Methods
void onDrawFrame(GL10 pGL)
Called to draw the current frame.
void onSurfaceChanged(GL10 pGL, int pWidth, int pHeight)
Called when the surface changed size.
void onSurfaceCreated(GL10 pGL, EGLConfig pConfig)
Called when the surface is created or recreated.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.anddev.andengine.opengl.view.GLSurfaceView.Renderer

Public Constructors

public RenderSurfaceView.Renderer (Engine pEngine)

Public Methods

public void onDrawFrame (GL10 pGL)

Called to draw the current frame.

This method is responsible for drawing the current frame.

The implementation of this method typically looks like this:

 void onDrawFrame(GL10 gl) {
 	gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
 	//... other gl calls to render the scene ...
 }
 

Parameters
pGL the GL interface. Use instanceof to test if the interface supports GL11 or higher interfaces.

public void onSurfaceChanged (GL10 pGL, int pWidth, int pHeight)

Called when the surface changed size.

Called after the surface is created and whenever the OpenGL ES surface size changes.

Typically you will set your viewport here. If your camera is fixed then you could also set your projection matrix here:

 void onSurfaceChanged(GL10 gl, int width, int height) {
 	gl.glViewport(0, 0, width, height);
 	// for a fixed camera, set the projection too
 	float ratio = (float) width / height;
 	gl.glMatrixMode(GL10.GL_PROJECTION);
 	gl.glLoadIdentity();
 	gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
 }
 

Parameters
pGL the GL interface. Use instanceof to test if the interface supports GL11 or higher interfaces.

public void onSurfaceCreated (GL10 pGL, EGLConfig pConfig)

Called when the surface is created or recreated.

Called when the rendering thread starts and whenever the EGL context is lost. The context will typically be lost when the Android device awakes after going to sleep.

Since this method is called at the beginning of rendering, as well as every time the EGL context is lost, this method is a convenient place to put code to create resources that need to be created when the rendering starts, and that need to be recreated when the EGL context is lost. Textures are an example of a resource that you might want to create here.

Note that when the EGL context is lost, all OpenGL resources associated with that context will be automatically deleted. You do not need to call the corresponding "glDelete" methods such as glDeleteTextures to manually delete these lost resources.

Parameters
pGL the GL interface. Use instanceof to test if the interface supports GL11 or higher interfaces.
pConfig the EGLConfig of the created surface. Can be used to create matching pbuffers.