I'm developing an OpenGL live wallpaper for android phones. This is my
wallpaper service class.

Basically, it can work perfectly on my phone, Galaxy S2 and several
others. BUT, there have been reports that this live wallpaper cant
even be previewed and force closes. Even by phones such as the Galaxy
S1! I don't have a phone that doesnt run this program so i cant fix
this. Someone HELP!!!

p.s. - the reason i think its the executor problem is becuz i fixed
the power of 2 texture problem already. I successfully added the
configchooser as well.

public class Wallpaper extends GLWallpaperService {

private class MyEngine extends Engine {

    private GLRenderer glRenderer;
    private GL10 gl;
    private EGL10 egl;
    private EGLContext glc;
    private EGLDisplay glDisplay;
    private EGLSurface glSurface;

    private ExecutorService executor;
    private Runnable drawCommand;

    public void onCreate(final SurfaceHolder holder) {
        super.onCreate(holder);


        executor = Executors.newScheduledThreadPool(BIND_AUTO_CREATE);

        drawCommand = new Runnable() {
            public void run() {
                glRenderer.onDrawFrame(gl);
                egl.eglSwapBuffers(glDisplay, glSurface);
                if (isVisible()
                        && egl.eglGetError() !=
EGL11.EGL_CONTEXT_LOST) {
                    executor.execute(drawCommand);
                }
            }
        };

    }

    public void onSurfaceCreated(final SurfaceHolder holder) {
        super.onSurfaceCreated(holder);

        Runnable surfaceCreatedCommand = new Runnable() {
            public void run() {
                // Initialize OpenGL
                egl = (EGL10) EGLContext.getEGL();
                glDisplay =
egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
                int[] version = new int[2];
                egl.eglInitialize(glDisplay, version);
                int[] configSpec = { EGL10.EGL_RED_SIZE, 5,
                        EGL10.EGL_GREEN_SIZE, 6, EGL10.EGL_BLUE_SIZE,
5,
                        EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE };
                EGLConfig[] configs = new EGLConfig[1];
                int[] numConfig = new int[1];
                egl.eglChooseConfig(glDisplay, configSpec, configs, 1,
                        numConfig);
                EGLConfig config = configs[0];

                glc = egl.eglCreateContext(glDisplay, config,
                        EGL10.EGL_NO_CONTEXT, null);

                glSurface = egl.eglCreateWindowSurface(glDisplay,
config,
                        holder, null);
                egl.eglMakeCurrent(glDisplay, glSurface, glSurface,
glc);
                gl = (GL10) (glc.getGL());

                // Initialize Renderer
                glRenderer = new GLRenderer(Wallpaper.this);
                glRenderer.onSurfaceCreated(gl, config);
            }
        };
        executor.execute(surfaceCreatedCommand);

    }


    public void onSurfaceDestroyed(final SurfaceHolder holder) {

        Runnable surfaceDestroyedCommand = new Runnable() {
            public void run() {
                // Free OpenGL resources
                egl.eglMakeCurrent(glDisplay, EGL10.EGL_NO_SURFACE,
                        EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
                egl.eglDestroySurface(glDisplay, glSurface);
                egl.eglDestroyContext(glDisplay, glc);
                egl.eglTerminate(glDisplay);

            }
        };
        executor.execute(surfaceDestroyedCommand);

        super.onSurfaceDestroyed(holder);
    }


    public void onSurfaceChanged(final SurfaceHolder holder,
            final int format, final int width, final int height) {
        super.onSurfaceChanged(holder, format, width, height);

        Runnable surfaceChangedCommand = new Runnable() {
            public void run() {
                glRenderer.onSurfaceChanged(gl, width, height);
            }
        };
        executor.execute(surfaceChangedCommand);

    }

    public void onDestroy() {

        executor.shutdownNow();

        super.onDestroy();
    }


    public void onVisibilityChanged(final boolean visible) {
        super.onVisibilityChanged(visible);

        if (visible) {
            executor.execute(drawCommand);
        }

    }


    public void onOffsetsChanged(final float xOffset, final float
yOffset,
            final float xOffsetStep, final float yOffsetStep,
            final int xPixelOffset, final int yPixelOffset) {
        super.onOffsetsChanged(xOffset, yOffset, xOffsetStep,
yOffsetStep,
                xPixelOffset, yPixelOffset);

        Runnable offsetsChangedCommand = new Runnable() {
            public void run() {
                if (1 / xOffsetStep + 1 != 0f) {
                    glRenderer.setParallax(xOffset - 1f);
                }
            }
        };
        executor.execute(offsetsChangedCommand);

    }

}


public Engine onCreateEngine() {
    return new MyEngine();
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to