From 33b5a21c261430f592b4c90689bb672b640b2261 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Fri, 30 Jun 2017 01:50:06 +0900 Subject: [PATCH] blocks camera and framebuffer seems working --- src/net/torvald/terrarum/StateInGameGDX.kt | 83 ++++++++++++++++--- src/net/torvald/terrarum/TerrarumGDX.kt | 3 +- .../terrarum/gameactors/ActorWithPhysics.kt | 8 +- .../terrarum/worlddrawer/BlocksDrawer_old.kt | 13 +-- work_files/graphics/fonts/furigana.psd | 3 + 5 files changed, 83 insertions(+), 27 deletions(-) create mode 100644 work_files/graphics/fonts/furigana.psd diff --git a/src/net/torvald/terrarum/StateInGameGDX.kt b/src/net/torvald/terrarum/StateInGameGDX.kt index e519a4c22..e29df2ce1 100644 --- a/src/net/torvald/terrarum/StateInGameGDX.kt +++ b/src/net/torvald/terrarum/StateInGameGDX.kt @@ -416,24 +416,85 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen { + worldDrawFrameBuffer.inAction { + batch.inUse { + camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work + camera.update() + batch.projectionMatrix = camera.combined + + + + blendNormal() + + + + BlocksDrawer.renderWall(batch) + actorsRenderBehind.forEach { it.drawBody(batch) } + actorsRenderBehind.forEach { it.drawGlow(batch) } + particlesContainer.forEach { it.drawBody(batch) } + particlesContainer.forEach { it.drawGlow(batch) } + BlocksDrawer.renderTerrain(batch) + + ///////////////// + // draw actors // + ///////////////// + actorsRenderMiddle.forEach { it.drawBody(batch) } + actorsRenderMidTop.forEach { it.drawBody(batch) } + player?.drawBody(batch) + actorsRenderFront.forEach { it.drawBody(batch) } + // --> Change of blend mode <-- introduced by childs of ActorWithBody // + + + ///////////////////////////// + // draw map related stuffs // + ///////////////////////////// + LightmapRenderer.renderLightMap() + + //BlocksDrawer.renderFront(batch, false) + // --> blendNormal() <-- by BlocksDrawer.renderFront + //FeaturesDrawer.render(batch) + + + //FeaturesDrawer.drawEnvOverlay(batch) + + //if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendMul() + //else blendNormal() + //blendMul() + //LightmapRenderer.draw(batch) + + + + ////////////////////// + // draw actor glows // + ////////////////////// + // needs some new blending/shader for glow... + + //actorsRenderMiddle.forEach { it.drawGlow(batch) } + //actorsRenderMidTop.forEach { it.drawGlow(batch) } + player?.drawGlow(batch) + //actorsRenderFront.forEach { it.drawGlow(batch) } + // --> blendLightenOnly() <-- introduced by childs of ActorWithBody // + + + } + } + + + + ///////////////////////////////// + // draw framebuffers to screen // + ///////////////////////////////// blendNormal() batch.inUse { - camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work + camera.position.set(TerrarumGDX.HALFW.toFloat(), TerrarumGDX.HALFH.toFloat(), 0f) // make camara work camera.update() batch.projectionMatrix = camera.combined - WeatherMixer.render(batch) // drawing to gwin so that any lights from lamp wont "leak" to the skybox - // e.g. Bright blue light on sunset + WeatherMixer.render(batch) - LightmapRenderer.renderLightMap() - - BlocksDrawer.renderWall(batch) - BlocksDrawer.renderTerrain(batch) - - - batch.color = Color.WHITE - player?.drawBody(batch) + val tex = worldDrawFrameBuffer.colorBufferTexture // TODO zoom! + batch.draw(tex, 0f, 0f, Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat()) } diff --git a/src/net/torvald/terrarum/TerrarumGDX.kt b/src/net/torvald/terrarum/TerrarumGDX.kt index a7fc5bb67..811974913 100644 --- a/src/net/torvald/terrarum/TerrarumGDX.kt +++ b/src/net/torvald/terrarum/TerrarumGDX.kt @@ -46,6 +46,7 @@ fun main(args: Array) { config.height = 742 config.backgroundFPS = 9999 config.foregroundFPS = 9999 + //config.useGL30 = true config.title = GAME_NAME LwjglApplication(TerrarumGDX, config) @@ -491,7 +492,7 @@ object TerrarumGDX : ApplicationAdapter() { } -inline fun Batch.inUse(action: (Batch) -> Unit) { +inline fun SpriteBatch.inUse(action: (SpriteBatch) -> Unit) { this.begin() action(this) this.end() diff --git a/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt b/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt index a88e44223..9e706bcae 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithPhysics.kt @@ -34,7 +34,7 @@ typealias Second = Float open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean = false, physics: Boolean = true) : ActorWithBody(renderOrder) { - val COLLISION_TEST_MODE = true + val COLLISION_TEST_MODE = false /** !! ActorValue macros are on the very bottom of the source !! **/ @@ -323,10 +323,6 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean override fun update(delta: Float) { if (isUpdate && !flagDespawn) { - hitbox.translate(0.0, 2.0) - - - if (!assertPrinted) assertInit() if (sprite != null) sprite!!.update(delta) @@ -339,6 +335,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean isNoSubjectToFluidResistance = isPlayerNoClip } + //////////////////////////////////////////////////////////////// // Codes that modifies velocity (moveDelta and externalForce) // //////////////////////////////////////////////////////////////// @@ -488,6 +485,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean * Apply only if not grounded; normal force is precessed separately. */ private fun applyGravitation() { + if (!isNoSubjectToGrav && !(gravitation.y > 0 && walledBottom || gravitation.y < 0 && walledTop)) { //if (!isWalled(hitbox, COLLIDING_BOTTOM)) { /** diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer_old.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer_old.kt index c19326a6b..f60fbd392 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer_old.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer_old.kt @@ -484,18 +484,11 @@ object BlocksDrawer { else { zeroTileCounter++ // unused for now - GL11.glColor4f(0f, 0f, 0f, 1f) + batch.color = Color.BLACK - GL11.glTexCoord2f(0f, 0f) - GL11.glVertex3f(x * TILE_SIZE.toFloat(), y * TILE_SIZE.toFloat(), 0f) - GL11.glTexCoord2f(0f, 0f + TILE_SIZE) - GL11.glVertex3f(x * TILE_SIZE.toFloat(), (y + 1) * TILE_SIZE.toFloat(), 0f) - GL11.glTexCoord2f(0f + TILE_SIZE, 0f + TILE_SIZE) - GL11.glVertex3f((x + 1) * TILE_SIZE.toFloat(), (y + 1) * TILE_SIZE.toFloat(), 0f) - GL11.glTexCoord2f(0f + TILE_SIZE, 0f) - GL11.glVertex3f((x + 1) * TILE_SIZE.toFloat(), y * TILE_SIZE.toFloat(), 0f) + batch.fillRect(x.toFloat(), y.toFloat(), TILE_SIZEF, TILE_SIZEF) - GL11.glColor4f(1f, 1f, 1f, 1f) + batch.color = Color.WHITE } } // end if (not an air) } catch (e: NullPointerException) { diff --git a/work_files/graphics/fonts/furigana.psd b/work_files/graphics/fonts/furigana.psd new file mode 100644 index 000000000..c76137797 --- /dev/null +++ b/work_files/graphics/fonts/furigana.psd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:683b01a7bf3b891d7b4dab61ddb53dd6c4c3a126e056899a7b5a08080cf5a120 +size 29874