Author Topic: Render to target, blit the texture, but got a black screen.  (Read 1235 times)

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Render to target, blit the texture, but got a black screen.
« on: February 02, 2013, 05:51:44 am »
I want to make the special effect like that:





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:

Code: [Select]
//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);
 




« Last Edit: February 02, 2013, 05:56:08 am by kiffa »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12035
    • View Profile
    • http://www.jpct.net
Re: Render to target, blit the texture, but got a black screen.
« Reply #1 on: February 02, 2013, 10:04:55 am »
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.

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: Render to target, blit the texture, but got a black screen.
« Reply #2 on: February 06, 2013, 04:26:43 am »
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:
Code: [Select]
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);



« Last Edit: February 06, 2013, 04:45:55 am by kiffa »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12035
    • View Profile
    • http://www.jpct.net
Re: Render to target, blit the texture, but got a black screen.
« Reply #3 on: February 06, 2013, 07:57:34 am »
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

Code: [Select]
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(...);