2013-02-06 3 views
2

libgdx에서 FrameBuffer 클래스로 다음과 같은 이상한 결과가 나타납니다. 왜 내가 이성을 상실하고,보다 작은 얻을 나는 프레임 버퍼에 그린 마음을 얻고 그libgdx에서 프레임 버퍼가있는 모호한 결과

// This is the rendering code 
@Override 
public void render(float delta) { 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); 

    stage.act(); 
    stage.draw(); 

    fbo.begin(); 
    batch.begin(); 
    batch.draw(heart, 0, 0); 
    batch.end(); 
    fbo.end(); 

    test = new Image(fbo.getColorBufferTexture()); 
    test.setPosition(256, 256); 
    stage.addActor(test); 
} 

//This is the initialization code 
@Override 
public void show() { 
    stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); 
    atlas = Assets.getAtlas(); 
    batch = new SpriteBatch(); 

    background = new Image(atlas.findRegion("background"));  
    background.setFillParent(true); 
    heart = atlas.findRegion("fluttering"); 
    fbo = new FrameBuffer(Pixmap.Format.RGBA8888, heart.getRegionWidth(), heart.getRegionHeight(), false); 

    stage.addActor(background); 
    Image temp = new Image(new TextureRegion(heart)); 
    stage.addActor(temp); 
} 

입니다 : 여기

enter image description here

이 결과를 생성하는 코드 원래 프레임 버퍼의 너비와 높이가 이미지의 너비와 높이와 동일하지만 (71 x 72).

fbo = new FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); 
+0

+1 문제에 대한 주석이 달린 그림입니다. 좋은. –

답변

3

는 프레임 버퍼는 이와 같은 단계의 동일한 폭과 높이를 가져야한다. 사용자 정의 크기의 FrameBuffer로 렌더링하므로 수동으로 설정해야합니다.

projectionMatrix = new Matrix4(); 
projectionMatrix.setToOrtho2D(0, 0, heart.getRegionWidth(), heart.getRegionHeight()); 
batch.setProjectionMatrix(projectionMatrix); 
6

귀하의 SpriteBatch 잘못된 투영 매트릭스를 사용한다 :이 문제를 해결하기

+0

이것은 올바른 답변이며, 다른 하나는 해결 방법입니다. 크기가 화면의 크기와 일치하지 않는 FB를 사용하려는 경우가 많습니다. –