Browse Source

Make vc.c include olive.c for you

rexim 3 years ago
parent
commit
a94281face
4 changed files with 19 additions and 20 deletions
  1. 2 5
      demos/3d.c
  2. 2 6
      demos/squish.c
  3. 2 4
      demos/triangle.c
  4. 13 5
      demos/vc.c

+ 2 - 5
demos/3d.c

@@ -1,8 +1,8 @@
 // This example renders a rotating 3D cube made out of circles.
 // This example renders a rotating 3D cube made out of circles.
 // This idea is that you can take this code and compile it to different platforms with different rendering machanisms:
 // This idea is that you can take this code and compile it to different platforms with different rendering machanisms:
 // native with SDL, WebAssembly with HTML5 canvas, etc.
 // native with SDL, WebAssembly with HTML5 canvas, etc.
-#define OLIVEC_IMPLEMENTATION
-#include "olive.c"
+#define SCALE_DOWN_FACTOR 10
+#include "vc.c"
 
 
 float sqrtf(float x);
 float sqrtf(float x);
 float atan2f(float y, float x);
 float atan2f(float y, float x);
@@ -13,7 +13,6 @@ float cosf(float x);
 
 
 #define WIDTH 960
 #define WIDTH 960
 #define HEIGHT 720
 #define HEIGHT 720
-#define SCALE_DOWN_FACTOR 10
 #define BACKGROUND_COLOR 0xFF181818
 #define BACKGROUND_COLOR 0xFF181818
 #define GRID_COUNT 10
 #define GRID_COUNT 10
 #define GRID_PAD 0.5/GRID_COUNT
 #define GRID_PAD 0.5/GRID_COUNT
@@ -81,5 +80,3 @@ Olivec_Canvas render(float dt)
 
 
     return oc;
     return oc;
 }
 }
-
-#include "vc.c"

+ 2 - 6
demos/squish.c

@@ -1,11 +1,9 @@
-#define OLIVEC_IMPLEMENTATION
-#include "./olive.c"
-
+#define SCALE_DOWN_FACTOR 10
+#include "vc.c"
 #include "./assets/tsodinPog.c"
 #include "./assets/tsodinPog.c"
 
 
 #define WIDTH 960
 #define WIDTH 960
 #define HEIGHT 720
 #define HEIGHT 720
-#define SCALE_DOWN_FACTOR 10
 
 
 float sinf(float);
 float sinf(float);
 
 
@@ -34,5 +32,3 @@ Olivec_Canvas render(float dt)
 
 
     return dst_canvas;
     return dst_canvas;
 }
 }
-
-#include "vc.c"

+ 2 - 4
demos/triangle.c

@@ -1,12 +1,11 @@
 // This example renders a rotating triangle.
 // This example renders a rotating triangle.
 // This idea is that you can take this code and compile it to different platforms with different rendering machanisms:
 // This idea is that you can take this code and compile it to different platforms with different rendering machanisms:
 // native with SDL, WebAssembly with HTML5 canvas, etc.
 // native with SDL, WebAssembly with HTML5 canvas, etc.
-#define OLIVEC_IMPLEMENTATION
-#include "olive.c"
+#define SCALE_DOWN_FACTOR 20
+#include "vc.c"
 
 
 #define WIDTH 960
 #define WIDTH 960
 #define HEIGHT 720
 #define HEIGHT 720
-#define SCALE_DOWN_FACTOR 20
 #define BACKGROUND_COLOR 0xFF181818
 #define BACKGROUND_COLOR 0xFF181818
 #define CIRCLE_RADIUS 100
 #define CIRCLE_RADIUS 100
 #define CIRCLE_COLOR 0x99AA2020
 #define CIRCLE_COLOR 0x99AA2020
@@ -76,4 +75,3 @@ Olivec_Canvas render(float dt)
     return oc;
     return oc;
 }
 }
 
 
-#include "vc.c"

+ 13 - 5
demos/vc.c

@@ -3,6 +3,11 @@
 // # Usage
 // # Usage
 // ```c
 // ```c
 // // demo.c
 // // demo.c
+// // vc.c expectes render() to be defined and also supplies it's own entry point
+// // if needed (some platforms like WASM_PLATFORM do not have the main()
+// // entry point)
+// #include "vc.c"
+//
 // #define WIDTH 800
 // #define WIDTH 800
 // #define HEIGHT 600
 // #define HEIGHT 600
 // static uint32_t pixels[WIDTH*HEIGHT];
 // static uint32_t pixels[WIDTH*HEIGHT];
@@ -15,11 +20,6 @@
 //     // ...
 //     // ...
 //     return oc;
 //     return oc;
 // }
 // }
-//
-// // vc.c expectes render() to be defined an also supplies it's own entry point
-// // if needed (some platforms like WASM_PLATFORM do not have the main()
-// // entry point)
-// #include "vc.c"
 // ```
 // ```
 //
 //
 // # Build
 // # Build
@@ -29,14 +29,22 @@
 // $ clang -fno-builtin --target=wasm32 --no-standard-libraries -Wl,--no-entry -Wl,--export=render -Wl,--allow-undefined -o demo.wasm -DPLATFORM=WASM_PLATFORM demo.c
 // $ clang -fno-builtin --target=wasm32 --no-standard-libraries -Wl,--no-entry -Wl,--export=render -Wl,--allow-undefined -o demo.wasm -DPLATFORM=WASM_PLATFORM demo.c
 // ```
 // ```
 
 
+#define OLIVEC_IMPLEMENTATION
+#include <olive.c>
 
 
 // TODO: prefix VC api elements with vc_*
 // TODO: prefix VC api elements with vc_*
 // Like vc_render, VC_WASM_PLATFORM, VC_SCALE_DOWN_FACTOR, etc.
 // Like vc_render, VC_WASM_PLATFORM, VC_SCALE_DOWN_FACTOR, etc.
 
 
+Olivec_Canvas render(float dt);
+
 #define WASM_PLATFORM 0
 #define WASM_PLATFORM 0
 #define SDL_PLATFORM 1
 #define SDL_PLATFORM 1
 #define TERM_PLATFORM 2
 #define TERM_PLATFORM 2
 
 
+#ifndef PLATFORM
+#error "Please define PLATFORM macro"
+#endif
+
 #if PLATFORM == SDL_PLATFORM
 #if PLATFORM == SDL_PLATFORM
 #include <stdio.h>
 #include <stdio.h>
 #include <SDL2/SDL.h>
 #include <SDL2/SDL.h>