Skip to content

Instantly share code, notes, and snippets.

@dmitrykolesnikovich
Last active March 29, 2023 14:23
Show Gist options
  • Save dmitrykolesnikovich/dfd4dd485e2dab56b1e6da3ea8c5c301 to your computer and use it in GitHub Desktop.
Save dmitrykolesnikovich/dfd4dd485e2dab56b1e6da3ea8c5c301 to your computer and use it in GitHub Desktop.
featurea game engine minimalism demonstration
@file:Dependency("featurea:app:1.0")
@file:Dependency("featurea:graphics:1.0")
@file:Dependency("featurea:input:1.0")
@file:Dependency("featurea:pbr:1.0")
package game
import featurea.app.*
import featurea.graphics.*
import featurea.input.*
import featurea.pbr.*
import featurea.runtime.*
import featurea.utils.Color.orangeColor
val artifact = Artifact {
include(featurea.graphics.artifact)
include(featurea.input.artifact)
}
fun bootstrap(init: Runnable) = runApplication(include = game.artifact, init)
fun main() = bootstrap {
val app: Application = import()
val gl: Opengl = import()
val graphics: Graphics = import()
val loader: Loader = import()
app.delegate = ApplicationDelegate {
init {
loader.load(marioPng)
loader.load(pbrShader)
loader.load(simpleShader)
loader.load(sponzaGlb)
loader.load(quadIndices)
loader.load(quadVertices)
}
update {
graphics.clear(orangeColor)
// mario.png
graphics.drawImage(marioPng, x = 30, y = 30, width = 100, height = 100)
// simple.shader
gl.useProgram(simpleShader)
gl.useBuffer(quadVertices)
gl.uniforms["time"] = app.time
gl.drawTriangles(quadIndices)
// sponza.glb
gl.useProgram(pbrShader)
gl.drawModel(sponzaGlb)
}
}
}
/*content*/
const val marioPng = "https://images.com/mario.png"
const val sponzaGlb ="https://models.com/sponza.glb"
val quadVertices: VertexBuffer = VertexBuffer(
-1.0f, 1.0f,
-1.0f, -1.0f,
1.0f, -1.0f,
1.0f, 1.0f,
)
val quadIndices: IndexBuffer = IndexBuffer(
0, 1, 2,
1, 2, 3,
)
const val simpleShader: Program = Program("""
#shader vertex(vec2 position)
void main() {
outPosition = vec4(position, 0.0, 1.0)
}
#shader pixel
float time;
void main() {
outColor = vec4(0.2, sin(totalTime) * 0.5 + 0.5, 0.8, 1.0);
}
""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment