1

我想通过将场景渲染到 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。这个带有红色背景的十字架是我场景中的一个精灵。

4

2 回答 2

1

我找到了答案!纹理是动态加载的,在第一帧我根本没有加载纹理,因为我在那里有一个选择对话框并在它之后创建所有纹理。每次更改纹理时,我都需要调用 initRenderTextures。

于 2012-04-21T08:52:42.560 回答
1

Andengine 已经有了截图的基础设施,你试过用吗?看一下例子: https ://github.com/nicolasgramlich/AndEngineExamples/blob/GLES2/src/org/andengine/examples/ScreenCaptureExample.java

于 2012-04-20T16:50:04.097 回答