Browse Source

Lesson 21.2 && Lesson 21.3

Godzil 3 years ago
parent
commit
af988ad4c1
3 changed files with 63 additions and 4 deletions
  1. 5 1
      source/include/texture.h
  2. 10 3
      source/main.c
  3. 48 0
      source/texture.c

+ 5 - 1
source/include/texture.h

@@ -12,6 +12,8 @@
 
 #include <stdint.h>
 
+#include <upng.h>
+
 #include <display.h>
 
 /***********************************************************************************************************************
@@ -31,10 +33,12 @@ extern int textureHeight;
 extern const uint8_t REDBRICK_TEXTURE[];
 
 colour_t *meshTexture;
-
+extern upng_t *pngTexture;
 
 /***********************************************************************************************************************
  * Prototypes
  **********************************************************************************************************************/
+void loadTextureDateFromPng(const char *filepath);
+void textureCleanup();
 
 #endif /* THREEDENGINE_SOURCE_INCLUDE_TEXTURE_H */

+ 10 - 3
source/main.c

@@ -35,6 +35,7 @@ typedef enum displayMode_t
     DISPLAY_MODE_TEXTURED,
     DISPLAY_MODE_TEXTURED_WIRE,
 } displayMode_t;
+
 bool displayVertex = false;
 bool doNotCull = false;
 enum displayMode_t currentDisplayMode = DISPLAY_MODE_SOLID;
@@ -61,7 +62,7 @@ void setup()
         goto exit;
     }
 
-    frameBufferTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, windowWidth,
+    frameBufferTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STREAMING, windowWidth,
                                            windowHeight);
     if (frameBufferTexture == NULL)
     {
@@ -76,9 +77,14 @@ void setup()
     globalLight.direction.z = 1;
     vec3Normalize(&globalLight.direction);
 
-    meshTexture = (colour_t *)REDBRICK_TEXTURE;
 
-    //loadOBJFile("assets/f22.obj");
+    /* Load texture */
+    //meshTexture = (colour_t *)REDBRICK_TEXTURE;
+    loadTextureDateFromPng("assets/cube.png");
+
+
+    /* Load object */
+    //loadOBJFile("assets/cube.obj");
     loadCubeMeshData();
 
     trianglesTotal = arrayGetSize(mesh.faces);
@@ -397,6 +403,7 @@ no_more_params:
     }
 
     arrayFree(projectedTriangles);
+    textureCleanup();
     meshFree();
     destroyWindow();
 

File diff suppressed because it is too large
+ 48 - 0
source/texture.c


Some files were not shown because too many files changed in this diff