Android game guidance (1. Create an OpenGL project) Table of Contents
- 1. Build an environment
- 2. Create an android Project
- 3. Establish an OpenGL program framework
1. Build an environment
My environment is Mac. In view of the many tutorials built on Windows, You can Google them. Let's talk about the environment building process in Mac.
- Download the android SDK for Mac. The tianchao wall is very solid and has been pasted with a 2.3 patch. It can be downloaded by thunder with the powerful leeching function.
Platform |
Package |
Size |
MD5 checksum |
Mac OS X (Intel) |
Android-sdk_r08-mac_86.zip |
28797617 bytes |
D2e392c4e4680cbf2dfd6dbf82b662c7 |
Linux (i386) |
Android-sdk_r08-linux_86.tgz |
26817291 bytes |
3b626645b223d137d27beefbda0c94bc |
- Decompress the file. Click the android file in the tool directory. Select the SDK, document, and tool of the desired version.
- Android requires JDK version later than 1.5, and Mac OS X is pre-installed with version 1.6. (Java-version view ). So you don't have to go to JDK any more. (I think the official website does not provide the Mac version ).
- Download eclipse. The version is for Java developers. Decompress the package to a folder and run eclipse directly.
- Install ADT. Install new software... under the Help menu of eclipse .... Click the Add button, in the pop-up dialog box location, enter http://dl-ssl.google.com/android/eclipse/, OK, omitted...
- Configure the android environment of Eclipse. Restart eclipse and click preferences in the eclipse menu to open the setting interface. Find the android item and set the android SDK directory. Click Apply to display all your SDK versions. OK.
- Create an AVD. Open "android SDK and AVD" under the Windows menu of eclipse and create an AVD. The configuration is successful.
2. Create an android Project
"File"-> "new"-> "project": Select Android project:
Set the project information and SDK version:
A project is created.
3. Establish an OpenGL program framework
By default, the source code of an activity in the created program is as follows:
public class GlGame extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); }}
OpenGL has its own surface: glsurfaceview, which provides an internal Renderer interface. All we need to do is register our own Renderer. Let's take a look at our activity:
Import android. app. activity; import android. openGL. glsurfaceview; import android. openGL. glsurfaceview. renderer; import android. OS. bundle; public class glgame extends activity {/** called when the activity is first created. * // @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); // setcontentview (R. layout. main); Renderer render = new myrenderer (); // The Renderer glsurfaceview glview to be implemented; glview. setrenderer (render); setcontentview (glview );}}
Renderer must implement three Abstract METHODS:
- Public void ondrawframe (gl10 GL) Plotting
- Public void onsurfacechanged (gl10 GL, int width, int height) window size change
- Public void onsurfacecreated (gl10 GL, eglconfig config) Window Creation
Add class myrenderer:
Import javax. microedition. khronos. EGL. eglconfig; import javax. microedition. khronos. opengles. gl10; import android. openGL. glsurfaceview. renderer; public class myrenderer implements Renderer {public void ondrawframe (gl10 GL) {GL. glclearcolor (1, 0, 0, 0); // clear the screen and depth cache GL. glclear (gl10.gl _ color_buffer_bit) | gl10.gl _ depth_buffer_bit);} public void onsurfacechanged (gl10 GL, int width, int height) {// set the size of GL in OpenGL scenarios. glviewport (0, 0, width, height);} public void onsurfacecreated (gl10 GL, eglconfig config) {// todo auto-generated method stub }}
A good OpenGL framework is ready. Next we will plot the relevant things on the cute screen. Next time.