mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-08 04:41:51 +09:00
new blending function for SpriteGlow, which now uses no alpha channel; reduced the number of framebuffer used to draw a world from 2 to 1.
Former-commit-id: 823182690f0c0dfc73a46474e194cbf6470fe5ad Former-commit-id: 9c4e041ef2799841d905c2b6dc32d578d9c082a3
This commit is contained in:
1
assets/graphics/sprites/.gitattributes
vendored
1
assets/graphics/sprites/.gitattributes
vendored
@@ -1 +0,0 @@
|
||||
*.{psd,tga,ogg} filter=lfs diff=lfs merge=lfs -text
|
||||
BIN
assets/graphics/sprites/test_player_glow.png
Normal file
BIN
assets/graphics/sprites/test_player_glow.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
@@ -72,8 +72,7 @@ constructor() : BasicGameState() {
|
||||
val ZOOM_MAX = 2.0f
|
||||
val ZOOM_MIN = 0.5f
|
||||
|
||||
val tilesDrawFrameBuffer = Image(Terrarum.WIDTH.div(ZOOM_MIN).ceilInt(), Terrarum.HEIGHT.div(ZOOM_MIN).ceilInt())
|
||||
val actorsDrawFrameBuffer = Image(Terrarum.WIDTH.div(ZOOM_MIN).ceilInt(), Terrarum.HEIGHT.div(ZOOM_MIN).ceilInt())
|
||||
val worldDrawFrameBuffer = Image(Terrarum.WIDTH.div(ZOOM_MIN).ceilInt(), Terrarum.HEIGHT.div(ZOOM_MIN).ceilInt())
|
||||
val uisDrawFrameBuffer = Image(Terrarum.WIDTH, Terrarum.HEIGHT)
|
||||
|
||||
//private lateinit var shader12BitCol: Shader // grab LibGDX if you want some shader
|
||||
@@ -274,27 +273,26 @@ constructor() : BasicGameState() {
|
||||
|
||||
override fun render(gc: GameContainer, sbg: StateBasedGame, gwin: Graphics) {
|
||||
// clean the shit beforehand
|
||||
tilesDrawFrameBuffer.graphics.clear()
|
||||
actorsDrawFrameBuffer.graphics.clear()
|
||||
worldDrawFrameBuffer.graphics.clear()
|
||||
uisDrawFrameBuffer.graphics.clear()
|
||||
|
||||
blendNormal()
|
||||
|
||||
|
||||
drawSkybox(tilesDrawFrameBuffer.graphics)
|
||||
// FIXME skybox is not scaled at all
|
||||
drawSkybox(worldDrawFrameBuffer.graphics)
|
||||
|
||||
|
||||
// make camara work //
|
||||
// compensate for zoom. UIs must be treated specially! (see UIHandler)
|
||||
//g.translate(-MapCamera.cameraX * screenZoom, -MapCamera.cameraY * screenZoom)
|
||||
tilesDrawFrameBuffer.graphics.translate(-MapCamera.cameraX.toFloat(), -MapCamera.cameraY.toFloat())
|
||||
actorsDrawFrameBuffer.graphics.translate(-MapCamera.cameraX.toFloat(), -MapCamera.cameraY.toFloat())
|
||||
worldDrawFrameBuffer.graphics.translate(-MapCamera.cameraX.toFloat(), -MapCamera.cameraY.toFloat())
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// draw map related stuffs //
|
||||
/////////////////////////////
|
||||
MapCamera.renderBehind(gc, tilesDrawFrameBuffer.graphics)
|
||||
MapCamera.renderBehind(gc, worldDrawFrameBuffer.graphics)
|
||||
|
||||
|
||||
/////////////////
|
||||
@@ -302,10 +300,10 @@ constructor() : BasicGameState() {
|
||||
/////////////////
|
||||
actorContainer.forEach { actor ->
|
||||
if (actor is ActorWithBody && actor.inScreen() && actor !is Player) {
|
||||
actor.drawBody(gc, actorsDrawFrameBuffer.graphics)
|
||||
actor.drawBody(gc, worldDrawFrameBuffer.graphics)
|
||||
}
|
||||
}
|
||||
player.drawBody(gc, actorsDrawFrameBuffer.graphics)
|
||||
player.drawBody(gc, worldDrawFrameBuffer.graphics)
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
@@ -313,15 +311,15 @@ constructor() : BasicGameState() {
|
||||
/////////////////////////////
|
||||
LightmapRenderer.renderLightMap()
|
||||
|
||||
MapCamera.renderFront(gc, tilesDrawFrameBuffer.graphics)
|
||||
MapDrawer.render(gc, tilesDrawFrameBuffer.graphics)
|
||||
MapCamera.renderFront(gc, worldDrawFrameBuffer.graphics)
|
||||
MapDrawer.render(gc, worldDrawFrameBuffer.graphics)
|
||||
|
||||
|
||||
blendMul()
|
||||
MapDrawer.drawEnvOverlay(actorsDrawFrameBuffer.graphics)
|
||||
MapDrawer.drawEnvOverlay(worldDrawFrameBuffer.graphics)
|
||||
|
||||
if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendMul() else blendNormal()
|
||||
LightmapRenderer.draw(actorsDrawFrameBuffer.graphics)
|
||||
LightmapRenderer.draw(worldDrawFrameBuffer.graphics)
|
||||
blendNormal()
|
||||
|
||||
|
||||
@@ -330,10 +328,10 @@ constructor() : BasicGameState() {
|
||||
//////////////////////
|
||||
actorContainer.forEach { actor ->
|
||||
if (actor is ActorWithBody && actor.inScreen() && actor !is Player) {
|
||||
actor.drawGlow(gc, actorsDrawFrameBuffer.graphics)
|
||||
actor.drawGlow(gc, worldDrawFrameBuffer.graphics)
|
||||
}
|
||||
}
|
||||
player.drawGlow(gc, actorsDrawFrameBuffer.graphics)
|
||||
player.drawGlow(gc, worldDrawFrameBuffer.graphics)
|
||||
|
||||
|
||||
////////////////////////
|
||||
@@ -343,17 +341,17 @@ constructor() : BasicGameState() {
|
||||
if (debugWindow.isVisible) {
|
||||
actorContainer.forEachIndexed { i, actor ->
|
||||
if (actor is ActorWithBody) {
|
||||
actorsDrawFrameBuffer.graphics.color = Color.white
|
||||
actorsDrawFrameBuffer.graphics.font = Terrarum.fontSmallNumbers
|
||||
actorsDrawFrameBuffer.graphics.drawString(
|
||||
worldDrawFrameBuffer.graphics.color = Color.white
|
||||
worldDrawFrameBuffer.graphics.font = Terrarum.fontSmallNumbers
|
||||
worldDrawFrameBuffer.graphics.drawString(
|
||||
actor.referenceID.toString(),
|
||||
actor.hitbox.posX.toFloat(),
|
||||
actor.hitbox.pointedY.toFloat() + 4
|
||||
)
|
||||
|
||||
if (DEBUG_ARRAY) {
|
||||
actorsDrawFrameBuffer.graphics.color = GameFontBase.codeToCol["g"]
|
||||
actorsDrawFrameBuffer.graphics.drawString(
|
||||
worldDrawFrameBuffer.graphics.color = GameFontBase.codeToCol["g"]
|
||||
worldDrawFrameBuffer.graphics.drawString(
|
||||
i.toString(),
|
||||
actor.hitbox.posX.toFloat(),
|
||||
actor.hitbox.pointedY.toFloat() + 4 + 10
|
||||
@@ -364,7 +362,7 @@ constructor() : BasicGameState() {
|
||||
}
|
||||
// fluidmap debug
|
||||
if (KeyToggler.isOn(Key.F4))
|
||||
WorldSimulator.drawFluidMapDebug(actorsDrawFrameBuffer.graphics)
|
||||
WorldSimulator.drawFluidMapDebug(worldDrawFrameBuffer.graphics)
|
||||
|
||||
|
||||
//////////////
|
||||
@@ -379,8 +377,7 @@ constructor() : BasicGameState() {
|
||||
/////////////////
|
||||
// draw layers //
|
||||
/////////////////
|
||||
gwin.drawImage(tilesDrawFrameBuffer, 0f, 0f)
|
||||
gwin.drawImage(actorsDrawFrameBuffer.getScaledCopy(screenZoom), 0f, 0f)
|
||||
gwin.drawImage(worldDrawFrameBuffer.getScaledCopy(screenZoom), 0f, 0f)
|
||||
gwin.drawImage(uisDrawFrameBuffer, 0f, 0f)
|
||||
}
|
||||
|
||||
|
||||
@@ -432,9 +432,12 @@ fun main(args: Array<String>) {
|
||||
Terrarum.main(args)
|
||||
}
|
||||
|
||||
// I must say: What the fuck is wrong with you, Slick2D?!
|
||||
///////////////////////////////////
|
||||
// customised blending functions //
|
||||
///////////////////////////////////
|
||||
|
||||
fun blendMul() {
|
||||
// I must say: What the fuck is wrong with you, Slick2D? Your built-it blending is just fucking wrong.
|
||||
GL11.glEnable(GL11.GL_BLEND)
|
||||
GL11.glColorMask(true, true, true, true)
|
||||
GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA)
|
||||
@@ -445,13 +448,27 @@ fun blendNormal() {
|
||||
GL11.glColorMask(true, true, true, true)
|
||||
//GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
|
||||
|
||||
// TODO seems working as intended (no more whitened-out semitransparent colour), but needs further investigation
|
||||
// semitransparent textures working as intended with this,
|
||||
// but needs further investigation in the case of:
|
||||
// TODO blend semitransparent over semitransparent
|
||||
GL14.glBlendFuncSeparate(
|
||||
GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, // blend func for RGB channels
|
||||
GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA // blend func for alpha channels
|
||||
)
|
||||
}
|
||||
|
||||
fun blendLightenOnly() {
|
||||
GL11.glEnable(GL11.GL_BLEND)
|
||||
GL14.glBlendFuncSeparate(
|
||||
GL11.GL_ONE, GL11.GL_ONE, // blend func for RGB channels
|
||||
GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA // blend func for alpha channels
|
||||
)
|
||||
GL20.glBlendEquationSeparate(
|
||||
GL14.GL_MAX,
|
||||
GL14.GL_FUNC_ADD
|
||||
)
|
||||
}
|
||||
|
||||
fun blendAlphaMap() {
|
||||
GL11.glDisable(GL11.GL_BLEND)
|
||||
GL11.glColorMask(false, false, false, true)
|
||||
|
||||
@@ -899,7 +899,7 @@ open class ActorWithBody : Actor() {
|
||||
|
||||
open fun drawGlow(gc: GameContainer, g: Graphics) {
|
||||
if (isVisible && spriteGlow != null) {
|
||||
blendNormal()
|
||||
blendLightenOnly()
|
||||
|
||||
if (!sprite!!.flippedHorizontal()) {
|
||||
spriteGlow!!.render(g,
|
||||
|
||||
@@ -32,7 +32,7 @@ object PlayerBuilderSigrid {
|
||||
p.sprite!!.setRowsAndFrames(1, 1)
|
||||
|
||||
p.makeNewSpriteGlow(28, 51)
|
||||
p.spriteGlow!!.setSpriteImage("assets/graphics/sprites/test_player_glow.tga")
|
||||
p.spriteGlow!!.setSpriteImage("assets/graphics/sprites/test_player_glow.png")
|
||||
p.spriteGlow!!.setDelay(200)
|
||||
p.spriteGlow!!.setRowsAndFrames(1, 1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user