added two new global pointers in demo.h: vmem_back and vmem_front, and
[dosdemo] / src / grise.c
index fcee596..2aaf925 100644 (file)
@@ -10,6 +10,7 @@
 /* APPROX. 170 FPS Minimum */
 
 #define BG_FILENAME "data/grise.png"
+#define GROBJ_01_FILENAME "data/grobj_01.png"
 
 #define BB_SIZE 512    /* Let's use a power of 2. Maybe we'll zoom/rotate the effect */
 
@@ -30,7 +31,7 @@
 static int init(void);
 static void destroy(void);
 static void start(long trans_time);
-static void stop(long trans_time);
+/*static void stop(long trans_time);*/
 static void draw(void);
 
 static void convert32To16(unsigned int *src32, unsigned short *dst16, unsigned int pixelCount);
@@ -38,9 +39,11 @@ static void processNormal();
 static void initScrollTables();
 static void updateScrollTables(float dt);
 
+static void rleEncode(unsigned char *pixels, unsigned int w, unsigned int h);
+
 static unsigned short *background = 0;
-static unsigned int backgroundW = 0;
-static unsigned int backgroundH = 0;
+static int backgroundW = 0;
+static int backgroundH = 0;
 
 static unsigned int lastFrameTime = 0;
 static float lastFrameDuration = 0.0f;
@@ -60,7 +63,7 @@ static struct screen scr = {
        init,
        destroy,
        start,
-       stop,
+       0,
        draw
 };
 
@@ -72,9 +75,13 @@ struct screen *grise_screen(void)
 
 static int init(void)
 {
+       unsigned char *reflectedObject;
+       int reflectedObjectW, reflectedObjectH;
+
        /* Allocate back buffer */
        backBuffer = (unsigned short*) malloc(BB_SIZE * BB_SIZE * sizeof(unsigned short));
 
+       /* grise.png contains the background (horizon), baked reflection and normalmap for displacement */
        if (!(background = img_load_pixels(BG_FILENAME, &backgroundW, &backgroundH, IMG_FMT_RGBA32))) {
                fprintf(stderr, "failed to load image " BG_FILENAME "\n");
                return -1;
@@ -83,6 +90,16 @@ static int init(void)
        /* Convert to 16bpp */
        convert32To16((unsigned int*)background, background, backgroundW * NORMALMAP_SCANLINE); /* Normalmap will keep its 32 bit color */
 
+       /* Load reflected objects */
+       if (!(reflectedObject = img_load_pixels(GROBJ_01_FILENAME, &reflectedObjectW, &reflectedObjectH, IMG_FMT_GREY8))) {
+               fprintf(stderr, "failed to load image " GROBJ_01_FILENAME "\n");
+               return -1;
+       }
+
+       rleEncode(reflectedObject, reflectedObjectW, reflectedObjectH);
+
+       img_free_pixels(reflectedObject);
+
        initScrollTables();
 
        processNormal();
@@ -107,12 +124,17 @@ static void start(long trans_time)
        lastFrameTime = time_msec;
 }
 
+/* XXX add the stop function when you have an out-transition, otherwise
+ * it just delays the change to the next effect.
+ */
+/*
 static void stop(long trans_time)
 {
 }
+*/
 
 static void draw(void)
-{      
+{
        int scroll = MIN_SCROLL + (MAX_SCROLL - MIN_SCROLL) * mouse_x / fb_width;
        unsigned short *dst = backBuffer + PIXEL_PADDING;
        unsigned short *src = background + scroll;
@@ -130,7 +152,7 @@ static void draw(void)
                src += backgroundW;
                dst += BB_SIZE;
        }
-       
+
        /* Create scroll opffsets for all scanlines of the normalmap */
        updateScrollTables(lastFrameDuration);
 
@@ -156,6 +178,8 @@ static void draw(void)
                src += BB_SIZE;
                dst += fb_width;
        }
+
+       swap_buffers(fb_pixels);
 }
 
 /* src and dst can be the same */
@@ -237,7 +261,7 @@ static void initScrollTables() {
 
 static void updateScrollTables(float dt) {
        int i = 0;
-       
+
        nearScrollAmount += dt * NEAR_SCROLL_SPEED;
        nearScrollAmount = (float) fmod(nearScrollAmount, 512.0f);
 
@@ -246,3 +270,17 @@ static void updateScrollTables(float dt) {
                scrollTableRounded[i] = (int)(scrollTable[i] + 0.5f) % scrollModTable[i];
        }
 }
+
+static void rleEncode(unsigned char *pixels, unsigned int w, unsigned int h) {
+       int scanline;
+       int i;
+       int skipping = 1;
+
+       for (scanline = 0; scanline < h; scanline++) {
+               for (i = 0; i < w; i++) {
+                       if (*pixels++) {
+
+                       }
+               }
+       }
+}