Game Development Reference
In-Depth Information
Listing 4-5. Main Application Activity
public class ShadersActivity extends Activity {
ShadersView view;
int width;
int height;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
width = getWindowManager().getDefaultDisplay().getWidth();
height = getWindowManager().getDefaultDisplay().getHeight();
String[] args = {};
view = new ShadersView(this);
view.setRenderer(args, false, 0, 0);
setContentView(view);
}
}
Now, on to the surface view.
Surface View
The surface view is in charge of creating an OpenGL-capable, hardware-accelerated surface
where objects can be drawn. The process is triggered by the setRenderer method. Because
Android supports a plethora of graphics configuration, resolutions, and hardware specs,
you don't know if the running device is set up to perform OpenGL ES 3.1 calls. Thus you
must create a context factory class ContextFactory , which implements GLSurfaceView.
EGLContextFactory . This class can then be used to tell Android that you want to use an
OpenGL ES 3.1−enabled context by giving the version as an attribute (see Listing 4-6).
int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
Listing 4-6. Surface View Class
public class ShadersView extends GLSurfaceView {
private static final String TAG = "View";
private String[] mArgs;
private ViewRenderer mRenderer;
public ShadersView(Context context) {
super(context);
}
public void setRenderer(String[] args, boolean translucent, int depth,
int stencil) {
Log.d(TAG, "Setting startup args & renderer");
 
Search WWH ::




Custom Search