more descriptive name for the blend-normal function because why there are two fucking standards for an alpha channel

This commit is contained in:
minjaesong
2022-10-31 01:52:40 +09:00
parent ccef7c32a0
commit 474279aefe
42 changed files with 122 additions and 108 deletions

View File

@@ -188,7 +188,7 @@ internal class UIHomeComputer : UICanvas(
otherBatch.begin()
otherBatch.shader = null
blendNormal(otherBatch)
blendNormalStraightAlpha(otherBatch)
otherBatch.color = Color.WHITE
otherBatch.draw(fbo.colorBufferTexture, posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
otherBatch.color = Toolkit.Theme.COL_INACTIVE

View File

@@ -557,7 +557,7 @@ public class App implements ApplicationListener {
FrameBufferManager.begin(renderFBO);
gdxClearAndSetBlend(.094f, .094f, .094f, 0f);
gdxClearAndEnableBlend(.094f, .094f, .094f, 0f);
setCameraPosition(0, 0);

View File

@@ -38,7 +38,7 @@ object ErrorDisp : Screen {
}
override fun render(delta: Float) {
gdxClearAndSetBlend(.094f, .094f, .094f, 0f)
gdxClearAndEnableBlend(.094f, .094f, .094f, 0f)

View File

@@ -50,7 +50,7 @@ class NoModuleDefaultTitlescreen(batch: FlippingSpriteBatch) : IngameInstance(ba
genericBackdrop
override fun render(updateRate: Float) {
gdxClearAndSetBlend(0f, 0f, 0f, 0f)
gdxClearAndEnableBlend(0f, 0f, 0f, 0f)
if (!init) {
val lh = 28f
@@ -68,7 +68,7 @@ class NoModuleDefaultTitlescreen(batch: FlippingSpriteBatch) : IngameInstance(ba
val centering = (App.scr.hf - heights.last() - App.fontGameFBO.lineHeight) / 2f
fbo.inAction(null, null) {
gdxClearAndSetBlend(backdrop)
gdxClearAndEnableBlend(backdrop)
batch.inUse {
batch.color = Color.WHITE
wot.reversed().forEachIndexed { index, s ->

View File

@@ -78,10 +78,10 @@ object SanicLoadScreen : LoadScreenBase() {
gdxClearAndSetBlend(.094f, .094f, .094f, 0f)
gdxClearAndEnableBlend(.094f, .094f, .094f, 0f)
textFbo.inAction(null, null) {
gdxClearAndSetBlend(0f, 0f, 0f, 0f)
gdxClearAndEnableBlend(0f, 0f, 0f, 0f)
}
// update arrow object
@@ -114,7 +114,7 @@ object SanicLoadScreen : LoadScreenBase() {
App.batch.inUse {
blendNormal(App.batch)
blendNormalStraightAlpha(App.batch)
App.fontGame
it.color = Color.WHITE
@@ -137,7 +137,7 @@ object SanicLoadScreen : LoadScreenBase() {
App.batch.inUse {
initViewPort(App.scr.width, App.scr.height) // dunno, no render without this
it.projectionMatrix = camera.combined
blendNormal(App.batch)
blendNormalStraightAlpha(App.batch)
// almost black background
@@ -204,7 +204,7 @@ object SanicLoadScreen : LoadScreenBase() {
initViewPort(App.scr.width, App.scr.height) // dunno, no render without this
it.projectionMatrix = camera.combined
blendNormal(App.batch)
blendNormalStraightAlpha(App.batch)

View File

@@ -479,46 +479,62 @@ fun blendDisable(batch: SpriteBatch) {
batch.disableBlending()
}
/**
* GLSource (foreground) must NOT have alpha premultiplied!
*/
fun blendNormal(batch: SpriteBatch) {
fun blendNormalStraightAlpha(batch: SpriteBatch) {
batch.enableBlending()
// batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA) // for premultiplied textures
batch.setBlendFunctionSeparate(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA) // for not premultiplied textures
batch.setBlendFunctionSeparate(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA)
// helpful links:
// - https://stackoverflow.com/questions/19674740/opengl-es2-premultiplied-vs-straight-alpha-blending#37869033
// - https://gamedev.stackexchange.com/questions/82741/normal-blend-mode-with-opengl-trouble
// - https://www.andersriggelsen.dk/glblendfunc.php
// - https://stackoverflow.com/questions/45781683/how-to-get-correct-sourceover-alpha-compositing-in-sdl-with-opengl
}
fun blendNormalPremultAlpha(batch: SpriteBatch) {
batch.enableBlending()
batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA)
// helpful links:
// - https://stackoverflow.com/questions/19674740/opengl-es2-premultiplied-vs-straight-alpha-blending#37869033
// - https://gamedev.stackexchange.com/questions/82741/normal-blend-mode-with-opengl-trouble
// - https://www.andersriggelsen.dk/glblendfunc.php
// - https://stackoverflow.com/questions/45781683/how-to-get-correct-sourceover-alpha-compositing-in-sdl-with-opengl
}
fun gdxClearAndSetBlend(color: Color) {
gdxClearAndSetBlend(color.r, color.g, color.b, color.a)
fun gdxClearAndEnableBlend(color: Color) {
gdxClearAndEnableBlend(color.r, color.g, color.b, color.a)
}
fun gdxClearAndSetBlend(r: Float, g: Float, b: Float, a: Float) {
fun gdxClearAndEnableBlend(r: Float, g: Float, b: Float, a: Float) {
Gdx.gl.glClearColor(r,g,b,a)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
gdxSetBlend()
gdxEnableBlend()
}
fun gdxSetBlend() {
fun gdxEnableBlend() {
Gdx.gl.glEnable(GL20.GL_TEXTURE_2D)
Gdx.gl.glEnable(GL20.GL_BLEND)
}
fun gdxSetBlendNormal() {
gdxSetBlend()
// Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA) // for premultiplied textures
Gdx.gl.glBlendFuncSeparate(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA) // for not premultiplied textures
fun gdxBlendNormalStraightAlpha() {
gdxEnableBlend()
Gdx.gl.glBlendFuncSeparate(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA)
// helpful links:
// - https://stackoverflow.com/questions/19674740/opengl-es2-premultiplied-vs-straight-alpha-blending#37869033
// - https://gamedev.stackexchange.com/questions/82741/normal-blend-mode-with-opengl-trouble
// - https://www.andersriggelsen.dk/glblendfunc.php
// - https://stackoverflow.com/questions/45781683/how-to-get-correct-sourceover-alpha-compositing-in-sdl-with-opengl
}
fun gdxSetBlendMul() {
gdxSetBlend()
fun gdxBlendNormalPremultAlpha() {
gdxEnableBlend()
Gdx.gl.glBlendFunc(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA)
// helpful links:
// - https://stackoverflow.com/questions/19674740/opengl-es2-premultiplied-vs-straight-alpha-blending#37869033
// - https://gamedev.stackexchange.com/questions/82741/normal-blend-mode-with-opengl-trouble
// - https://www.andersriggelsen.dk/glblendfunc.php
// - https://stackoverflow.com/questions/45781683/how-to-get-correct-sourceover-alpha-compositing-in-sdl-with-opengl
}
fun gdxBlendMul() {
gdxEnableBlend()
Gdx.gl.glBlendFunc(GL20.GL_DST_COLOR, GL20.GL_ONE_MINUS_SRC_ALPHA)
}
@@ -532,7 +548,7 @@ object BlendMode {
when (mode) {
SCREEN -> blendScreen(batch)
MULTIPLY -> blendMul(batch)
NORMAL -> blendNormal(batch)
NORMAL -> blendNormalStraightAlpha(batch)
//MAX -> blendLightenOnly() // not supported by GLES -- use shader
else -> throw Error("Unknown blend mode: $mode")
}

View File

@@ -105,7 +105,7 @@ object TerrarumPostProcessor : Disposable {
outFBO.inAction(camera, batch) {
App.measureDebugTime("Renderer.PostProcessor") {
gdxClearAndSetBlend(.094f, .094f, .094f, 0f)
gdxClearAndEnableBlend(.094f, .094f, .094f, 0f)
fbo.colorBufferTexture.setFilter(
Texture.TextureFilter.Linear,

View File

@@ -55,7 +55,7 @@ class UIFakeGradOverlay : UICanvas() {
blendMul(batch)
batch.draw(tex, 0f, 0f, App.scr.wf, App.scr.hf)
blendNormal(batch)
blendNormalStraightAlpha(batch)
}
override fun doOpening(delta: Float) {}
@@ -90,7 +90,7 @@ class UIFakeBlurOverlay(val blurRadius: Float, val nodarken: Boolean) : UICanvas
batch.color = darken
Toolkit.fillArea(batch, 0, 0, width, height)
blendNormal(batch)
blendNormalStraightAlpha(batch)
}
}

View File

@@ -267,7 +267,7 @@ class UIItemInventoryCatBar(
if (showSideButtons) sideButtons.forEach { it.render(batch, camera) }
blendNormal(batch)
blendNormalStraightAlpha(batch)
// underline

View File

@@ -54,7 +54,7 @@ class UIItemInventoryElemSimple(
private var highlightToSubCol = false
override fun render(batch: SpriteBatch, camera: Camera) {
blendNormal(batch)
blendNormalStraightAlpha(batch)
highlightToMainCol = customHighlightRuleMain?.invoke(this) ?: (equippedSlot != null && highlightEquippedItem) || forceHighlighted
highlightToSubCol = customHighlightRule2?.invoke(this) ?: false

View File

@@ -79,7 +79,7 @@ class UIItemInventoryElemWide(
var textHighlightNormalCol = Color.WHITE
override fun render(batch: SpriteBatch, camera: Camera) {
blendNormal(batch)
blendNormalStraightAlpha(batch)
highlightToMainCol = customHighlightRuleMain?.invoke(this) ?: (equippedSlot != null && highlightEquippedItem) || forceHighlighted
highlightToSubCol = customHighlightRule2?.invoke(this) ?: false
@@ -100,7 +100,7 @@ class UIItemInventoryElemWide(
if (item != null && itemImage != null) {
val amountString = amount.toItemCountText()
blendNormal(batch)
blendNormalStraightAlpha(batch)
// item image
batch.color = Color.WHITE

View File

@@ -1695,7 +1695,7 @@ open class ActorWithBody : Actor {
open fun drawGlow(batch: SpriteBatch) {
if (isVisible && spriteGlow != null) {
blendNormal(batch)
blendNormalStraightAlpha(batch)
drawSpriteInGoodPosition(spriteGlow!!, batch)
}
}

View File

@@ -38,7 +38,7 @@ class ChunkLoadingLoadScreen(screenToBeLoaded: IngameInstance, private val world
}
override fun render(delta: Float) {
gdxClearAndSetBlend(.094f, .094f, .094f, 0f)
gdxClearAndEnableBlend(.094f, .094f, .094f, 0f)
val drawWidth = Toolkit.drawWidth

View File

@@ -241,7 +241,7 @@ object IngameRenderer : Disposable {
// clear main or whatever super-FBO being used
//clearBuffer()
gdxClearAndSetBlend(.64f, .754f, .84f, 0f)
gdxClearAndEnableBlend(.64f, .754f, .84f, 0f)
///////////////////////////////////////////////////////////////////////
@@ -252,7 +252,7 @@ object IngameRenderer : Disposable {
aTex.texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
fboMixedOut.inAction(camera, batch) {
gdxClearAndSetBlend(0f, 0f, 0f, 0f)
gdxClearAndEnableBlend(0f, 0f, 0f, 0f)
// draw sky
WeatherMixer.render(camera, batch, world)
@@ -269,7 +269,7 @@ object IngameRenderer : Disposable {
batch.inUse {
blendNormal(batch)
blendNormalStraightAlpha(batch)
batch.shader = shaderBlendGlow
shaderBlendGlow.setUniformi("tex1", 1)
batch.draw(rgbTex,
@@ -287,7 +287,7 @@ object IngameRenderer : Disposable {
) {
debugMode = 1
batch.inUse {
blendNormal(batch)
blendNormalStraightAlpha(batch)
batch.shader = null
batch.draw(rgbTex,
-0.5f * rgbTex.regionWidth * zoom + 0.5f * rgbTex.regionWidth,
@@ -314,7 +314,7 @@ object IngameRenderer : Disposable {
) {
debugMode = 2
batch.inUse {
blendNormal(batch)
blendNormalStraightAlpha(batch)
batch.shader = null
batch.draw(aTex,
-0.5f * aTex.regionWidth * zoom + 0.5f * aTex.regionWidth,
@@ -348,7 +348,7 @@ object IngameRenderer : Disposable {
}
}
blendNormal(batch)
blendNormalStraightAlpha(batch)
batch.inUse {
// it's no use applying dithering here: colours are no longer "floats" once they're written to the FBO
@@ -389,7 +389,7 @@ object IngameRenderer : Disposable {
}
// works but some UI elements have wrong transparency -> should be fixed with Terrarum.gdxCleanAndSetBlend -- Torvald 2019-01-12
blendNormal(batch)
blendNormalStraightAlpha(batch)
batch.color = Color.WHITE
@@ -409,7 +409,7 @@ object IngameRenderer : Disposable {
processKawaseBlur(lightmapFbo)
blendNormal(batch)
blendNormalStraightAlpha(batch)
}
/**
@@ -479,14 +479,14 @@ object IngameRenderer : Disposable {
setCameraPosition(0f, 0f)
val (xrem, yrem) = worldCamToRenderPos()
gdxSetBlend()
gdxEnableBlend()
// App.getCurrentDitherTex().bind(1)
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it
batch.inUse {
blendNormal(batch)
blendNormalStraightAlpha(batch)
// draw world
batch.shader = shaderDemultiply
@@ -497,7 +497,7 @@ object IngameRenderer : Disposable {
lightTex.texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
if (KeyToggler.isOn(Input.Keys.F8))
blendNormal(batch)
blendNormalStraightAlpha(batch)
else
blendMul(batch)
@@ -522,7 +522,7 @@ object IngameRenderer : Disposable {
}
blendNormal(batch)
blendNormalStraightAlpha(batch)
}
private fun drawToA(
@@ -536,7 +536,7 @@ object IngameRenderer : Disposable {
fboA.inAction(null, null) {
clearBuffer()
// paint black
gdxClearAndSetBlend(0f,0f,0f,1f) // solid black: so that unused area will be also black
gdxClearAndEnableBlend(0f,0f,0f,1f) // solid black: so that unused area will be also black
}
fboA_lightMixed.inAction(null, null) { clearBuffer() }
@@ -591,7 +591,7 @@ object IngameRenderer : Disposable {
lightTex.texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
if (KeyToggler.isOn(Input.Keys.F8))
blendNormal(batch)
blendNormalStraightAlpha(batch)
else
blendMul(batch)
@@ -612,7 +612,7 @@ object IngameRenderer : Disposable {
}
blendNormal(batch)
blendNormalStraightAlpha(batch)
}
private fun drawOverlayActors(actors: List<ActorWithBody>?) {
@@ -652,7 +652,7 @@ object IngameRenderer : Disposable {
}
private fun clearBuffer() {
gdxClearAndSetBlend(0f,0f,0f,0f)
gdxClearAndEnableBlend(0f,0f,0f,0f)
}
private fun moveCameraToWorldCoord() {

View File

@@ -297,7 +297,7 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) {
//camera.setToOrtho(true, AppLoader.terrarumAppConfig.screenWf, AppLoader.terrarumAppConfig.screenHf)
// render world
gdxClearAndSetBlend(.64f, .754f, .84f, 1f)
gdxClearAndEnableBlend(.64f, .754f, .84f, 1f)
if (!demoWorld.layerTerrain.ptr.destroyed) { // FIXME q&d hack to circumvent the dangling pointer issue #26
@@ -328,7 +328,7 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) {
private fun renderOverlayTexts() {
setCameraPosition(0f, 0f)
blendNormal(batch)
blendNormalStraightAlpha(batch)
batch.shader = null
batch.color = Color.LIGHT_GRAY

View File

@@ -55,7 +55,7 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidt
}
override fun render(delta: Float) {
gdxClearAndSetBlend(.094f, .094f, .094f, 0f)
gdxClearAndEnableBlend(.094f, .094f, .094f, 0f)
val drawWidth = Toolkit.drawWidth

View File

@@ -237,7 +237,7 @@ internal class UIStorageChest : UICanvas(
itemListPlayer.render(batch, camera)
blendNormal(batch)
blendNormalStraightAlpha(batch)
// encumbrance meter
val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"]

View File

@@ -465,7 +465,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
// control hints
val controlHintXPos = thisOffsetX.toFloat()
blendNormal(batch)
blendNormalStraightAlpha(batch)
App.fontGame.draw(batch, controlHelp, controlHintXPos, full.yEnd - 20)
@@ -482,7 +482,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
else 0f
App.fontGame.draw(batch, encumbranceText, encumbBarTextXPos, encumbBarYPos - 3f)
// encumbrance bar background
blendNormal(batch)
blendNormalStraightAlpha(batch)
val encumbCol = UIItemInventoryCellCommonRes.getHealthMeterColour(1f - encumbrancePerc, 0f, 1f)
val encumbBack = encumbCol mul UIItemInventoryCellCommonRes.meterBackDarkening
batch.color = encumbBack
@@ -511,7 +511,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
}
blendNormal(batch)
blendNormalStraightAlpha(batch)
}
override fun doOpening(delta: Float) {

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.App
import net.torvald.terrarum.Second
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.blendNormalStraightAlpha
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
@@ -51,7 +51,7 @@ class Notification : UICanvas() {
private val drawColor = Color(1f, 1f, 1f, 1f)
override fun renderUI(batch: SpriteBatch, camera: Camera) {
blendNormal(batch)
blendNormalStraightAlpha(batch)
drawColor.a = handler.opacity
fontCol.a = handler.opacity

View File

@@ -6,7 +6,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.BlockCodex
import net.torvald.terrarum.ItemCodex
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.blendNormalStraightAlpha
import net.torvald.terrarum.modulebasegame.BuildingMaker
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_WHITE
import net.torvald.terrarum.ui.Toolkit
@@ -128,7 +128,7 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
palette.forEach { it.render(batch, camera) }
blendNormal(batch)
blendNormalStraightAlpha(batch)
// gaps between tabs and close button
batch.color = DEFAULT_BACKGROUNDCOL

View File

@@ -91,7 +91,7 @@ internal class UIInventoryCells(
// control hints
val controlHintXPos = full.offsetX
blendNormal(batch)
blendNormalStraightAlpha(batch)
batch.color = Color.WHITE
App.fontGame.draw(batch, full.listControlHelp, controlHintXPos, full.yEnd - 20)
@@ -110,7 +110,7 @@ internal class UIInventoryCells(
App.fontGame.draw(batch, encumbranceText, encumbBarTextXPos, encumbBarYPos - 3f)
// encumbrance bar background
blendNormal(batch)
blendNormalStraightAlpha(batch)
val encumbCol = UIItemInventoryCellCommonRes.getHealthMeterColour(1f - encumbrancePerc, 0f, 1f)
val encumbBack = encumbCol mul UIItemInventoryCellCommonRes.meterBackDarkening
batch.color = encumbBack

View File

@@ -8,7 +8,7 @@ import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.INGAME
import net.torvald.terrarum.Terrarum.getPlayerSaveFiledesc
import net.torvald.terrarum.Terrarum.getWorldSaveFiledesc
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.blendNormalStraightAlpha
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent
import net.torvald.terrarum.modulebasegame.TerrarumIngame
@@ -271,7 +271,7 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
blendNormal(batch)
blendNormalStraightAlpha(batch)
batch.color = Color.WHITE
screenRenders[screen](batch, camera)
}

View File

@@ -65,7 +65,7 @@ class UIInventoryFull(
fun drawBackground(batch: SpriteBatch) {
batch.end()
gdxSetBlendNormal()
gdxBlendNormalStraightAlpha()
if (shapeRenderer == null) {
shapeRenderer = ShapeRenderer()

View File

@@ -7,7 +7,6 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.FrameBuffer
import com.badlogic.gdx.utils.GdxRuntimeException
import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
import net.torvald.terrarum.blockstats.MinimapComposer
import net.torvald.terrarum.blockstats.MinimapComposer.MINIMAP_TILE_HEIGHT
@@ -67,7 +66,7 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
blendNormal(batch)
blendNormalStraightAlpha(batch)
val cellOffY = INVENTORY_CELLS_OFFSET_Y()
val worldWidth = INGAME.world.width
@@ -145,7 +144,7 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
minimapFBO.inActionF(minimapCamera, batch) {
gdxClearAndSetBlend(MINIMAP_SKYCOL)
gdxClearAndEnableBlend(MINIMAP_SKYCOL)
batch.inUse {

View File

@@ -68,7 +68,7 @@ class UIItemInventoryEquippedView(
}
override fun render(batch: SpriteBatch, camera: Camera) {
blendNormal(batch)
blendNormalStraightAlpha(batch)
val posXDelta = posX - oldPosX
itemGrid.forEach { it.posX += posXDelta }
@@ -84,7 +84,7 @@ class UIItemInventoryEquippedView(
// sprite
INGAME.actorNowPlaying?.let { actor ->
actor.sprite?.let {
blendNormal(batch)
blendNormalStraightAlpha(batch)
batch.color = SPRITE_DRAW_COL

View File

@@ -295,7 +295,7 @@ class UILoadDemoSavefiles(val remoCon: UIRemoCon) : UICanvas() {
// to hide the "flipped skybox" artefact
batch.end()
gdxClearAndSetBlend(.094f, .094f, .094f, 0f)
gdxClearAndEnableBlend(.094f, .094f, .094f, 0f)
batch.begin()
@@ -314,7 +314,7 @@ class UILoadDemoSavefiles(val remoCon: UIRemoCon) : UICanvas() {
lateinit var savePixmap: Pixmap
sliderFBO.inAction(camera as OrthographicCamera, batch) {
gdxClearAndSetBlend(0f, 0f, 0f, 0f)
gdxClearAndEnableBlend(0f, 0f, 0f, 0f)
setCameraPosition(batch, camera, 0f, 0f)
batch.color = Color.WHITE
@@ -787,7 +787,7 @@ class UIItemWorldCells(
// draw thumbnail
batch.color = Color.WHITE
blendNormal(batch)
blendNormalStraightAlpha(batch)
batch.draw(thumb ?: CommonResourcePool.getAsTextureRegion("terrarum-defaultsavegamethumb"), x, y, width.toFloat(), height.toFloat())
// draw gradient
blendMul(batch)
@@ -795,7 +795,7 @@ class UIItemWorldCells(
// draw texts
batch.color = highlightCol
blendNormal(batch)
blendNormalStraightAlpha(batch)
// save status icon
(if (saveDamaged) icons.get(1,0)

View File

@@ -7,7 +7,7 @@ import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.App
import net.torvald.terrarum.ItemCodex
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.blendNormalStraightAlpha
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.modulebasegame.BuildingMaker
@@ -74,7 +74,7 @@ class UIPaletteSelector(val parent: BuildingMaker) : UICanvas() {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
// draw title bar
batch.color = UINSMenu.DEFAULT_TITLEBACKCOL
blendNormal(batch)
blendNormalStraightAlpha(batch)
Toolkit.fillArea(batch, 0, 0, width, LINE_HEIGHT)
// draw "Pal."

View File

@@ -141,7 +141,7 @@ class UITitleModules(val remoCon: UIRemoCon) : UICanvas() {
lateinit var savePixmap: Pixmap
sliderFBO.inAction(camera as OrthographicCamera, batch) {
gdxClearAndSetBlend(0f, 0f, 0f, 0f)
gdxClearAndEnableBlend(0f, 0f, 0f, 0f)
setCameraPosition(batch, camera, 0f, 0f)
batch.color = Color.WHITE

View File

@@ -10,7 +10,7 @@ import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.unicode.EMDASH
import net.torvald.gdx.graphics.PixmapIO2
import net.torvald.terrarum.gdxClearAndSetBlend
import net.torvald.terrarum.gdxClearAndEnableBlend
import net.torvald.terrarum.inUse
import java.awt.BorderLayout
import java.awt.Font
@@ -288,7 +288,7 @@ class SpriteAssemblerPreview: Game() {
}
gdxClearAndSetBlend(bgCol)
gdxClearAndEnableBlend(bgCol)
batch.inUse {

View File

@@ -7,7 +7,7 @@ import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.unicode.EMDASH
import net.torvald.terrarum.gdxClearAndSetBlend
import net.torvald.terrarum.gdxClearAndEnableBlend
import net.torvald.terrarum.inUse
/**
@@ -101,7 +101,7 @@ class GetKeycode : Game() {
override fun render() {
Gdx.graphics.setTitle("Get Keycode $EMDASH F: ${Gdx.graphics.framesPerSecond}")
gdxClearAndSetBlend(.1f,.1f,.1f,1f)
gdxClearAndEnableBlend(.1f,.1f,.1f,1f)
batch.inUse {
font.draw(batch, "Hit a key", 10f, 20f)

View File

@@ -84,7 +84,7 @@ class UIElemTest : ApplicationAdapter() {
override fun render() {
gdxClearAndSetBlend(0.1f, 0.1f, 0.1f, 1f)
gdxClearAndEnableBlend(0.1f, 0.1f, 0.1f, 1f)
ui.update(Gdx.graphics.deltaTime)
ui.render(batch, camera)

View File

@@ -359,7 +359,7 @@ class BasicDebugInfoWindow : UICanvas() {
Toolkit.fillArea(batch, bar_x, bar_y, bar_w, -bar_h)
}
}
blendNormal(batch)
blendNormalStraightAlpha(batch)
}
private fun drawGamepadAxis(gamepad: TerrarumController, batch: SpriteBatch, axisX: Float, axisY: Float, uiX: Int, uiY: Int) {
@@ -375,10 +375,10 @@ class BasicDebugInfoWindow : UICanvas() {
val deadzone = App.gamepadDeadzone
blendNormal(batch)
blendNormalStraightAlpha(batch)
batch.end()
gdxSetBlendNormal()
gdxBlendNormalStraightAlpha()
Terrarum.inShapeRenderer {
it.color = uiColour
it.rect(uiX.toFloat(), App.scr.height - uiY.toFloat(), w, -h)

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.BlendMode
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.blendNormalStraightAlpha
/**
* Created by minjaesong on 2017-07-16.
@@ -62,7 +62,7 @@ open class UIItemImageButton(
// draw image
blendNormal(batch)
blendNormalStraightAlpha(batch)
batch.color = if (highlighted) highlightCol
else if (mouseUp) activeCol

View File

@@ -58,7 +58,7 @@ class UIItemModuleInfoCell(
private val ccDesc = App.fontGame.toColorCode(13,13,13)
override fun render(batch: SpriteBatch, camera: Camera) {
blendNormal(batch)
blendNormalStraightAlpha(batch)
batch.color = Toolkit.Theme.COL_CELL_FILL
Toolkit.fillArea(batch, initialX, initialY, 32, height)

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.App
import net.torvald.terrarum.BlendMode
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.blendNormalStraightAlpha
import net.torvald.terrarum.langpack.Lang
/**
@@ -102,7 +102,7 @@ open class UIItemTextButton(
}*/
blendNormal(batch)
blendNormalStraightAlpha(batch)
if (hasBorder) {
batch.color = Toolkit.Theme.COL_CELL_FILL

View File

@@ -483,7 +483,7 @@ class UIItemTextLineInput(
if (true || fboUpdateLatch) {
fboUpdateLatch = false
fbo.inAction(camera as OrthographicCamera, batch) { batch.inUse {
gdxClearAndSetBlend(0f, 0f, 0f, 0f)
gdxClearAndEnableBlend(0f, 0f, 0f, 0f)
it.color = Color.WHITE

View File

@@ -8,7 +8,6 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.FrameBuffer
import net.torvald.terrarum.*
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
* @param width width of the text input where the text gets drawn, not the entire item
@@ -130,7 +129,7 @@ class UIItemTextSelector(
if (fboUpdateLatch) {
fboUpdateLatch = false
fbo.inAction(camera as OrthographicCamera, batch) { batch.inUse {
gdxClearAndSetBlend(0f, 0f, 0f, 0f)
gdxClearAndEnableBlend(0f, 0f, 0f, 0f)
it.color = Color.WHITE
val t = labelCache[selection]

View File

@@ -7,7 +7,7 @@ import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.blendNormalStraightAlpha
import net.torvald.terrarum.toInt
import kotlin.math.roundToInt
@@ -95,7 +95,7 @@ class UIItemToggleButton(
override fun render(batch: SpriteBatch, camera: Camera) {
batch.color = Color.WHITE
blendNormal(batch)
blendNormalStraightAlpha(batch)
batch.draw(togglerBase, posX.toFloat(), posY.toFloat())
batch.draw(togglerHandle, (posX + handlePos).toFloat(), posY.toFloat())

View File

@@ -174,7 +174,7 @@ class UINSMenu(
Toolkit.fillArea(batch, it.ui.posX.toFloat(), it.ui.posY.toFloat() - LINE_HEIGHT, it.ui.width.toFloat(), LINE_HEIGHT.toFloat())
batch.color = titleTextCol
blendNormal(batch)
blendNormalStraightAlpha(batch)
App.fontGame.draw(batch, it.title, TEXT_OFFSETX + it.ui.posX, TEXT_OFFSETY + it.ui.posY - LINE_HEIGHT)
// draw the list

View File

@@ -186,7 +186,7 @@ internal object WeatherMixer : RNGConsumer {
// draw using shaperenderer or whatever
//Terrarum.textureWhiteSquare.bind(0)
gdxSetBlendNormal()
gdxBlendNormalStraightAlpha()
// draw to skybox texture
skyboxPixmap.setColor(colBottom)

View File

@@ -207,15 +207,15 @@ internal object BlocksDrawer {
}
internal fun drawWall(projectionMatrix: Matrix4, drawGlow: Boolean) {
gdxSetBlendNormal()
gdxBlendNormalStraightAlpha()
renderUsingBuffer(WALL, projectionMatrix, drawGlow)
gdxSetBlendMul()
gdxBlendMul()
renderUsingBuffer(OCCLUSION, projectionMatrix, false)
}
internal fun drawTerrain(projectionMatrix: Matrix4, drawGlow: Boolean) {
gdxSetBlendNormal()
gdxBlendNormalStraightAlpha()
renderUsingBuffer(TERRAIN, projectionMatrix, drawGlow)
renderUsingBuffer(FLUID, projectionMatrix, drawGlow)
@@ -223,14 +223,14 @@ internal object BlocksDrawer {
internal fun drawFront(projectionMatrix: Matrix4) {
gdxSetBlendMul()
gdxBlendMul()
// let's just not MUL on terrain, make it FLUID only...
renderUsingBuffer(FLUID, projectionMatrix, false)
gdxSetBlendNormal()
gdxBlendNormalStraightAlpha()
/*if (selectedWireRenderClass.isNotBlank()) {
//println("Wires! draw: $drawWires") // use F10 instead

View File

@@ -7,7 +7,7 @@ import net.torvald.terrarum.App
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
import net.torvald.terrarum.blendMul
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.blendNormalStraightAlpha
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockstats.BlockStats
import net.torvald.terrarum.gameworld.GameWorld
@@ -68,7 +68,7 @@ object FeaturesDrawer {
(App.scr.height * if (zoom < 1) 1f / zoom else zoom).roundToInt()
)
blendNormal(batch)
blendNormalStraightAlpha(batch)
}
/**