Kaynağa Gözat

Pixel union! :D

Florian DORMONT 10 yıl önce
ebeveyn
işleme
4853d5990f
2 değiştirilmiş dosya ile 29 ekleme ve 1 silme
  1. 27 0
      include/Graphics.h
  2. 2 1
      src/main.cpp

+ 27 - 0
include/Graphics.h

@@ -3,6 +3,33 @@
 
 namespace WalrusRPG{ namespace Graphics {
 
+
+	/*
+	 * Pixel structure
+	 * TODO?: Convert this into a class to hide value?
+	 */
+	union Pixel {
+		::uint16_t value;
+		struct {
+			unsigned r : 5;
+			unsigned g : 6;
+			unsigned b : 5;
+		};
+
+		Pixel(::uint8_t red, ::uint8_t green, ::uint8_t blue) : r(red>>3), g(green>>2), b(blue>>3) {
+
+		}
+
+		// Overloading (unsigned) typecast
+		operator ::uint16_t() {
+			return value;
+		}
+		Pixel& operator=(unsigned value) {
+			this->value = value;
+			return *this;
+		}
+	};
+
 	typedef struct Rect Rect_t;
 	struct Rect
 	{

+ 2 - 1
src/main.cpp

@@ -27,8 +27,9 @@ void map_loop(unsigned x, unsigned y, Map &map)
 		// Frameskip
 		if (timer_read(0) > loop_next)
 		{
+			Pixel pix(255, 255, 255);
 			// TODO?: Preset color macros/consts?
-			buffer_fill(0xff0000);
+			buffer_fill(pix);
 			map.render(camera, 1);
 			lcd_vsync();
 			buffer_swap();