Skip to content

Commit

Permalink
fix: render corruption and fbo crash
Browse files Browse the repository at this point in the history
  • Loading branch information
isHarryh committed Sep 7, 2024
1 parent 3399c76 commit 9fdb766
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions core/src/cn/harryh/arkpets/ArkChar.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,25 +200,24 @@ public void adjustCanvas(AnimStage animStage) {
* The animation will be updated according to {@code Gdx.graphics.getDeltaTime()}.
*/
protected void renderToBatch() {
// Update skeleton position
// Update skeleton position and geometry
position.reset(camera.getWidth() >> 1, position.end().y, position.end().z);
position.addProgress(Gdx.graphics.getDeltaTime());
offsetY.addProgress(Gdx.graphics.getDeltaTime());
outlineWidth.addProgress(Gdx.graphics.getDeltaTime());
skeleton.setPosition(position.now().x, position.now().y + offsetY.now());
skeleton.setScaleX(position.now().z);
skeleton.updateWorldTransform();
batch.getProjectionMatrix().set(camera.combined);
// Apply current animation
animationState.apply(skeleton);
animationState.update(Gdx.graphics.getDeltaTime());
// Reset the canvas
ScreenUtils.clear(0, 0, 0, 0, true);
batch.getProjectionMatrix().set(camera.combined);
// Render Pass 1: Render the skeleton
FrameBuffer fbo = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
FrameBuffer fbo = new FrameBuffer(Format.RGBA8888, camera.getWidth(), camera.getHeight(), false);
fbo.begin();
shader1.bind();
batch.setShader(shader1);
ScreenUtils.clear(0, 0, 0, 0, true);
batch.begin();
batch.draw(bgTexture, 0, 0);
renderer.draw(batch, skeleton);
Expand All @@ -231,6 +230,7 @@ protected void renderToBatch() {
shader2.setUniformf("u_outlineColor", 1f, 1f, 0f);
shader2.setUniformf("u_outlineWidth", outlineWidth.now());
batch.setShader(shader2);
ScreenUtils.clear(0, 0, 0, 0, true);
batch.begin();
batch.draw(passedTexture,
0, 0, 0, 0, camera.getWidth(), camera.getHeight(),
Expand All @@ -239,6 +239,7 @@ protected void renderToBatch() {
false, true);
batch.end();
batch.setShader(null);
fbo.dispose();
}

private ShaderProgram getShader(String path2vertex, String path2fragment) {
Expand Down

0 comments on commit 9fdb766

Please sign in to comment.