mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 10:34:06 +09:00
VT redraw on request
Former-commit-id: 3ada71215d9291760704a982cc3952061dbc7afe Former-commit-id: ca1495e668e88bc7214429472ad918621a650189
This commit is contained in:
1
assets/.gitattributes
vendored
Normal file
1
assets/.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.{psd,tga,ogg} filter=lfs diff=lfs merge=lfs -text
|
||||||
16
assets/test.frag
Normal file
16
assets/test.frag
Normal file
@@ -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);
|
||||||
|
}
|
||||||
14
assets/test.vert
Normal file
14
assets/test.vert
Normal file
@@ -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;
|
||||||
|
}
|
||||||
@@ -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
|
|
||||||
|
|||||||
100
src/net/torvald/terrarum/StateShaderTest.kt
Normal file
100
src/net/torvald/terrarum/StateShaderTest.kt
Normal file
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,8 +21,8 @@ class StateVTTest : BasicGameState() {
|
|||||||
|
|
||||||
// HiRes: 100x64, LoRes: 80x25
|
// HiRes: 100x64, LoRes: 80x25
|
||||||
val computerInside = BaseTerrarumComputer(8)
|
val computerInside = BaseTerrarumComputer(8)
|
||||||
val vt = SimpleTextTerminal(SimpleTextTerminal.WHITE, 80, 25,
|
val vt = SimpleTextTerminal(SimpleTextTerminal.AMETHYST_NOVELTY, 80, 25,
|
||||||
computerInside, colour = true, hires = false)
|
computerInside, colour = false, hires = false)
|
||||||
|
|
||||||
|
|
||||||
val vtUI = Image(vt.displayW, vt.displayH)
|
val vtUI = Image(vt.displayW, vt.displayH)
|
||||||
@@ -56,31 +56,6 @@ class StateVTTest : BasicGameState() {
|
|||||||
|
|
||||||
blendNormal()
|
blendNormal()
|
||||||
g.drawImage(vtUI, vtUIrenderX, vtUIrenderY)
|
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) {
|
override fun keyPressed(key: Int, c: Char) {
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ constructor(gamename: String) : StateBasedGame(gamename) {
|
|||||||
//addState(StateFontTester())
|
//addState(StateFontTester())
|
||||||
//addState(StateNoiseTexGen())
|
//addState(StateNoiseTexGen())
|
||||||
//addState(StateBlurTest())
|
//addState(StateBlurTest())
|
||||||
|
//addState(StateShaderTest())
|
||||||
|
|
||||||
ingame = StateInGame()
|
ingame = StateInGame()
|
||||||
addState(ingame)
|
addState(ingame)
|
||||||
@@ -241,6 +242,7 @@ constructor(gamename: String) : StateBasedGame(gamename) {
|
|||||||
val STATE_ID_TEST_LIGHTNING_GFX = 0x101
|
val STATE_ID_TEST_LIGHTNING_GFX = 0x101
|
||||||
val STATE_ID_TEST_TTY = 0x102
|
val STATE_ID_TEST_TTY = 0x102
|
||||||
val STATE_ID_TEST_BLUR = 0x103
|
val STATE_ID_TEST_BLUR = 0x103
|
||||||
|
val STATE_ID_TEST_SHADER = 0x104
|
||||||
|
|
||||||
val STATE_ID_TOOL_NOISEGEN = 0x200
|
val STATE_ID_TOOL_NOISEGEN = 0x200
|
||||||
|
|
||||||
@@ -539,3 +541,20 @@ fun Image.getPixel(x: Int, y: Int): IntArray {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|||||||
@@ -480,10 +480,6 @@ end
|
|||||||
|
|
||||||
-- END OF LEXER ---------------------------------------------------------------
|
-- END OF LEXER ---------------------------------------------------------------
|
||||||
|
|
||||||
local testprogram = [[
|
|
||||||
10 PRINT "Hello, world!"
|
|
||||||
]]
|
|
||||||
|
|
||||||
|
|
||||||
_G._TBASIC.EXEC = function(cmdstring) -- you can access this interpreter with this global function
|
_G._TBASIC.EXEC = function(cmdstring) -- you can access this interpreter with this global function
|
||||||
_TBASIC._INTPRTR.RESET()
|
_TBASIC._INTPRTR.RESET()
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ package net.torvald.terrarum.virtualcomputer.terminal
|
|||||||
|
|
||||||
import net.torvald.aa.AAFrame
|
import net.torvald.aa.AAFrame
|
||||||
import net.torvald.aa.ColouredFastFont
|
import net.torvald.aa.ColouredFastFont
|
||||||
import net.torvald.terrarum.blendNormal
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.blendMul
|
|
||||||
import net.torvald.terrarum.blendScreen
|
|
||||||
import net.torvald.terrarum.gameactors.abs
|
import net.torvald.terrarum.gameactors.abs
|
||||||
import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer
|
import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer
|
||||||
import org.lwjgl.BufferUtils
|
import org.lwjgl.BufferUtils
|
||||||
@@ -178,13 +176,11 @@ open class SimpleTextTerminal(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
redrawSemaphore = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// cursor
|
// cursor
|
||||||
/*if (cursorBlinkOn) {
|
if (cursorBlinkOn) {
|
||||||
g.color = getColor(if (cursorBlink) foreDefault else backDefault)
|
g.color = getColor(if (cursorBlink) foreDefault else backDefault) screen colourScreen mul phosphor
|
||||||
|
|
||||||
g.fillRect(
|
g.fillRect(
|
||||||
fontW * cursorX.toFloat() + borderSize,
|
fontW * cursorX.toFloat() + borderSize,
|
||||||
@@ -192,8 +188,40 @@ open class SimpleTextTerminal(
|
|||||||
fontW.toFloat(),
|
fontW.toFloat(),
|
||||||
fontH.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()
|
blendNormal()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user