Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mi-sts committed Oct 22, 2023
1 parent 882f10d commit 669e389
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/solve/rendering/canvas/OpenGLCanvas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class OpenGLCanvas {
createCapabilities()
}

@Suppress("UNUSED_PARAMETER")
private fun render(event: GLRenderEvent) {
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LEQUAL)
Expand Down
3 changes: 0 additions & 3 deletions src/main/kotlin/solve/rendering/engine/components/Sprite.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class Sprite(val texture: Texture, uvCoordinates: List<Vector2f> = defaultUVCoor
}
}

fun setTexture(texture: Texture) {
}

companion object {
private const val UVCoordinatesNumber = 4
private val defaultUVCoordinates = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ open class RenderBatch(
}

fun addTexture(texture: Texture): Int {
var textureID = 0
val textureID: Int
if (textures.contains(texture)) {
textureID = textures.indexOf(texture) + 1
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import solve.rendering.engine.scene.GameObject
import solve.rendering.engine.shader.ShaderAttributeType
import solve.rendering.engine.shader.ShaderProgram
import solve.rendering.engine.shader.ShaderType
import solve.rendering.engine.utils.plus

class SpriteRenderer(
window: Window
Expand Down Expand Up @@ -68,10 +69,9 @@ class SpriteRenderer(
val uvCoordinates = sprite.uvCoordinates

spriteLocalVerticesPositions.forEachIndexed { index, vertexPosition ->
val scaledX = vertexPosition.x * scale.x
val scaleY = vertexPosition.y * scale.y
val scaleVector = Vector2f(vertexPosition.x * scale.x, vertexPosition.y * scale.y)

batch.pushVector2f(position)
batch.pushVector2f(position + scaleVector)
batch.pushVector4f(color.toVector4f())
batch.pushVector2f(uvCoordinates[index])
batch.pushInt(textureID)
Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/solve/rendering/engine/utils/StructuresUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ import org.joml.Vector2f
import org.joml.Vector3f
import org.joml.Vector4f

operator fun Vector2f.plus(otherVector: Vector2f) = Vector2f(x + otherVector.x, y + otherVector.y)
operator fun Vector3f.plus(otherVector: Vector3f) = Vector3f(x + otherVector.x, y + otherVector.y, z + otherVector.z)
operator fun Vector4f.plus(otherVector: Vector4f) =
Vector4f(x + otherVector.x, y + otherVector.y, z + otherVector.z, w + otherVector.w)

operator fun Vector2f.unaryMinus() = Vector2f(-x, -y)
operator fun Vector3f.unaryMinus() = Vector3f(-x, -y, -z)
operator fun Vector4f.unaryMinus() = Vector4f(-x, -y, -z, -w)

operator fun Vector2f.minus(otherVector: Vector2f) = this + (-otherVector)
operator fun Vector3f.minus(otherVector: Vector3f) = this + (-otherVector)
operator fun Vector4f.minus(otherVector: Vector4f) = this + (-otherVector)

fun Vector2f.toList() = listOf(x, y)

fun Vector3f.toList() = listOf(x, y, z)
Expand Down

0 comments on commit 669e389

Please sign in to comment.