screen zooming, temporarily toggle with Z key

This commit is contained in:
minjaesong
2019-08-11 05:42:04 +09:00
parent 08c18caa25
commit 419773550a
11 changed files with 61 additions and 17 deletions

View File

@@ -20,6 +20,8 @@ uniform float rcount = 64.0; // it even works on 256.0!
uniform float gcount = 64.0; // using 64: has less banding and most monitors are internally 6-bit
uniform float bcount = 64.0;
// inverted zoom; this value must set to (1f/zoom)
uniform float zoomInv = 1f;
/*int bayer[7 * 7] = int[](
32,42,10,27,37,5,15,
@@ -72,12 +74,13 @@ void main(void) {
float scale = v_texCoords.y * (1.0 - parallax_size) + (parallax_size / 2.0) + (parallax * parallax_size / 2.0);
float zoomSamplePoint = (1f - zoomInv) / 2f; // will never quite exceed 0.5
float inR = mix(bottomColor.r, topColor.r, scale);
float inG = mix(bottomColor.g, topColor.g, scale);
float inB = mix(bottomColor.b, topColor.b, scale);
// I don't even know if it works, and also not sure if I actually want it
vec3 newBottom = mix(bottomColor, topColor, zoomSamplePoint);
vec3 newTop = mix(topColor, bottomColor, zoomSamplePoint);
vec4 inColor = vec4(inR, inG, inB, 1.0);
vec4 inColor = vec4(mix(newBottom, newTop, scale), 1.0);
vec2 entry = mod(gl_FragCoord.xy, vec2(bayerSize, bayerSize));

View File

@@ -73,6 +73,7 @@ void main() {
vec2 overscannedScreenDimension = tilesInAxes * tileSizeInPx; // how many tiles will fit into a screen; one used by the tileFromMap
vec2 flippedFragCoord = vec2(gl_FragCoord.x, screenDimension.y - gl_FragCoord.y) + cameraTranslation; // NO IVEC2!!; this flips Y
//vec2 pxCoord = flippedFragCoord.xy; // TODO do I actually need 'pxCoord'?
vec2 zoomVec = vec2(zoom);
// get required tile numbers //
@@ -97,8 +98,8 @@ void main() {
// get final UV coord for the actual sampling //
vec2 finalUVCoordForTile = uvCoordForTile + uvCoordOffsetTile;// where we should be actually looking for in atlas, using UV coord (0..1)
vec2 finalUVCoordForBreakage = uvCoordForTile + uvCoordOffsetBreakage;
vec2 finalUVCoordForTile = (uvCoordForTile + uvCoordOffsetTile);// where we should be actually looking for in atlas, using UV coord (0..1)
vec2 finalUVCoordForBreakage = (uvCoordForTile + uvCoordOffsetBreakage);
// blending a breakage tex with main tex //

View File

@@ -72,6 +72,7 @@ object DefaultConfig {
jsonObject.addProperty("keyinventory", Input.Keys.Q)
jsonObject.addProperty("keyinteract", Input.Keys.R)
jsonObject.addProperty("keyclose", Input.Keys.C) // this or hard-coded ESC
jsonObject.addProperty("keyzoom", Input.Keys.Z)
jsonObject.addProperty("keygamemenu", Input.Keys.TAB)
jsonObject.addProperty("keyquicksel", Input.Keys.SHIFT_LEFT) // pie menu is now LShift because GDX does not read CapsLock

View File

@@ -20,7 +20,7 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
var screenZoom = 1.0f
val ZOOM_MAXIMUM = 4.0f
val ZOOM_MINIMUM = 0.5f
val ZOOM_MINIMUM = 1.0f
open var consoleHandler: ConsoleWindow = ConsoleWindow()

View File

@@ -83,6 +83,7 @@ object PostProcessor : Disposable {
postShader(projMat, fbo)
// draw things when F keys are on
if (AppLoader.IS_DEVELOPMENT_BUILD && KeyToggler.isOn(Input.Keys.F11)) {
drawSafeArea()
}
@@ -113,6 +114,14 @@ object PostProcessor : Disposable {
else {
if (!debugUI.isClosed && !debugUI.isClosing) debugUI.setAsClose()
}
// draw dev build notifiers
if (AppLoader.IS_DEVELOPMENT_BUILD && Terrarum.ingame != null) {
batch.inUse {
batch.color = safeAreaCol
AppLoader.fontGame.draw(it, thisIsDebugStr, 5f, AppLoader.screenH - 24f)
}
}
}
}
@@ -143,16 +152,25 @@ object PostProcessor : Disposable {
val tvSafeArea2H = AppLoader.getTvSafeActionHeight().toFloat()
shapeRenderer.inUse(ShapeRenderer.ShapeType.Line) {
// centre ind
shapeRenderer.color = safeAreaCol2
shapeRenderer.line(0f, 0f, AppLoader.screenW.toFloat(), AppLoader.screenH.toFloat())
shapeRenderer.line(0f, AppLoader.screenH.toFloat(), AppLoader.screenW.toFloat(), 0f)
// safe action area
shapeRenderer.color = safeAreaCol2
shapeRenderer.rect(
tvSafeArea2W, tvSafeArea2H, AppLoader.screenW - 2 * tvSafeArea2W, AppLoader.screenH - 2 * tvSafeArea2H
)
// safe graphics area
shapeRenderer.color = safeAreaCol
shapeRenderer.rect(
tvSafeAreaW, tvSafeAreaH, AppLoader.screenW - 2 * tvSafeAreaW, AppLoader.screenH - 2 * tvSafeAreaH
)
// default res ind
shapeRenderer.color = defaultResCol
shapeRenderer.rect(
(AppLoader.screenW - AppLoader.minimumW).div(2).toFloat(),
@@ -189,6 +207,8 @@ object PostProcessor : Disposable {
private val defaultResStr = "${AppLoader.minimumW}x${AppLoader.minimumH}"
private val safeAreaStr = "TV Safe Area"
private val versionStr = "Version ${AppLoader.getVERSION_STRING()}"
private val thisIsDebugStr = "${AppLoader.GAME_NAME} Develoment Build $versionStr"
/**
* Camera will be moved so that (newX, newY) would be sit on the top-left edge.

View File

@@ -11,6 +11,7 @@ import net.torvald.terrarum.floorInt
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.toInt
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
import net.torvald.terrarum.worlddrawer.WorldCamera
@@ -74,6 +75,15 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
/////////////////////
// GAMEPAD CONTROL //
/////////////////////
//////////////////////
// KEYBOARD CONTROL //
//////////////////////
// FIXME temporarily make zoom work with 'Z' key
terrarumIngame.screenZoom = 1f + KeyToggler.isOn(AppLoader.getConfigInt("keyzoom")).toInt()
}
private var f12Down = false

View File

@@ -198,6 +198,8 @@ object IngameRenderer : Disposable {
//renderingParticleCount = (particlesContainer?.buffer?.map { (!it.flagDespawn).toInt() } ?: listOf(0)).sum()
renderingUIsCount = ((uisToDraw?.map { (it?.isVisible ?: false).toInt() }) ?: listOf(0)).sum()
val zoom = Terrarum.ingame?.screenZoom ?: 1f
if (uisToDraw != null) {
uiListToDraw = uisToDraw
@@ -236,6 +238,8 @@ object IngameRenderer : Disposable {
val rgbTex = fboRGB_lightMixed.colorBufferTexture
val aTex = fboA_lightMixed.colorBufferTexture
rgbTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
aTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
// normal behaviour
if (!KeyToggler.isOn(Input.Keys.F6) &&
@@ -250,11 +254,11 @@ object IngameRenderer : Disposable {
blendNormal(batch)
batch.shader = shaderBlendGlow
shaderBlendGlow.setUniformi("tex1", 1)
batch.draw(rgbTex, 0f, 0f)
batch.draw(rgbTex, 0f, 0f, rgbTex.width * zoom, rgbTex.height * zoom)
}
// definitely something is not blended correctly
// blending is correct... somewhat. Alpha must be premultiplied
}
// something about RGB
else if (KeyToggler.isOn(Input.Keys.F6) &&
@@ -264,7 +268,7 @@ object IngameRenderer : Disposable {
batch.inUse {
blendNormal(batch)
batch.shader = null
batch.draw(rgbTex, 0f, 0f)
batch.draw(rgbTex, 0f, 0f, rgbTex.width * zoom, rgbTex.height * zoom)
// indicator
@@ -287,7 +291,7 @@ object IngameRenderer : Disposable {
batch.inUse {
blendNormal(batch)
batch.shader = null
batch.draw(aTex, 0f, 0f)
batch.draw(aTex, 0f, 0f, aTex.width * zoom, aTex.height * zoom)
// indicator

View File

@@ -12,9 +12,9 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.IngameRenderer
import net.torvald.terrarum.modulebasegame.RNGConsumer
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.ParticleMegaRain
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.modulebasegame.worldgenerator.WorldGenerator
@@ -161,6 +161,7 @@ internal object WeatherMixer : RNGConsumer {
IngameRenderer.shaderSkyboxFill.setUniformf("bottomColor", bottomCol.r, bottomCol.g, bottomCol.b)
IngameRenderer.shaderSkyboxFill.setUniformf("parallax", parallax.coerceIn(-1f, 1f))
IngameRenderer.shaderSkyboxFill.setUniformf("parallax_size", 1f/3f)
IngameRenderer.shaderSkyboxFill.setUniformf("zoomInv", 1f / (Terrarum.ingame?.screenZoom ?: 1f))
AppLoader.fullscreenQuad.render(IngameRenderer.shaderSkyboxFill, GL20.GL_TRIANGLES)
IngameRenderer.shaderSkyboxFill.end()

View File

@@ -635,7 +635,8 @@ internal object BlocksDrawer {
else
0f
)
shader.setUniformf("drawBreakage", if (mode == WIRE) 0f else 1f)
//shader.setUniformf("drawBreakage", if (mode == WIRE) 0f else 1f)
shader.setUniformf("zoom", Terrarum.ingame?.screenZoom ?: 1f)
tilesQuad.render(shader, GL20.GL_TRIANGLES)
shader.end()

View File

@@ -15,6 +15,9 @@ import org.dyn4j.geometry.Vector2
object WorldCamera {
private val TILE_SIZE = CreateTileAtlas.TILE_SIZE
val zoom: Float
get() = Terrarum.ingame?.screenZoom ?: 1f
var x: Int = 0 // left position
private set
var y: Int = 0 // top position
@@ -24,9 +27,9 @@ object WorldCamera {
var yEnd: Int = 0 // bottom position
private set
inline val gdxCamX: Float // centre position
get() = xCentre.toFloat()
get() = (x + width / 2f * zoom).toInt().toFloat()
inline val gdxCamY: Float// centre position
get() = yCentre.toFloat()
get() = (y + height / 2f * zoom).toInt().toFloat()
var width: Int = 0
private set
var height: Int = 0
@@ -41,8 +44,8 @@ object WorldCamera {
fun update(world: GameWorld, player: ActorWithBody?) {
if (player == null) return
width = FastMath.ceil(AppLoader.screenW / (Terrarum.ingame?.screenZoom ?: 1f)) // div, not mul
height = FastMath.ceil(AppLoader.screenH / (Terrarum.ingame?.screenZoom ?: 1f))
width = FastMath.ceil(AppLoader.screenW / zoom) // div, not mul
height = FastMath.ceil(AppLoader.screenH / zoom)
// TOP-LEFT position of camera border

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB