Browse Source

Add new colour_t type for colours instead of uint32_t.

Godzil 3 years ago
parent
commit
49c2617006
4 changed files with 27 additions and 21 deletions
  1. 7 7
      source/display.c
  2. 13 8
      source/include/display.h
  3. 3 2
      source/include/triangle.h
  4. 4 4
      source/triangle.c

+ 7 - 7
source/display.c

@@ -102,7 +102,7 @@ void renderFrameBuffer()
     SDL_RenderCopy(renderer, frameBufferTexture, NULL, NULL);
 }
 
-void drawPixel(int32_t x, int32_t y, uint32_t colour)
+void drawPixel(int32_t x, int32_t y, colour_t colour)
 {
     if ((x >= 0) && (x < windowWidth) && (y >= 0) && (y < windowHeight))
     {
@@ -110,7 +110,7 @@ void drawPixel(int32_t x, int32_t y, uint32_t colour)
     }
 }
 
-void drawVLine(int32_t x, int32_t y0, int32_t y1, uint32_t colour)
+void drawVLine(int32_t x, int32_t y0, int32_t y1, colour_t colour)
 {
     int32_t i;
     if (y0 > y1) {
@@ -134,7 +134,7 @@ void drawVLine(int32_t x, int32_t y0, int32_t y1, uint32_t colour)
     }
 }
 
-void drawHLine(int32_t x0, int32_t y, int32_t x1, uint32_t colour)
+void drawHLine(int32_t x0, int32_t y, int32_t x1, colour_t colour)
 {
     int32_t i;
     if (x0 > x1) {
@@ -158,7 +158,7 @@ void drawHLine(int32_t x0, int32_t y, int32_t x1, uint32_t colour)
     }
 }
 
-void clearFrameBuffer(int32_t colour)
+void clearFrameBuffer(colour_t colour)
 {
     int32_t x, y;
     for (y = 0 ; y < windowHeight ; y++)
@@ -170,7 +170,7 @@ void clearFrameBuffer(int32_t colour)
     }
 }
 
-void drawGrid(int spacing, uint32_t colour)
+void drawGrid(int spacing, colour_t colour)
 {
     int32_t x, y;
     for (y = 0 ; y < windowHeight ; y++)
@@ -185,7 +185,7 @@ void drawGrid(int spacing, uint32_t colour)
     }
 }
 
-void drawRectangle(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t colour)
+void drawRectangle(int32_t x, int32_t y, int32_t w, int32_t h, colour_t colour)
 {
     int32_t j;
 
@@ -196,7 +196,7 @@ void drawRectangle(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t colour)
 }
 
 /* FIXME: Some out of screen line may render weirdly. Will fix that later */
-void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t colour)
+void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, colour_t colour)
 {
     int i;
     int32_t deltaX = x1 - x0;

+ 13 - 8
source/include/display.h

@@ -13,6 +13,11 @@
 #include <stdbool.h>
 #include <SDL.h>
 
+/***********************************************************************************************************************
+ * Data types
+ **********************************************************************************************************************/
+typedef uint32_t colour_t;
+
 /***********************************************************************************************************************
  * Constants
  **********************************************************************************************************************/
@@ -40,14 +45,14 @@ void destroyWindow();
 void renderFrameBuffer();
 
 /* --- Drawing functions --- */
-void drawPixel(int32_t x, int32_t y, uint32_t colour);
-
-void clearFrameBuffer(int32_t colour);
-void drawGrid(int spacing, uint32_t colour);
-void drawRectangle(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t colour);
-void drawVLine(int32_t x, int32_t y0, int32_t y1, uint32_t colour);
-void drawHLine(int32_t x0, int32_t y, int32_t x1, uint32_t colour);
-void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t colour);
+void drawPixel(int32_t x, int32_t y, colour_t colour);
+
+void clearFrameBuffer(colour_t colour);
+void drawGrid(int spacing, colour_t colour);
+void drawRectangle(int32_t x, int32_t y, int32_t w, int32_t h, colour_t colour);
+void drawVLine(int32_t x, int32_t y0, int32_t y1, colour_t colour);
+void drawHLine(int32_t x0, int32_t y, int32_t x1, colour_t colour);
+void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, colour_t colour);
 
 static inline void intSwap(int *a, int *b)
 {

+ 3 - 2
source/include/triangle.h

@@ -11,6 +11,7 @@
 #define THREEDENGINE_SOURCE_INCLUDE_TRIANGLE_H
 
 #include <stdint.h>
+#include <display.h>
 #include <vector.h>
 
 /***********************************************************************************************************************
@@ -30,7 +31,7 @@ typedef struct triangle_t
 /***********************************************************************************************************************
  * Prototypes
  **********************************************************************************************************************/
-void drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t colour);
-void drawFilledTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t colour);
+void drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, colour_t colour);
+void drawFilledTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, colour_t colour);
 
 #endif /* THREEDENGINE_SOURCE_INCLUDE_TRIANGLE_H */

+ 4 - 4
source/triangle.c

@@ -10,7 +10,7 @@
 #include <display.h>
 #include <triangle.h>
 
-void drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t colour)
+void drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, colour_t colour)
 {
     drawLine(x0, y0, x1, y1, colour);
     drawLine(x1, y1, x2, y2, colour);
@@ -18,7 +18,7 @@ void drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, in
 }
 
 /* This function expect Point 0 to be the top, 1 to be the bottom left, 2 to be the bottom right */
-static void drawFillBottomFlatTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t colour)
+static void drawFillBottomFlatTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, colour_t colour)
 {
     int i;
     int32_t deltaXL = x1 - x0;
@@ -44,7 +44,7 @@ static void drawFillBottomFlatTriangle(int32_t x0, int32_t y0, int32_t x1, int32
 }
 
 /* This function expect Point 2 to be the bottom, 0 to be the top left, 1 to be the top right */
-static void drawFillTopFlatTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t colour)
+static void drawFillTopFlatTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, colour_t colour)
 {
     int i;
     int32_t deltaXL = x0 - x2;
@@ -74,7 +74,7 @@ static void drawFillTopFlatTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t
     }
 }
 
-void drawFilledTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t colour)
+void drawFilledTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, colour_t colour)
 {
     int32_t My, Mx;
     if (y0 > y1)