SDL_SetVideoMode(WIDTH, HEIGHT, 0, SDL_OPENGL);
SDL_WM_SetCaption("OpenGL window", NULL);
- init_movit();
+ init_movit(".");
printf("GPU texture subpixel precision: about %.1f bits\n",
log2(1.0f / movit_texel_subpixel_precision));
#include <GL/glew.h>
+#include <string>
#include "init.h"
#include "util.h"
float movit_texel_subpixel_precision;
bool movit_srgb_textures_supported;
+// The rules for objects with nontrivial constructors in static scope
+// are somewhat convoluted, and easy to mess up. We simply have a
+// pointer instead (and never care to clean it up).
+std::string *movit_data_directory = NULL;
+
namespace {
void measure_texel_subpixel_precision()
} // namespace
-void init_movit()
+void init_movit(const std::string& data_directory)
{
if (movit_initialized) {
return;
}
+ movit_data_directory = new std::string(data_directory);
+
glewInit();
// geez
#ifndef _INIT_H
#define _INIT_H
+#include <string>
+
// Initialize the library; in particular, will query the GPU for information
// that is needed by various components. For instance, it verifies that
// we have all the OpenGL extensions we need.
-void init_movit();
+//
+// The parameter gives which directory to read .frag files from.
+// This is a temporary hack until we add something more solid.
+// If you call init_movit() twice with different values for data_directory,
+// only the first will count.
+void init_movit(const std::string& data_directory);
// GPU features. These are not intended for end-user use.
GLenum framebuffer_format)
: chain(width, height), width(width), height(height), finalized(false)
{
- init_movit();
+ init_movit(".");
if (data != NULL) {
add_input(data, pixel_format, color_space, gamma_curve);
#include "util.h"
#include "init.h"
+extern std::string *movit_data_directory;
+
void hsv2rgb(float h, float s, float v, float *r, float *g, float *b)
{
if (h < 0.0f) {
std::string read_file(const std::string &filename)
{
+ const std::string full_pathname = *movit_data_directory + "/" + filename;
+
static char buf[131072];
- FILE *fp = fopen(filename.c_str(), "r");
+ FILE *fp = fopen(full_pathname.c_str(), "r");
if (fp == NULL) {
- perror(filename.c_str());
+ perror(full_pathname.c_str());
exit(1);
}