2016-05-01 4 views
1

OpenGLフレームバッファに1つの問題があります。 私は達成したい:OpenGLフレームバッファ+ LibGDX

  1. バインドFBO1。 image1をFBO1に描画します。 FBO1をアンバインドします。
  2. FBINをバインドします。 FBO1をFBO2に引きます。 FBO2をバインド解除します。
  3. バインドFBO1。 image2をFBO1に描画します。 FBO1をアンバインドします。
  4. 私が見ることを期待どのような画面

にドローFBO2: それは最初FBOに描画された後、最初のFBOが二FBOに描画されているので、私は、画面上の唯一のイメージ1を見ることを期待

FBO1がFBO2で描画され、FBO2のみが画面に描画されるときに、最初の画像のみがFBO1で描画されるため、画像1と画像2の両方が表示されます。ここで

は、問題を再現するためのコードです:

// --- in show() method 
this.img = new Texture(Gdx.files.internal("shaders/image.jpg")); 
this.img2 = new Texture(Gdx.files.internal("shaders/image2.jpg")); 
this.fbo = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); 
this.fbo2 = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); 

// --- in render() method 
// start frame buffer 1 and draw image 1 
this.fbo.begin(); 
{ 
    this.batch.begin(); 
    this.batch.draw(this.img, 0, 0, 400, 400, 0, 0, this.img.getWidth(), this.img.getHeight(), false, true); 
    this.batch.end(); 
} 
this.fbo.end(); 

// start frame buffer 2 and frame buffer 1 output 
this.fbo2.begin(); 
{ 
    this.batch.begin(); 
    this.batch.draw(this.fbo.getColorBufferTexture(), 500, 0, this.fbo.getColorBufferTexture().getWidth(), this.fbo.getColorBufferTexture().getHeight(), 0, 0, this.fbo.getColorBufferTexture() 
      .getWidth(), this.fbo.getColorBufferTexture().getHeight(), false, true); 
    this.batch.end(); 
} 
this.fbo2.end(); 

// start frame buffer 1 again and draw image 2 
this.fbo.begin(); 
{ 
    this.batch.begin(); 
    this.batch.draw(this.img2, 150, 150, 400, 400, 0, 0, this.img2.getWidth(), this.img2.getHeight(), false, true); 
    this.batch.end(); 
} 
this.fbo.end(); 

// draw frame buffer 2 to the batch 
this.batch.begin(); 
this.batch.draw(this.fbo2.getColorBufferTexture(), 0, 0); 
this.batch.end(); 

ドロー()私は真flipY =を渡したいので、OpenGLは逆さまのフレームバッファを描画するための方法は、少し長いです。

私が使用していdraw()メソッドのパラメータは次のとおりです。

Texture texture, float x, float y, float width, float height, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY 

私は何をしないのですか?なぜこうなった?

答えて

1

別のFrameBufferで描画を開始するたびに、古い内容を必要としない場合は、クリアする必要があります。

frameBuffer.begin(); 
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
//... 

また、あなたがrender()に最後の呼び出しからコンテンツをしたくない場合はrender()の冒頭で画面をクリアする必要があります。

また、背景全体を画像で覆っている場合は、SpriteBatchでブレンドを無効にすることもできます。

+0

実際に私はglClearと呼ばれましたが、バッファをバインドする前に行っていましたが、どういうわけか気付かなかったのです。しかし、今あなたのコメントを見て、私は再び私のコードを見直し、今回私はそれを見た。ありがとうございました! –

関連する問題