mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 12:04:06 +09:00
tiling using shader, sorta works
This commit is contained in:
@@ -8,6 +8,7 @@ import com.badlogic.gdx.graphics.*
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
||||
import net.torvald.terrarum.gameactors.ceilInt
|
||||
import net.torvald.terrarum.worlddrawer.BlocksDrawer
|
||||
import net.torvald.terrarumsansbitmap.gdx.GameFontBase
|
||||
|
||||
/**
|
||||
@@ -40,13 +41,15 @@ object GlslTilingTest : ApplicationAdapter() {
|
||||
val TILE_SIZE = 16
|
||||
|
||||
|
||||
lateinit var tilesBuffer: FloatArray
|
||||
lateinit var tilesBuffer: Pixmap
|
||||
|
||||
lateinit var tileAtlas: Texture
|
||||
|
||||
|
||||
override fun create() {
|
||||
ShaderProgram.pedantic = false
|
||||
|
||||
shader = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/loadingCircle.frag"))
|
||||
shader = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/tiling.frag"))
|
||||
|
||||
|
||||
font = GameFontBase("assets/graphics/fonts/terrarum-sans-bitmap", flipY = false)
|
||||
@@ -54,6 +57,10 @@ object GlslTilingTest : ApplicationAdapter() {
|
||||
|
||||
if (!shader.isCompiled) {
|
||||
Gdx.app.log("Shader", shader.log)
|
||||
|
||||
//ErrorDisp.title = "Error in shader ${shader.vertexShaderSource}"
|
||||
//ErrorDisp.text = shader.log.split('\n')
|
||||
//TerrarumAppLoader.getINSTANCE().setScreen(ErrorDisp)
|
||||
System.exit(1)
|
||||
}
|
||||
|
||||
@@ -70,15 +77,15 @@ object GlslTilingTest : ApplicationAdapter() {
|
||||
)
|
||||
|
||||
tilesQuad.setVertices(floatArrayOf(
|
||||
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, tilesInVertical,
|
||||
Gdx.graphics.width.toFloat(), 0f, 0f, 1f, 1f, 1f, 1f, tilesInHorizontal, tilesInVertical,
|
||||
Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat(), 0f, 1f, 1f, 1f, 1f, tilesInHorizontal, 0f,
|
||||
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f,
|
||||
Gdx.graphics.width.toFloat(), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
|
||||
Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat(), 0f, 1f, 1f, 1f, 1f, 1f, 0f,
|
||||
0f, Gdx.graphics.height.toFloat(), 0f, 1f, 1f, 1f, 1f, 0f, 0f
|
||||
))
|
||||
tilesQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
|
||||
|
||||
|
||||
tilesBuffer = FloatArray(tilesInHorizontal.ceilInt() * tilesInVertical.ceilInt())
|
||||
tilesBuffer = Pixmap(tilesInHorizontal.ceilInt(), tilesInVertical.ceilInt(), Pixmap.Format.RGBA8888)
|
||||
|
||||
|
||||
camera = OrthographicCamera(Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat())
|
||||
@@ -89,39 +96,50 @@ object GlslTilingTest : ApplicationAdapter() {
|
||||
batch = SpriteBatch()
|
||||
|
||||
fucktex = Texture(Gdx.files.internal("assets/graphics/ortho_line_tex_2px.tga"))
|
||||
|
||||
tileAtlas = Texture(Gdx.files.internal("assets/terrain.tga"))//BlocksDrawer.tilesTerrain.texture
|
||||
|
||||
|
||||
|
||||
println(tilesBuffer.format)
|
||||
// 0brrrrrrrr_gggggggg_bbbbbbbb_aaaaaaaa
|
||||
for (x in 0 until tilesBuffer.width * tilesBuffer.height) {
|
||||
val color = Color(0f, 1f/16f, 0f, 1f)
|
||||
tilesBuffer.drawPixel(x / tilesBuffer.width, x % tilesBuffer.width, 0x00ff00ff)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun render() {
|
||||
Gdx.graphics.setTitle("ShitOnGlsl — F: ${Gdx.graphics.framesPerSecond}")
|
||||
Gdx.graphics.setTitle("GlslTilingTest — F: ${Gdx.graphics.framesPerSecond}")
|
||||
|
||||
Gdx.gl.glClearColor(.094f, .094f, .094f, 0f)
|
||||
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight())
|
||||
Gdx.gl.glClearColor(0f, 0f, 0f, 1f)
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
|
||||
Gdx.gl.glEnable(GL20.GL_TEXTURE_2D)
|
||||
Gdx.gl.glEnable(GL20.GL_BLEND)
|
||||
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)
|
||||
|
||||
val tilesInHorizontal = Gdx.graphics.width.toFloat() / TILE_SIZE
|
||||
val tilesInVertical = Gdx.graphics.height.toFloat() / TILE_SIZE
|
||||
|
||||
|
||||
|
||||
batch.inUse {
|
||||
val tilesBufferAsTex = Texture(tilesBuffer)
|
||||
tilesBufferAsTex.bind(2)
|
||||
tileAtlas.bind(1) // for some fuck reason, it must be bound as last
|
||||
|
||||
batch.shader = shader
|
||||
|
||||
shader.setUniformMatrix("u_projTrans", camera.combined)
|
||||
shader.setUniformi("u_texture", 0)
|
||||
shader.setUniform1fv("tilesBuffer", tilesBuffer, 0, tilesBuffer.size)
|
||||
//tilesQuad.render(shader, GL20.GL_TRIANGLES)
|
||||
|
||||
batch.draw(fucktex, 0f, 0f, Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat())
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*shader.begin()
|
||||
shader.setUniformMatrix("u_projTrans", batch.projectionMatrix)
|
||||
shader.setUniformi("u_texture", 0)
|
||||
shader.setUniformf("circleCentrePoint", Gdx.graphics.width / 2f, Gdx.graphics.height / 2f)
|
||||
shader.setUniformf("colorCentrePoint", Gdx.graphics.width / 2f, Gdx.graphics.height / 2f)
|
||||
shader.setUniformf("circleSize", 200f)
|
||||
shader.begin()
|
||||
shader.setUniformMatrix("u_projTrans", batch.projectionMatrix)//camera.combined)
|
||||
shader.setUniformi("tilesAtlas", 1)
|
||||
shader.setUniformi("tilemap", 2)
|
||||
shader.setUniformf("tilemapSize", tilesBuffer.width.toFloat(), tilesBuffer.height.toFloat())
|
||||
shader.setUniformf("tileInDim", tilesInHorizontal, tilesInVertical)
|
||||
shader.setUniformf("cameraTranslation", 4f, 1f)
|
||||
tilesQuad.render(shader, GL20.GL_TRIANGLES)
|
||||
shader.end()*/
|
||||
shader.end()
|
||||
tilesBufferAsTex.dispose()
|
||||
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
|
||||
Reference in New Issue
Block a user