summaryrefslogtreecommitdiffhomepage
path: root/src/rodeo_math.c
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2023-03-25 01:25:05 -0400
committerrealtradam <[email protected]>2023-03-25 01:25:05 -0400
commit2577adf913e292a4a515e7dfc4023e37e8177f46 (patch)
treeb6340f698487ae0dc25ffc9cfc521f8698f63c6c /src/rodeo_math.c
parentb2fdd29e4965b096e285a17162b268710077ea04 (diff)
downloadRodeoKit-2577adf913e292a4a515e7dfc4023e37e8177f46.tar.gz
RodeoKit-2577adf913e292a4a515e7dfc4023e37e8177f46.zip
progress on getting textures working
Diffstat (limited to 'src/rodeo_math.c')
-rw-r--r--src/rodeo_math.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/rodeo_math.c b/src/rodeo_math.c
index 4985cd1..6406f6a 100644
--- a/src/rodeo_math.c
+++ b/src/rodeo_math.c
@@ -5,12 +5,27 @@
// system
#include <stdint.h>
-uint32_t
-rodeo_rgba_to_uint32(const rodeo_rgba_t color)
+// when casting from float to int(example):
+// 20.50-21.00 rounds up to 21
+// 20.00-20.49 rounds down to 20
+rodeo_RGBA8_t
+rodeo_RGBAFloat_to_RGBA8(const rodeo_RGBAFloat_t color)
{
- return
- ((uint32_t)(uint8_t)(color.red * 255))
- | ((uint32_t)(uint8_t)(color.green * 255)) << (8 * 1)
- | ((uint32_t)(uint8_t)(color.blue * 255)) << (8 * 2)
- | ((uint32_t)(uint8_t)(color.alpha * 255)) << (8 * 3);
+ return (rodeo_RGBA8_t){
+ .red = (uint8_t)((color.red * (float)UINT8_MAX) + 0.5),
+ .green = (uint8_t)((color.green * (float)UINT8_MAX) + 0.5),
+ .blue = (uint8_t)((color.blue * (float)UINT8_MAX) + 0.5),
+ .alpha = (uint8_t)((color.alpha * (float)UINT8_MAX) + 0.5),
+ };
+}
+
+rodeo_BGRA8_t
+rodeo_RGBA8_to_BGRA8(const rodeo_RGBA8_t color)
+{
+ return (rodeo_BGRA8_t){
+ .alpha = color.alpha,
+ .blue = color.blue,
+ .green = color.green,
+ .red = color.red,
+ };
}