Godzil před 3 roky
rodič
revize
c693983ea5
3 změnil soubory, kde provedl 27 přidání a 10 odebrání
  1. 11 6
      source/display.c
  2. 14 3
      source/include/display.h
  3. 2 1
      source/main.c

+ 11 - 6
source/display.c

@@ -95,6 +95,17 @@ void destroy_window()
     SDL_Quit();
 }
 
+void renderFrameBuffer()
+{
+    SDL_UpdateTexture(frameBufferTexture, NULL, frameBuffer, (uint32_t)(windowWidth * sizeof(uint32_t)));
+    SDL_RenderCopy(renderer, frameBufferTexture, NULL, NULL);
+}
+
+void drawPixel(uint32_t x, uint32_t y, uint32_t colour)
+{
+    frameBuffer[x + (y * windowWidth)] = colour;
+}
+
 void clearFrameBuffer(uint32_t colour)
 {
     int x, y;
@@ -133,10 +144,4 @@ void drawRectangle(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t colo
             frameBuffer[i + x + ((j + y) * windowWidth)] = colour;
         }
     }
-}
-
-void renderFrameBuffer()
-{
-    SDL_UpdateTexture(frameBufferTexture, NULL, frameBuffer, (uint32_t)(windowWidth * sizeof(uint32_t));
-    SDL_RenderCopy(renderer, frameBufferTexture, NULL, NULL);
 }

+ 14 - 3
source/include/display.h

@@ -12,6 +12,10 @@
 
 #include <SDL.h>
 
+/***********************************************************************************************************************
+ * Global variables
+ **********************************************************************************************************************/
+
 extern SDL_Window *window;
 extern SDL_Renderer *renderer;
 extern bool isRunning;
@@ -20,14 +24,21 @@ extern SDL_Texture *frameBufferTexture;
 extern int windowWidth;
 extern int windowHeight;
 
-//
+/***********************************************************************************************************************
+ * Prototypes
+ **********************************************************************************************************************/
 
+/* --- Window functions --- */
 bool initialiseWindow(bool fullScreen);
-
 void destroy_window();
+void renderFrameBuffer();
+
+/* --- Drawing functions --- */
+void drawPixel(uint32_t x, uint32_t y, uint32_t colour);
 
 void clearFrameBuffer(uint32_t colour);
 void drawGrid(int spacing, uint32_t colour);
 void drawRectangle(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t colour);
-void renderFrameBuffer();
+
+
 #endif /* THREEDENGINE_SOURCE_INCLUDE_DISPLAY_H */

+ 2 - 1
source/main.c

@@ -73,11 +73,12 @@ void render()
 
     drawGrid(100, 0xFF003353);
 
+    drawPixel(20, 20, 0xFFFF00FF);
     drawRectangle(100, 100, 50, 50, 0xFF9A2378);
 
     renderFrameBuffer();
     clearFrameBuffer(0xFF000000);
-    
+
     SDL_RenderPresent(renderer);
 }