简体   繁体   中英

Android OpenGL ES 2.0 Live Wallpaper - GLSurface methods not calling

I follow next tutorial (first part of it), but with slightly simple class structure
http://www.learnopengles.com/how-to-use-opengl-es-2-in-an-android-live-wallpaper/

I get next chain of events when i try to select wallpaper (preview)

onCreateEngine()->onCreate() -> onResume()->onPause()->onResume()->onPause()
Why i get onResume()->onPause() two times?

When i hit "Set wallpaper" i get extra onPause()->onResume() and live wallpaper crashes (well maybe because onPause() called 2 times)

Also i don't see calls of OGLES2Renderer like onSurfaceCreated() , onDrawFrame() in preview or on setting wallpaper.

What i missed out of view?

Android manifest (part of it)

<uses-feature
    android:name="android.software.live_wallpaper"
    android:required="true" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
<service
android:name="com.aristarhys.lw.LW"
android:label="@string/app_name"
android:permission="android.permission.BIND_WALLPAPER" >
<intent-filter>
    <action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data
    android:name="android.service.wallpaper"
    android:resource="@xml/lw" />

res/xml/lw.xml

<?xml version="1.0" encoding="UTF-8"?>
<wallpaper 
xmlns:android="http://schemas.android.com/apk/res/android"
android:thumbnail="@drawable/ic_launcher"
android:description="@string/app_desc"/>

LW.java

public class LW extends WallpaperService
{
public class OGLES2Engine extends Engine
{
    private class OGLES2SV extends GLSurfaceView 
    {
        public OGLES2SV(Context context)
        {
            super(context);
        }           

        public void onDestroy() 
        {
            super.onDetachedFromWindow();
        }
    }

    private OGLES2SV SV = null;

    @Override
    public void onCreate(SurfaceHolder surfaceHolder)
    {
        super.onCreate(surfaceHolder);
        SV = new OGLES2SV(LW.this);
        SV.setEGLContextClientVersion(2);
        SV.setRenderer(new OGLES2Renderer()); 
    }

    @Override
    public void onVisibilityChanged(boolean visible)
    {       

            if (!visible)
                SV.onResume();
            else
                SV.onPause();       
            super.onVisibilityChanged(visible);
    }

    @Override
    public void onDestroy()
    {
        SV.onDestroy();
        super.onDestroy();
    }
}

@Override
public Engine onCreateEngine()
{       
    return new OGLES2Engine();
}
}

OGLES2Renderer.java

public class OGLES2Renderer implements GLSurfaceView.Renderer
{
private static final String LOG_TAG = "GL2Surface";

@Override
public void onDrawFrame(GL10 unused) 
{
    Log.i(LOG_TAG, "Draw frame");
}

@Override
public void onSurfaceChanged(GL10 unused, int width, int height) 
{
    Log.i(LOG_TAG, "Surface changed");
}

@Override
public void onSurfaceCreated(GL10 unused_, EGLConfig _unused)
{
    Log.i(LOG_TAG, "Surface created");
}

}

您可以使用andengine Wallpaper extension来实现此目的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM