Game Development Reference
In-Depth Information
// Set the Renderer for drawing on the GLSurfaceView
m_Renderer = new MyGLRenderer();
setRenderer(m_Renderer);
}
// Constructor that is called when MyGLSurfaceView is created in the XML
// layout file
public MyGLSurfaceView(Context context, AttributeSet attrs)
{
super(context, attrs);
// Create an OpenGL ES 2.0 context.
setEGLContextClientVersion(2);
// Set the Renderer for drawing on the GLSurfaceView
m_Renderer = new MyGLRenderer();
setRenderer(m_Renderer);
}
}
Hands-on Example: A 3D OpenGL “Hello Droid” Example
In this hands-on exercise, I cover a simple 3D OpenGL example that gives you a preview of the kind
of things I will be covering later in this topic.
Importing Project Examples into Eclipse
In order to run the project examples from this topic, you will need to import them into the current
Eclipse work space. Under the main Eclipse menu, select File ➤ Import. This should bring up another
window. Select Android ➤ Existing Android Code Into Workspace to start the process of importing
existing code into your current work space. Follow the directions in the next window to select a root
directory. Select the projects you want to import and if you want to copy the code to the existing
work space or not. Click the Finish button when done.
Start up the Eclipse IDE. Import the Chapter 2 projects into your current work space, if you haven't
done so already. Select the GLHelloWorld project and bring up the source code listing into the
Package Explorer window area of the Eclipse IDE.
The MainActivity and MyGLSurfaceView Classes
Double-click the MainActivity Java file in the Package Explorer window to bring it up in the source
code area. This file defines the new program or Activity and follows the same format for the single
OpenGL view layout discussed earlier (see Listing 2-6.)
Listing 2-6. MainActivity and MyGLSurfaceView Classes
package com.robsexample.glhelloworld;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
 
Search WWH ::




Custom Search