2012-11-30 2 views
1

나는 렌더링 스크립트에 대한 초보자입니다. 나는 라이브 벽지 응용 프로그램을 통해 가고 있었다.안드로이드 라이브 벽지 렌더링 스크립트의 배경 이미지

이제는 배경 이미지 (라이브 배경 화면의 정적 배경)가 표시되지 않습니다.

아래 코드를 첨부합니다.

미리 감사드립니다.

LiveWallpaperView 파일

public class LiveWallpaperView extends RSSurfaceView { 
private RenderScriptGL mRSGL; 
private LiveWallpaperRS mRender; 

LiveWallpaper sf; 

Context context; 

public LiveWallpaperView(Context context) { 
    super(context); 

    this.context = context; 

} 

@Override 
public void surfaceCreated(SurfaceHolder holder) { 
    // TODO Auto-generated method stub 
    super.surfaceCreated(holder); 

} 

@Override 
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { 
    super.surfaceChanged(holder, format, w, h); 

    if (mRSGL == null) { 
     RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig(); 
     mRSGL = createRenderScriptGL(sc); 
     mRSGL.setSurface(holder, w, h); 

     mRender = new LiveWallpaperRS(w, h); 

     mRender.init(mRSGL, getResources(), false); 
     mRender.start(); 

    } 
} 

@Override 
protected void onDetachedFromWindow() { 
    if (mRSGL != null) { 
     mRSGL = null; 
     destroyRenderScriptGL(); 
    } 
} 

} 

LiveWallpaper.rs

// Built-in header with graphics API's 
#include "rs_graphics.rsh" 
#include "rs_core.rsh" 

rs_mesh livewMesh; 

// fragment shader 
rs_program_fragment gPFLW; 
rs_allocation gBgImage; // Background image(*****************************************) 
rs_program_fragment gSingleTextureFragmentProgram; // fragment shader 

static void drawBackground() { 
if (gBgImage.p != 0) { 
    rs_matrix4x4 projection, model; 
    rsMatrixLoadOrtho(&projection, -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f); 
    rsgProgramVertexLoadProjectionMatrix(&projection); 

    rsMatrixLoadIdentity(&model); 
    rsgProgramVertexLoadModelMatrix(&model); 

    rsgBindTexture(gSingleTextureFragmentProgram, 0, gBgImage); 

    rsgDrawQuad(
     gBgVertices[0].x, gBgVertices[0].y, gBgVertices[0].z, 
     gBgVertices[1].x, gBgVertices[1].y, gBgVertices[0].z, 
     gBgVertices[2].x, gBgVertices[2].y, gBgVertices[0].z, 
     gBgVertices[3].x, gBgVertices[3].y, gBgVertices[0].z 
    ); 
    } else { 
    //rsgClearColor(gBgColor.x, gBgColor.y, gBgColor.z, gBgColor.w); 
    } 
} 

배경 방법

는 같은 클래스에서 다음 루트 방법이라고합니다.

LiveWallpaperRS.java

public void setBackgroundBitmap(Bitmap bitmap) { 
    if (bitmap == null) { 
     return; 
    } 
    final Allocation bitmapAllocation = Allocation.createFromBitmap(mRS, bitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE); 
    mScript.set_gBgImage(bitmapAllocation); 
} 

그리고 마지막으로 나는

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


     if (mRenderScriptGL != null) { 
      mRenderScriptGL.setSurface(holder, width, height); 
     } 
     if (mlivewRS == null) { 
      mlivewRS = new LiveWallpaperRS(width, height); 

      mlivewRS.setBackgroundBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); 
      mlivewRS.init(mRenderScriptGL, getResources(), isPreview()); 



      mlivewRS.start(); 
     } else { 
      //mlivewRS.resize(width, height); 
     } 
    } 
+0

mlivewRS.init 방법 후 mlivewRs.setBackgroundBitmap를 호출해야 내 LiveWallpaperService 클래스에서이 불렀다 그러나 지금 renderscriptgl depriciated한다 .. – Ani

답변

0

당신은 당신의 onSurfaceChanged 콜백

관련 문제