fun drawRect(matrices: MatrixStack, x: Float, y: Float, w: Float, h: Float, vararg colors: Color) {
val matrix = matrices.peek().positionMatrix
setupRender()
RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR)
val buffer = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR)
if (colors.size == 1) setupRect(buffer, matrix, x, y, w, h, colors.first())
else setupRect(buffer, matrix, x, y, w, h, colors[0], colors[1], colors[2], colors[3])
BufferRenderer.drawWithGlobalProgram(buffer.end())
endRender()
}
private fun setupRect(
buffer: BufferBuilder,
matrix: Matrix4f,
x: Float,
y: Float,
w: Float,
h: Float,
color1: Color,
color2: Color = color1,
color3: Color = color2,
color4: Color = color3,
) = buffer.vertex(matrix, x, y + h, 0.0f).color(color1.rgb)
.vertex(matrix, x + w, y + h, 0.0f).color(color2.rgb)
.vertex(matrix, x + w, y, 0.0f).color(color3.rgb)
.vertex(matrix, x, y, 0.0f).color(color4.rgb)