我想通过将场景渲染到 RenderTexture 来捕获屏幕,我尝试在MotionStreakExample中执行此操作,一切正常,但是当我将代码复制到我的项目时,我有这张图片(也许纹理有一些问题......我无法理解):
@Override
public Engine onCreateEngine(EngineOptions pEngineOptions) {
return new Engine(pEngineOptions) {
private boolean mRenderTextureInitialized;
private RenderTexture mRenderTextures ;
private Sprite mRenderTextureSprites ;
@Override
public void onDrawFrame(final GLState pGLState) throws InterruptedException {
final boolean firstFrame = !this.mRenderTextureInitialized;
if(firstFrame) {
this.initRenderTextures(pGLState);
this.mRenderTextureInitialized = true;
}
final int surfaceWidth = WIDTH*2;
final int surfaceHeight = HEIGHT;
this.mRenderTextures.begin(pGLState, false, true);
{
/* Draw current frame. */
super.onDrawFrame(pGLState);
/* Draw previous frame with reduced alpha. */
}
this.mRenderTextures.end(pGLState);
{
pGLState.pushProjectionGLMatrix();
pGLState.orthoProjectionGLMatrixf(0, surfaceWidth, 0, surfaceHeight, -1, 1);
{
this.mRenderTextureSprites.setAlpha(1);
this.mRenderTextureSprites.onDraw(pGLState, this.mCamera);
}
pGLState.popProjectionGLMatrix();
}
if (needToSave)
{
needToSave = false;
FSHelper.saveBitmapToFile(this.mRenderTextures.getBitmap(pGLState), SAVED_PATH+"/test.png");
}
/* Flip RenderTextures. */
}
private void initRenderTextures(final GLState pGLState) {
final int surfaceWidth = WIDTH*2;
final int surfaceHeight = HEIGHT;
final VertexBufferObjectManager vertexBufferObjectManager = mEngine.getVertexBufferObjectManager();
this.mRenderTextures = new RenderTexture(mEngine.getTextureManager(), surfaceWidth, surfaceHeight);
this.mRenderTextures.init(pGLState);
final ITextureRegion renderTextureATextureRegion = TextureRegionFactory.extractFromTexture(this.mRenderTextures);
this.mRenderTextureSprites = new Sprite(0, 0, renderTextureATextureRegion, vertexBufferObjectManager);
}
};
}
PS。这个带有红色背景的十字架是我场景中的一个精灵。