I want to make the special effect like that:
(http://p13.freep.cn/p.aspx?u=v20_p13_photo_1302021252297466_0.jpg)
What i do:
1, Render skeleton animation, assume the frame sequences are 1\2\3\4\5\6...
2, When rendering frame-1, first render to frameBuffer, then change the transparency of obj3d, render frame-1 to a texture.
3, When rendering frame-2, first render to frameBuffer, then blit the last render-target-texture(frame-1). So there are 2 obj3ds in frameBuffer now, one is frame-1 with transparency, one is frame-2. then change the transparency of obj3d, render frame-2 to a texture.
4, Goto step 3.
Problem:
When blitting, i got an black-screen. OpenglES 2.0, Code:
//onDrawFrame
frameBuffer.clear();
world.renderScene(frameBuffer);
world.draw(frameBuffer);
if(mTexture == null){
mTexture = new Texture(frameBuffer.getWidth(), frameBuffer.getHeight(), 100);
Log.d(D.TAG, "texture width: " + mTexture.getWidth());
Log.d(D.TAG, "texture height: " + mTexture.getHeight());
}
else {
frameBuffer.blit(mTexture, 0, 0, 0, 0, frameBuffer.getWidth(), frameBuffer.getHeight(), FrameBuffer.TRANSPARENT_BLITTING);
}
obj.setTransparency(100); // Adjust Config, so transparency value is between 0 - 255;
frameBuffer.setRenderTarget(mTexture);
world.draw(frameBuffer);
frameBuffer.removeRenderTarget();
obj.setTransparency(-1);
You can't create a normal texture with these dimensions. Have a look at the NPOTTexture class. In addition, i suggest to execute the normal render sequence on the render target (i.e. clear,render...,draw...) instead of just calling draw again.
The width/height of texture(Framebuffer) is 256/256. So i think the dimension is not the problem. I will try to execute the normal render sequence on the render target as you suggesting.
Some other questions:
I only render once, draw twice, because i want to get the best performance. Is World.renderScene() more expensive than World.draw()?
If i don't render to target, but draw twice to Framebuffer, the result seems good, but if render to target, i got a black screen. So are there some difference between render to framebuffer and render to texture?
The result of rendering to Framebuffer:
Codes:
frameBuffer.clear();
world.renderScene(frameBuffer);
world.draw(frameBuffer);
Config.viewportOffsetX += 0.1f;
obj.setTransparency(150);
world.draw(frameBuffer);
Config.viewportOffsetX += 0.1f;
obj.setTransparency(100);
world.draw(frameBuffer);
Config.viewportOffsetX += 0.1f;
obj.setTransparency(50);
world.draw(frameBuffer);
Config.viewportOffsetX = 0;
obj.setTransparency(-1);
(http://p13.freep.cn/p.aspx?u=v20_p13_photo_1302061124311600_0.jpg)
Well then...in your code, i can't spot any call to display();!? Try to add a display()-call before setting the render target and after rendering into it (if there isn't any). Because otherwise, your blit will happen in the render target (because it's queued until the next non-blitting operation).
The sequence should be something like
frameBuffer.clear();
world.renderScene(frameBuffer);
world.draw(frameBuffer);
frameBuffer.display();
frameBuffer.setRenderTarget(...);
frameBuffer.clear();
world.renderScene(frameBuffer); // Maybe not...
world.draw(frameBuffer);
frameBuffer.display();
frameBuffer.removeRenderTarget(...);