]> git.sesse.net Git - movit/blobdiff - demo.cpp
Allow data files to be fetched somewhere else than the current directory.
[movit] / demo.cpp
index 0cc3c48a4fedac0375ca12736be807d14cc3e752..f5434cc1dd5d40f293bd9b9ec2d5c21534e9b812 100644 (file)
--- a/demo.cpp
+++ b/demo.cpp
 #include <vector>
 #include <map>
 
+#include <GL/glew.h>
+
 #include <SDL/SDL.h>
 #include <SDL/SDL_opengl.h>
 #include <SDL/SDL_image.h>
 
+#include "init.h"
 #include "effect.h"
 #include "effect_chain.h"
 #include "util.h"
-#include "opengl.h"
 #include "widgets.h"
 
 #include "flat_input.h"
@@ -144,7 +146,7 @@ void write_ppm(const char *filename, unsigned char *screenbuf)
 
 int main(int argc, char **argv)
 {
-       int quit = 0;
+       bool quit = false;
 
        SDL_Init(SDL_INIT_EVERYTHING);
        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
@@ -152,14 +154,16 @@ int main(int argc, char **argv)
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
        SDL_SetVideoMode(WIDTH, HEIGHT, 0, SDL_OPENGL);
        SDL_WM_SetCaption("OpenGL window", NULL);
-       
-       // geez 
-       glPixelStorei(GL_PACK_ALIGNMENT, 1);
 
+       init_movit(".");
+       printf("GPU texture subpixel precision: about %.1f bits\n",
+               log2(1.0f / movit_texel_subpixel_precision));
+       
        unsigned img_w, img_h;
-       unsigned char *src_img = load_image("blg_wheels_woman_1.jpg", &img_w, &img_h);
+       unsigned char *src_img = load_image(argc > 1 ? argv[1] : "blg_wheels_woman_1.jpg", &img_w, &img_h);
 
        EffectChain chain(WIDTH, HEIGHT);
+       glViewport(0, 0, WIDTH, HEIGHT);
 
        ImageFormat inout_format;
        inout_format.color_space = COLORSPACE_sRGB;
@@ -175,6 +179,7 @@ int main(int argc, char **argv)
        //sandbox_effect->set_float("parm", 42.0f);
        //chain.add_effect(new MirrorEffect());
        chain.add_output(inout_format);
+       chain.set_dither_bits(8);
        chain.finalize();
 
        // generate a PBO to hold the data we read back with glReadPixels()
@@ -186,7 +191,8 @@ int main(int argc, char **argv)
 
        make_hsv_wheel_texture();
 
-       int frame = 0, screenshot = 0;
+       int frame = 0;
+       bool screenshot = false;
 #if _POSIX_C_SOURCE >= 199309L
        struct timespec start, now;
        clock_gettime(CLOCK_MONOTONIC, &start);
@@ -199,11 +205,11 @@ int main(int argc, char **argv)
                SDL_Event event;
                while (SDL_PollEvent(&event)) {
                        if (event.type == SDL_QUIT) {
-                               quit = 1;
+                               quit = true;
                        } else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) {
-                               quit = 1;
+                               quit = true;
                        } else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_F1) {
-                               screenshot = 1;
+                               screenshot = true;
                        } else if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) {
                                mouse(event.button.x, event.button.y);
                        } else if (event.type == SDL_MOUSEMOTION && (event.motion.state & SDL_BUTTON(1))) {
@@ -218,8 +224,8 @@ int main(int argc, char **argv)
                //vignette_effect->set_float("inner_radius", inner_radius);
                //vignette_effect->set_vec2("center", (float[]){ 0.7f, 0.5f });
 
-               diffusion_effect->set_float("radius", blur_radius);
-               diffusion_effect->set_float("blurred_mix_amount", blurred_mix_amount);
+               CHECK(diffusion_effect->set_float("radius", blur_radius));
+               CHECK(diffusion_effect->set_float("blurred_mix_amount", blurred_mix_amount));
 
                input->set_pixel_data(src_img);
                chain.render_to_screen();
@@ -255,7 +261,7 @@ int main(int argc, char **argv)
                        sprintf(filename, "frame%05d.ppm", frame);
                        write_ppm(filename, screenbuf);
                        printf("Screenshot: %s\n", filename);
-                       screenshot = 0;
+                       screenshot = false;
                }
                glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB);
                check_error();