Skip to content

Commit

Permalink
fix(star): ensure stars are rendered with default white color
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
AdrienBousquieEPFL committed Dec 16, 2024
1 parent 276db10 commit c1d333f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit c1d333f

Please sign in to comment.