From e76458bff6fd18d718a6573c2bc1e442b4b4f6b4 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 18 Sep 2017 02:32:47 +0900 Subject: [PATCH] we've got something - except actor's RGB won't draw; only the glow does --- src/net/torvald/terrarum/Ingame.kt | 55 ++++++++++++------- src/net/torvald/terrarum/TitleScreen.kt | 7 +-- .../terrarum/gameactors/ActorWithPhysics.kt | 2 +- .../torvald/terrarum/weather/WeatherMixer.kt | 5 ++ 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/net/torvald/terrarum/Ingame.kt b/src/net/torvald/terrarum/Ingame.kt index 968339f0e..8ae8561ad 100644 --- a/src/net/torvald/terrarum/Ingame.kt +++ b/src/net/torvald/terrarum/Ingame.kt @@ -553,16 +553,35 @@ class Ingame(val batch: SpriteBatch) : Screen { + worldBlendFrameBuffer.inAction(null, null) { + Gdx.gl.glClearColor(0f,0f,0f,0f) + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) + Gdx.gl.glEnable(GL20.GL_TEXTURE_2D) + Gdx.gl.glEnable(GL20.GL_BLEND) + Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA) + } worldDrawFrameBuffer.inAction(null, null) { Gdx.gl.glClearColor(0f,0f,0f,0f) Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) + Gdx.gl.glEnable(GL20.GL_TEXTURE_2D) + Gdx.gl.glEnable(GL20.GL_BLEND) + Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA) } worldGlowFrameBuffer.inAction(null, null) { Gdx.gl.glClearColor(0f,0f,0f,1f) Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) + Gdx.gl.glEnable(GL20.GL_TEXTURE_2D) + Gdx.gl.glEnable(GL20.GL_BLEND) + Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA) } + fun moveCameraToWorldCoord() { + // using custom code for camera; this is obscure and tricky + camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work + camera.update() + batch.projectionMatrix = camera.combined + } /////////////////////////// @@ -574,44 +593,45 @@ class Ingame(val batch: SpriteBatch) : Screen { batch.inUse { batch.shader = null - // using custom code for camera; this is obscure and tricky - camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work - camera.update() - batch.projectionMatrix = camera.combined batch.color = Color.WHITE blendNormal() + setCameraPosition(0f, 0f) BlocksDrawer.renderWall(batch) - Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me + + moveCameraToWorldCoord() actorsRenderBehind.forEach { it.drawBody(batch) } particlesContainer.forEach { it.drawBody(batch) } + + setCameraPosition(0f, 0f) BlocksDrawer.renderTerrain(batch) + ///////////////// // draw actors // ///////////////// - Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me + moveCameraToWorldCoord() actorsRenderMiddle.forEach { it.drawBody(batch) } actorsRenderMidTop.forEach { it.drawBody(batch) } player.drawBody(batch) - Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me actorsRenderFront.forEach { it.drawBody(batch) } - // --> Change of blend mode <-- introduced by childs of ActorWithBody // + // --> Change of blend mode <-- introduced by children of ActorWithBody // ///////////////////////////// // draw map related stuffs // ///////////////////////////// + setCameraPosition(0f, 0f) BlocksDrawer.renderFront(batch, false) + // --> blendNormal() <-- by BlocksDrawer.renderFront FeaturesDrawer.drawEnvOverlay(batch) - Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me // mix lighpmap canvas to this canvas (Colors -- RGB channel) @@ -641,7 +661,7 @@ class Ingame(val batch: SpriteBatch) : Screen { } - Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me + Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is REALLY needed; it really depresses me batch.shader = null @@ -664,11 +684,6 @@ class Ingame(val batch: SpriteBatch) : Screen { batch.inUse { batch.shader = null - // using custom code for camera; this is obscure and tricky - camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work - camera.update() - batch.projectionMatrix = camera.combined - batch.color = Color.WHITE blendNormal() @@ -678,18 +693,16 @@ class Ingame(val batch: SpriteBatch) : Screen { ////////////////////// // draw actor glows // ////////////////////// - + moveCameraToWorldCoord() actorsRenderBehind.forEach { it.drawGlow(batch) } particlesContainer.forEach { it.drawGlow(batch) } actorsRenderMiddle.forEach { it.drawGlow(batch) } actorsRenderMidTop.forEach { it.drawGlow(batch) } player.drawGlow(batch) - Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me actorsRenderFront.forEach { it.drawGlow(batch) } // --> blendNormal() <-- introduced by childs of ActorWithBody // - Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me // mix lighpmap canvas to this canvas (UV lights -- A channel written on RGB as greyscale image) if (!KeyToggler.isOn(Input.Keys.F6)) { // F6 to disable lightmap draw @@ -735,8 +748,8 @@ class Ingame(val batch: SpriteBatch) : Screen { worldTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest) glowTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest) - glowTex.bind(1) worldTex.bind(0) + glowTex.bind(1) Terrarum.shaderBlendGlow.begin() @@ -748,7 +761,7 @@ class Ingame(val batch: SpriteBatch) : Screen { - Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me + Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is REALLY needed; it really depresses me batch.inUse { @@ -873,7 +886,7 @@ class Ingame(val batch: SpriteBatch) : Screen { // draw some overlays (UI) // ///////////////////////////// - uiContainer.forEach { if (it != consoleHandler) it.render(batch, camera) } // FIXME some of the UIs causes memory leak + uiContainer.forEach { if (it != consoleHandler) it.render(batch, camera) } debugWindow.render(batch, camera) // make sure console draws on top of other UIs diff --git a/src/net/torvald/terrarum/TitleScreen.kt b/src/net/torvald/terrarum/TitleScreen.kt index 60b9858fb..19acd2a82 100644 --- a/src/net/torvald/terrarum/TitleScreen.kt +++ b/src/net/torvald/terrarum/TitleScreen.kt @@ -254,9 +254,9 @@ class TitleScreen(val batch: SpriteBatch) : Screen { } private fun renderDemoWorld() { - println("camera TL: ${WorldCamera.x}, ${WorldCamera.y}") - println("camera CN: ${WorldCamera.gdxCamX}, ${WorldCamera.gdxCamY}") - println() + //println("camera TL: ${WorldCamera.x}, ${WorldCamera.y}") + //println("camera CN: ${WorldCamera.gdxCamX}, ${WorldCamera.gdxCamY}") + //println() @@ -272,7 +272,6 @@ class TitleScreen(val batch: SpriteBatch) : Screen { BlocksDrawer.renderWall(batch) BlocksDrawer.renderTerrain(batch) - Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me diff --git a/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt b/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt index 2194979df..f4cf7d0e1 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt @@ -1151,7 +1151,7 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val // this code potentially caused a collision bug which only happens near the "edge" of the world. // // -- Signed, 2017-09-17 - + // wrap around for X-axis val actorMinimumX = Terrarum.HALFW // to make camera's X stay positive diff --git a/src/net/torvald/terrarum/weather/WeatherMixer.kt b/src/net/torvald/terrarum/weather/WeatherMixer.kt index e1f67adce..41bf8c8bf 100644 --- a/src/net/torvald/terrarum/weather/WeatherMixer.kt +++ b/src/net/torvald/terrarum/weather/WeatherMixer.kt @@ -1,5 +1,6 @@ package net.torvald.terrarum.weather +import com.badlogic.gdx.Gdx import com.badlogic.gdx.Input import com.badlogic.gdx.graphics.* import javafx.scene.effect.Light @@ -138,6 +139,10 @@ object WeatherMixer { Terrarum.shaderBayerSkyboxFill.setUniformf("parallax_size", 1f/3f) Terrarum.fullscreenQuad.render(Terrarum.shaderBayerSkyboxFill, GL20.GL_TRIANGLES) Terrarum.shaderBayerSkyboxFill.end() + + + Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me + } fun Float.clampOne() = if (this > 1) 1f else this