diff --git a/assets/.gitattributes b/assets/.gitattributes new file mode 100644 index 000000000..ca82ef549 --- /dev/null +++ b/assets/.gitattributes @@ -0,0 +1 @@ +*.{psd,tga,ogg} filter=lfs diff=lfs merge=lfs -text \ No newline at end of file diff --git a/assets/test.frag b/assets/test.frag new file mode 100644 index 000000000..0a7045b79 --- /dev/null +++ b/assets/test.frag @@ -0,0 +1,16 @@ +#ifdef GL_ES + precision mediump float; +#endif + +varying vec4 v_color; +varying vec2 v_texCoords; +uniform sampler2D u_texture; +uniform mat4 u_projTrans; + +void main() { + vec3 color = texture2D(u_texture, v_texCoords).rgb; + float gray = (3.0 * color.r + 4.0 * color.g + color.b) / 8.0; + vec3 grayscale = vec3(gray); + + gl_FragColor = vec4(grayscale, 1.0); +} \ No newline at end of file diff --git a/assets/test.vert b/assets/test.vert new file mode 100644 index 000000000..17d96ca8d --- /dev/null +++ b/assets/test.vert @@ -0,0 +1,14 @@ +attribute vec4 a_position; +attribute vec4 a_color; +attribute vec2 a_texCoord0; + +uniform mat4 u_projTrans; + +varying vec4 v_color; +varying vec2 v_texCoords; + +void main() { + v_color = a_color; + v_texCoords = a_texCoord0; + gl_Position = u_projTrans * a_position; +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/StateInGame.kt b/src/net/torvald/terrarum/StateInGame.kt index 75ebdfaf3..0426c8f03 100644 --- a/src/net/torvald/terrarum/StateInGame.kt +++ b/src/net/torvald/terrarum/StateInGame.kt @@ -798,6 +798,3 @@ constructor() : BasicGameState() { } } } - -fun Color.toInt() = redByte.shl(16) or greenByte.shl(8) or blueByte -fun Color.to10bit() = redByte.shl(20) or greenByte.shl(10) or blueByte diff --git a/src/net/torvald/terrarum/StateShaderTest.kt b/src/net/torvald/terrarum/StateShaderTest.kt new file mode 100644 index 000000000..72aa635ab --- /dev/null +++ b/src/net/torvald/terrarum/StateShaderTest.kt @@ -0,0 +1,100 @@ +package net.torvald.terrarum + +import net.torvald.terrarum.Terrarum.Companion.STATE_ID_TEST_SHADER +import org.lwjgl.opengl.* +import org.newdawn.slick.GameContainer +import org.newdawn.slick.Graphics +import org.newdawn.slick.Image +import org.newdawn.slick.opengl.renderer.SGL +import org.newdawn.slick.state.BasicGameState +import org.newdawn.slick.state.StateBasedGame +import shader.Shader +import org.lwjgl.opengl.GL11 +import org.lwjgl.opengl.ARBShaderObjects +import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.close +import jdk.nashorn.internal.runtime.ScriptingFunctions.readLine +import net.torvald.terrarum.gameworld.fmod +import org.newdawn.slick.Color +import org.newdawn.slick.opengl.TextureImpl +import java.io.InputStreamReader +import java.io.BufferedReader +import java.io.File +import java.io.FileInputStream + + + + + + + +/** + * Created by SKYHi14 on 2017-01-23. + */ +class StateShaderTest : BasicGameState() { + override fun getID() = STATE_ID_TEST_SHADER + + + + override fun init(container: GameContainer?, game: StateBasedGame?) { + } + + private lateinit var shaderTest: Shader + private lateinit var testImage: Image + + override fun enter(container: GameContainer?, game: StateBasedGame?) { + shaderTest = Shader.makeShader("./assets/test.vert", "./assets/test.frag") + + testImage = Image("./assets/test_texture.tga") + //testImage = Image("./logo_repository.png") + } + + override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) { + Terrarum.appgc.setTitle("${Terrarum.NAME} — F: ${Terrarum.appgc.fps}") + } + + override fun render(container: GameContainer?, game: StateBasedGame?, g: Graphics?) { + val x = 10f + val y = 10f + val width = testImage.width + val height = testImage.height + val textureWidth = testImage.textureWidth + val textureHeight = testImage.textureHeight + val textureOffsetX = testImage.textureOffsetX + val textureOffsetY = testImage.textureOffsetY + + + GL11.glClear(GL11.GL_COLOR_BUFFER_BIT) + // bind texture + // glBegin(SGL.GL_QUADS) + // do shader + // glEnd() + + + + //testImage.bind() + + GL11.glBegin(GL11.GL_QUADS) + + //GL20.glUseProgram(0) + shaderTest.startShader() + //GL13.glActiveTexture(testImage.texture.textureID) + //GL11.glBindTexture(GL13.GL_TEXTURE0, testImage.texture.textureID) + //testImage.bind() + shaderTest.setUniformIntVariable("u_texture", 0) + + /*GL11.glTexCoord2f(textureOffsetX, textureOffsetY) + GL11.glVertex3f(x, y, 0f) + GL11.glTexCoord2f(textureOffsetX, textureOffsetY + textureHeight) + GL11.glVertex3f(x, y + height, 0f) + GL11.glTexCoord2f(textureOffsetX + textureWidth, textureOffsetY + textureHeight) + GL11.glVertex3f(x + width, y + height, 0f) + GL11.glTexCoord2f(textureOffsetX + textureWidth, textureOffsetY) + GL11.glVertex3f(x + width, y, 0f)*/ + + g!!.color = Color.orange + g!!.fillRect(10f, 10f, 512f, 512f) + + GL20.glUseProgram(0) + GL11.glEnd() + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/StateVTTest.kt b/src/net/torvald/terrarum/StateVTTest.kt index fe7e25a49..e4f88ebd7 100644 --- a/src/net/torvald/terrarum/StateVTTest.kt +++ b/src/net/torvald/terrarum/StateVTTest.kt @@ -21,8 +21,8 @@ class StateVTTest : BasicGameState() { // HiRes: 100x64, LoRes: 80x25 val computerInside = BaseTerrarumComputer(8) - val vt = SimpleTextTerminal(SimpleTextTerminal.WHITE, 80, 25, - computerInside, colour = true, hires = false) + val vt = SimpleTextTerminal(SimpleTextTerminal.AMETHYST_NOVELTY, 80, 25, + computerInside, colour = false, hires = false) val vtUI = Image(vt.displayW, vt.displayH) @@ -56,31 +56,6 @@ class StateVTTest : BasicGameState() { blendNormal() g.drawImage(vtUI, vtUIrenderX, vtUIrenderY) - - - // cursor - if (vt.cursorBlinkOn) { - g.color = vt.getColor(if (vt.cursorBlink) vt.foreDefault else vt.backDefault) - - g.fillRect( - vt.fontW * vt.cursorX.toFloat() + vt.borderSize + vtUIrenderX, - vt.fontH * vt.cursorY.toFloat() + vt.borderSize + vtUIrenderY, - vt.fontW.toFloat(), - vt.fontH.toFloat() - ) - } - - - // not-pure-black screen - /*g.color = vt.colourScreen - blendScreen() - g.fillRect(vtUIrenderX, vtUIrenderY, vt.displayW.toFloat(), vt.displayH.toFloat()) - - - // colour overlay - g.color = vt.phosphor - blendMul() - g.fillRect(vtUIrenderX, vtUIrenderY, vt.displayW.toFloat(), vt.displayH.toFloat())*/ } override fun keyPressed(key: Int, c: Char) { diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index f582b670a..f4e360105 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -132,6 +132,7 @@ constructor(gamename: String) : StateBasedGame(gamename) { //addState(StateFontTester()) //addState(StateNoiseTexGen()) //addState(StateBlurTest()) + //addState(StateShaderTest()) ingame = StateInGame() addState(ingame) @@ -241,6 +242,7 @@ constructor(gamename: String) : StateBasedGame(gamename) { val STATE_ID_TEST_LIGHTNING_GFX = 0x101 val STATE_ID_TEST_TTY = 0x102 val STATE_ID_TEST_BLUR = 0x103 + val STATE_ID_TEST_SHADER = 0x104 val STATE_ID_TOOL_NOISEGEN = 0x200 @@ -538,4 +540,21 @@ fun Image.getPixel(x: Int, y: Int): IntArray { else 255 ) } -} \ No newline at end of file +} + +fun Color.toInt() = redByte.shl(16) or greenByte.shl(8) or blueByte +fun Color.to10bit() = redByte.shl(20) or greenByte.shl(10) or blueByte + +infix fun Color.screen(other: Color) = Color( + 1f - (1f - this.r) * (1f - other.r), + 1f - (1f - this.g) * (1f - other.g), + 1f - (1f - this.b) * (1f - other.b), + 1f - (1f - this.a) * (1f - other.a) +) + +infix fun Color.mul(other: Color) = Color( + this.r * other.r, + this.g * other.g, + this.b * other.b, + this.a * other.a +) diff --git a/src/net/torvald/terrarum/virtualcomputer/assets/lua/TBASEXEC.lua b/src/net/torvald/terrarum/virtualcomputer/assets/lua/TBASEXEC.lua index 046465768..b4e18b7f2 100644 --- a/src/net/torvald/terrarum/virtualcomputer/assets/lua/TBASEXEC.lua +++ b/src/net/torvald/terrarum/virtualcomputer/assets/lua/TBASEXEC.lua @@ -480,10 +480,6 @@ end -- END OF LEXER --------------------------------------------------------------- -local testprogram = [[ -10 PRINT "Hello, world!" -]] - _G._TBASIC.EXEC = function(cmdstring) -- you can access this interpreter with this global function _TBASIC._INTPRTR.RESET() diff --git a/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt b/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt index 369093cbe..1190708af 100644 --- a/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt +++ b/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt @@ -2,9 +2,7 @@ package net.torvald.terrarum.virtualcomputer.terminal import net.torvald.aa.AAFrame import net.torvald.aa.ColouredFastFont -import net.torvald.terrarum.blendNormal -import net.torvald.terrarum.blendMul -import net.torvald.terrarum.blendScreen +import net.torvald.terrarum.* import net.torvald.terrarum.gameactors.abs import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer import org.lwjgl.BufferUtils @@ -178,13 +176,11 @@ open class SimpleTextTerminal( } } - redrawSemaphore = false } - // cursor - /*if (cursorBlinkOn) { - g.color = getColor(if (cursorBlink) foreDefault else backDefault) + if (cursorBlinkOn) { + g.color = getColor(if (cursorBlink) foreDefault else backDefault) screen colourScreen mul phosphor g.fillRect( fontW * cursorX.toFloat() + borderSize, @@ -192,8 +188,40 @@ open class SimpleTextTerminal( fontW.toFloat(), fontH.toFloat() ) - }*/ + } + else { + val x = cursorX + val y = cursorY + val ch = screenBuffer.getChar(x, y) + // background + g.color = getColor(screenBuffer.getBackgroundColour(x, y)) screen colourScreen mul phosphor + g.fillRect(fontW * x.toFloat() + borderSize, fontH * y.toFloat() + borderSize, + fontW.toFloat(), fontH.toFloat()) + + // foreground + if (ch.toInt() != 0 && ch.toInt() != 32) { + g.color = getColor(screenBuffer.getForegroundColour(x, y)) screen colourScreen mul phosphor + g.drawString( + Character.toString(ch), + fontW * x.toFloat() + borderSize, fontH * y.toFloat() + borderSize) + } + } + + if (redrawSemaphore) { + // colour base + g.color = colourScreen + blendScreen() + g.fillRect(0f, 0f, fontW * width.toFloat() + 2 * borderSize, fontH * height.toFloat() + 2 * borderSize) + + // colour overlay + g.color = phosphor + blendMul() + g.fillRect(0f, 0f, fontW * width.toFloat() + 2 * borderSize, fontH * height.toFloat() + 2 * borderSize) + + + redrawSemaphore = false + } blendNormal()