0

基本的に、私はAndroid携帯用のOpenGLライブ壁紙を開発しています。これは私の壁紙サービスクラスです。

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();
}

}

それは私の電話(サムスンギャラクシーS2)と他のいくつかで完全に動作します、しかしそれがロードされないという報告があります。Galaxy S1モデルからでも、ライブ壁紙をプレビューすることはできません。これは私の電話で動作するので、何が悪いのか理解できません。プログラムを実行できない電話がないので、問題を解決できません。


返信のためのthx。しかし、EGL10でわかるように、私はOpenGLES1.0を使用しています...インポートされたGL10。ああ、でもGL11(OpenGL 1.1)をインポートしたのを見たのですが、これが問題の原因だったのではないでしょうか?

4

2 に答える 2

0

executor.shutdownNow();から を削除してみてくださいonDestroy()。一部の Samsung の携帯電話では、通話が早すぎる傾向がonDestroyあり、スレッドがシャットダウンされます。

于 2011-10-22T00:45:22.797 に答える
0

OpenGL ES 2.0 は、Android 2.2 以降でサポートされています。

現在利用可能な Samsung Galaxy S1 およびその他の多くの電話は、2.2 より前のバージョンで動作しています。

API レベルを再確認し、OpenGL ES 1.0 にロールバックするか、別の API レベルで使用するラッパーを作成することを検討することをお勧めします。

于 2011-09-13T18:41:53.253 に答える