From c1d333f2e9dd60146d63cc4bfca866842fd33e25 Mon Sep 17 00:00:00 2001 From: Adrien Bousquie Date: Mon, 16 Dec 2024 18:00:32 +0100 Subject: [PATCH] fix(star): ensure stars are rendered with default white color Updated `Star.kt` to set a default white color (`intArrayOf(255, 255, 255, 255)`) for stars. Refactored `CircleRenderer.kt` to align with the updated color handling logic using `IntArray`. --- .../model/map/renderables/CircleRenderer.kt | 24 ++++++------------- .../lookup/model/map/renderables/Star.kt | 4 ++-- .../model/map/skybox/buffers/ColorBuffer.kt | 2 +- .../lookup/model/map/stars/StarsLoader.kt | 1 - 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/model/map/renderables/CircleRenderer.kt b/app/src/main/java/com/github/lookupgroup27/lookup/model/map/renderables/CircleRenderer.kt index 0d67b3fe3..6a67eb69c 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/model/map/renderables/CircleRenderer.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/model/map/renderables/CircleRenderer.kt @@ -13,15 +13,15 @@ import com.github.lookupgroup27.lookup.util.opengl.ShaderProgram /** * Renderer for creating circular 2D objects in an OpenGL environment. * - * @param segments Number of segments used to approximate the circle (default is 32) + * @param segments Number of segments used to approximate the circle (default is DEFAULT_SEGMENTS) * @param radius Radius of the circle (default is 1.0f) - * @param color Color of the circle as an integer (RGBA) + * @param color Color of the circle in RGBA format (range 0-255) (default is white) */ open class CircleRenderer( private val context: Context, private val segments: Int = DEFAULT_SEGMENTS, private val radius: Float = 1.0f, - private val color: FloatArray = floatArrayOf(1.0f, 1.0f, 1.0f, 1.0f) + private val color: IntArray = intArrayOf(255, 255, 255, 255) ) { /** Buffer for storing vertex positions. */ private val vertexBuffer = VertexBuffer() @@ -54,22 +54,12 @@ open class CircleRenderer( } // Add indices to the index buffer - for (index in geometryData.indices) { - indexBuffer.addIndex(index) - } - - // Convert float color to integer color for buffer - val colorInt = - ((color[3] * 255).toInt() shl - 24 or - (color[0] * 255).toInt() shl - 16 or - (color[1] * 255).toInt() shl - 8 or - (color[2] * 255).toInt()) + for (index in geometryData.indices) indexBuffer.addIndex(index) // Apply a single color for all vertices - repeat(geometryData.vertices.size / 3) { colorBuffer.addColor(colorInt) } + repeat(geometryData.vertices.size / 3) { + colorBuffer.addColor(color[3], color[0], color[1], color[2]) + } } /** Initializes shaders for rendering the circle. */ diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/model/map/renderables/Star.kt b/app/src/main/java/com/github/lookupgroup27/lookup/model/map/renderables/Star.kt index 45410c038..9ce843da8 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/model/map/renderables/Star.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/model/map/renderables/Star.kt @@ -9,14 +9,14 @@ import com.github.lookupgroup27.lookup.model.map.Camera * * @param context The Android context for resource management * @param position The x, y, z coordinates of the star - * @param color The color of the star, specified as an RGBA float array + * @param color The color of the star, specified as an RGBA array (range 0-255) (default is white) * @param size The size of the star (scale factor for its radius) * @param segments The number of segments used to approximate the circle (default is 32) */ class Star( val context: Context, val position: FloatArray, - val color: FloatArray, + val color: IntArray = intArrayOf(255, 255, 255, 255), val size: Float = 0.5f, val segments: Int = CircleRenderer.DEFAULT_SEGMENTS ) : Object() { diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/model/map/skybox/buffers/ColorBuffer.kt b/app/src/main/java/com/github/lookupgroup27/lookup/model/map/skybox/buffers/ColorBuffer.kt index 4d42097a7..12c82e1ea 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/model/map/skybox/buffers/ColorBuffer.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/model/map/skybox/buffers/ColorBuffer.kt @@ -66,7 +66,7 @@ class ColorBuffer { COLORS_PER_VERTEX, GLES20.GL_UNSIGNED_BYTE, true, // Normalize the values to [0, 1] - COLORS_PER_VERTEX * Int.SIZE_BYTES, + 0, colorBuffer) } diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/model/map/stars/StarsLoader.kt b/app/src/main/java/com/github/lookupgroup27/lookup/model/map/stars/StarsLoader.kt index c6e2474f4..ffae05871 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/model/map/stars/StarsLoader.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/model/map/stars/StarsLoader.kt @@ -26,7 +26,6 @@ class StarsLoader(private val context: Context, private val repository: StarData Star( context = context, position = floatArrayOf(starData.x.toFloat(), starData.y.toFloat(), starData.z.toFloat()), - color = floatArrayOf(1.0f, 1.0f, 1.0f), size = 0.2f) } }