Browse Source

Lesson 25.2

Godzil 3 years ago
parent
commit
65a081f69c
2 changed files with 18 additions and 9 deletions
  1. 10 3
      source/display.c
  2. 8 6
      source/main.c

+ 10 - 3
source/display.c

@@ -39,6 +39,8 @@ bool initialiseWindow(int32_t width, int32_t height, bool fullScreen)
 {
     bool ret = false;
     int windowFlags = 0;
+    int fullscreenWidth;
+    int fullscreenHeight;
 
     if (SDL_Init(SDL_INIT_EVERYTHING))
     {
@@ -64,13 +66,18 @@ bool initialiseWindow(int32_t width, int32_t height, bool fullScreen)
         SDL_DisplayMode displayMode;
         SDL_GetCurrentDisplayMode(0, &displayMode);
 
-        windowWidth = displayMode.w;
-        windowHeight = displayMode.h;
+        fullscreenWidth = displayMode.w;
+        fullscreenHeight = displayMode.h;
 
         windowFlags = SDL_WINDOW_BORDERLESS;
     }
+    else
+    {
+        fullscreenWidth = width * 4;
+        fullscreenHeight = height * 4;
+    }
 
-    window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight,
+    window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, fullscreenWidth, fullscreenHeight,
                               windowFlags);
     if (window == NULL)
     {

+ 8 - 6
source/main.c

@@ -78,7 +78,7 @@ void setup()
     vec3Normalize(&globalLight.direction);
 
     /* Load object */
-    loadOBJFile(&mesh,"assets/f117.obj");
+    loadOBJFile(&mesh,"assets/dragon.obj");
     //loadCubeMeshData(&mesh);
 
     /* Load texture */
@@ -133,8 +133,8 @@ void processInput()
             case SDLK_ESCAPE: isRunning = false; break;
             case SDLK_u: doNotCull = false; break;
             case SDLK_j: doNotCull = true; break;
-            case SDLK_i: doPerspectiveCorrection = false; break;
-            case SDLK_k: doPerspectiveCorrection = true; break;
+            case SDLK_k: doPerspectiveCorrection = false; break;
+            case SDLK_i: doPerspectiveCorrection = true; break;
             case SDLK_o: doZBuffer = true; break;
             case SDLK_l: doZBuffer = false; break;
             case SDLK_y: doClipping = true; break;
@@ -347,6 +347,8 @@ void render()
     clearFrameBuffer(MAKE_RGB(0, 0, 0));
     clearZBuffer();
 
+    drawGrid(20, MAKE_RGB(27, 2, 27));
+
     int triangleCount = arrayGetSize(projectedTriangles);
 
     for(i = 0; i < triangleCount; i++)
@@ -417,8 +419,8 @@ int main(int argc, char *argv[])
 
     Log(TLOG_ALWAYS, NULL, "Booting 3D Engine (version %s)!", VERSION);
 
-    windowWidth = 1024;
-    windowHeight = 768;
+    windowWidth = 320;
+    windowHeight = 240;
 
     for (param_i = 1 ; (param_i < argc) && (argv[param_i][0] == '-') ; param_i++)
     {
@@ -426,7 +428,7 @@ int main(int argc, char *argv[])
         {
         default: exit(-1); /* Option not recognized */
         case 'f': fullScreen = true; break;
-        case 'w': windowWidth = atoi(argv[++param_i]);
+        case 'w': windowWidth = atoi(argv[++param_i]); break;
         case 'h': windowHeight = atoi(argv[++param_i]); break;
 #ifdef DYNA_LOG_LEVEL
         case 'l': MAX_DEBUG_LEVEL = atoi(argv[++param_i]); break;