Joe Asks

^ Will Every Phone Have 3D?

Yes and no. Some low-end devices running Android may not actually have 3D hardware. However, the OpenGL programming interface will still be there. All the 3D functions will be emulated in software. Your program will still run, but it will be much slower than a hardware-accelerated device. For this reason, it's a good idea to provide options for users to turn off certain details and special effects that take time to draw but aren't absolutely necessary for the program. That way, if the user is running your program on a slower device, they can disable some of your eye candy to get better performance.

This will create to contain your main activity. Edit this, and change it to refer to a custom view named GLView, as shown here:

Download OpenGL/src/org/example/opengl/

package org.example.opengl;


import android.os.Bundle;

public class OpenGL extends Activity {

GLView view;

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); view = new GLView(this); setContentView(view);

@Override protected void onPause() { super.onPause(); view.onPause();

@Override protected void onResume() { super.onResume(); view.onResume();

We override the onPause( ) and onResume( ) methods so they can call the methods of the same name in the view.

We won't need the layout resource (res/layout/main.xml), so you can delete it. Now let's define our custom view class:

Download OpenGL/src/org/example/opengl/

package org.example.opengl;

import android.content.Context; import android.opengl.GLSurfaceView;

class GLView extends GLSurfaceView { private final GLRenderer renderer;

GLView(Context context) { super(context);

// Uncomment this to turn on error-checking and logging //setDebugFlags(DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS);

renderer = new GLRenderer(context); setRenderer(renderer);

GLSurfaceView is a new class introduced in Android 1.5 that greatly simplifies using OpenGL in Android. It provides the glue to connect OpenGL ES to the view system and activity life cycle. It takes care of picking the appropriate frame buffer pixel format, and it manages a separate rendering thread to enable smooth animation. All GLView needs to do is extend GLSurfaceView and define a renderer for the view.

In the next section, we'll fill the screen with a solid color.

0 0

Post a comment