//gcc -Wall -I/usr/include -o phimage phimage.cpp `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0` -L/usr/X11R6/lib -lX11 -lglut -lGL -lGLU -lm #include // Header File For The GLUT Library #include // Header File For The OpenGL32 Library #include // Header File For The GLu32 Library //#include //#include #include // needed to sleep #include #include #include #include #include #include #include #include #include #include #include using namespace std; class TextureLoader { private: int idl, buffersize, tilesize; float nix, niy; GdkInterpType tilequality; string filename; bool closed; bool resize; GdkPixbufLoader *pixbuf; GdkPixbuf *pixbuf_new, *pixbuf_old; ifstream file; public: TextureLoader(string, int, int, int, GdkInterpType); bool next_chunk(); GdkPixbuf* transfer(void); int get_width(); int get_height(); }; TextureLoader::TextureLoader(string in_filename, int in_idl, int in_buffersize, int in_tilesize, GdkInterpType in_tilequality) { filename = in_filename; idl = in_idl; buffersize = in_buffersize; tilesize = in_tilesize; tilequality = in_tilequality; closed = false; resize = false; pixbuf = gdk_pixbuf_loader_new(); pixbuf_new = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, tilesize, tilesize); gdk_pixbuf_fill(pixbuf_new, 0x00000000); file.open("/home/pete/NeHe.bmp", ios::in | ios::binary); file.seekg(0, ios::beg); } bool TextureLoader::next_chunk(void) { float ix, iy; char *buffer; buffer = new char [buffersize]; if (!closed) { if (file.eof()) { gdk_pixbuf_loader_close(pixbuf, NULL); file.close(); closed = true; pixbuf_old = gdk_pixbuf_loader_get_pixbuf(pixbuf); pixbuf_old = gdk_pixbuf_add_alpha(pixbuf_old, false, 'a', 'a', 'a'); ix = gdk_pixbuf_get_width(pixbuf_old); iy = gdk_pixbuf_get_height(pixbuf_old); if (ix > iy) { nix = tilesize - 4; niy = (nix / ix) * iy; } else { niy = tilesize - 4; nix = (niy / iy) * ix; } return true; } else { file.read(buffer, buffersize); gdk_pixbuf_loader_write(pixbuf, reinterpret_cast(buffer), buffersize, NULL); return true; } } else if (!resize) { pixbuf_old = gdk_pixbuf_scale_simple(pixbuf_old, (int)nix, (int)niy, tilequality); gdk_pixbuf_copy_area(pixbuf_old, 0, 0, (int)nix, (int)niy, pixbuf_new, (int)(2+(tilesize - 4 - nix)/2), (int)(2+(tilesize - 4 - niy)/2)); resize = true; } return false; } GdkPixbuf* TextureLoader::transfer() { return pixbuf_new; } int TextureLoader::get_width() { return (int)nix; } int TextureLoader::get_height() { return (int)niy; } class phimage { gint tilesize, tilequality, buffersize, blendtime, hangtime; uint counter; char *dir, *resolution, *angle, *constraint, *speed, *o_distance, *o_perspective; float distance, perspective; gboolean window; GdkInterpType realtilequality; vector files; public: phimage(int, char**); void init_options(int argc, char **argv); void check_options(); void get_files(); Glib::OptionEntry entry(char short_name, const char* long_name, const char* description); Glib::ustring next_file(); vector split(char *); }; phimage::phimage(int argc, char **argv) { this->check_options(); this->init_options(argc, argv); this->get_files(); vector c_options = this->split(constraint); gtk_init(&argc, &argv); ////Example for texture loader function //GdkPixbuf *man; //TextureLoader test("/home/pete/NeHe.bmp", 0, 16384, 512, realtilequality); //while (test.next_chunk()); //man = test.transfer(); //gdk_pixbuf_save(man, "/home/pete/opengl/test.png", "png", NULL, NULL); ////Example of float to string conversion //float jim; //Glib::ustring s = "33.2"; //std::istringstream i(s); //i >> jim; //cout << jim; } void phimage::get_files() { DIR *pdir; struct dirent *pent; vector tmpfiles; pdir=opendir(reinterpret_cast(dir)); //"." refers to the current dir if (!pdir) { printf ("opendir() failure; terminating"); exit(1); } errno=0; while ((pent=readdir(pdir))) { tmpfiles.push_back(pent->d_name); } if (errno) { printf ("readdir() failure; terminating"); exit(1); } closedir(pdir); int size = tmpfiles.size(); int i; Glib::ustring tempString; for (i=0 ; i< size; i++) { tempString = tmpfiles[i].lowercase(); if (tempString.find(".jpg")!=string::npos || tempString.find(".png")!=string::npos || tempString.find(".bmp")!=string::npos) { files.push_back(tmpfiles[i]); } } } void phimage::check_options() { tilesize=512; tilequality=1; dir="."; angle="5"; buffersize=16384; blendtime=300; hangtime=100; constraint="0.5,0.5,30,30"; speed="0.05,0.05"; resolution="1024x768:8@75"; window=false; distance=2.5; perspective=45.0; } Glib::OptionEntry phimage::entry(char short_name, const char* long_name, const char* description) { Glib::OptionEntry ent1; ent1.set_short_name(short_name); ent1.set_long_name(long_name); ent1.set_description(description); return ent1; } void phimage::init_options(int argc, char **argv) { Glib::OptionContext test; Glib::OptionGroup idiot("example", "example", "example"); idiot.add_entry(this->entry('b',"buffersize","no"), buffersize); test.set_main_group(idiot); test.parse(argc, argv); cout << "test"; /* static GOptionEntry entries[] = { { "tilesize", 't', 0, G_OPTION_ARG_INT, &tilesize, "Tile Size", "N" }, { "tilequality", 'q', 0, G_OPTION_ARG_INT, &tilequality, "Tile Quality", "M" }, { "dir", 'd', 0, G_OPTION_ARG_STRING, &dir, "Directory", NULL }, { "angle", 'a', 0, G_OPTION_ARG_STRING, &angle, "Angle", NULL }, { "buffersize", 'b', 0, G_OPTION_ARG_INT, &buffersize, "Buffer Size", "N" }, { "blendtime", 'B', 0, G_OPTION_ARG_INT, &blendtime, "Blend Time", "M" }, { "hangtime", 'H', 0, G_OPTION_ARG_INT, &hangtime, "Hang Time", NULL }, { "constraint", 'c', 0, G_OPTION_ARG_STRING, &constraint, "Constraint", NULL }, { "speed", 's', 0, G_OPTION_ARG_STRING, &speed, "Speed", "N" }, { "resolution", 'r', 0, G_OPTION_ARG_STRING, &resolution, "Resolution", "M" }, { "window", 'w', 0, G_OPTION_ARG_NONE, &window, "Window", NULL }, { "distance", 'D', 0, G_OPTION_ARG_STRING, &o_distance, "Distance", NULL }, { "perspective", 'p', 0, G_OPTION_ARG_STRING, &o_perspective, "Perspective", NULL }, { NULL } }; GOptionContext *context; context = g_option_context_new ("- test tree model performance"); g_option_context_add_main_entries (context, entries, NULL); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, NULL); if (tilequality == 0) realtilequality = GDK_INTERP_NEAREST; else if (tilequality == 1) realtilequality = GDK_INTERP_BILINEAR; std::istringstream i(o_perspective); i >> perspective; std::istringstream w(o_distance); w >> distance; */ } Glib::ustring phimage::next_file() { counter++; if (counter >= files.size()) counter = 0; return files[counter]; } vector phimage::split(char *string) { vector tmp; Glib::ustring test = string; int flag = 0; while (test.find_first_of(",", flag)!=string::npos) { tmp.push_back(test.substr(flag, test.find_first_of(",", flag) - flag)); flag = test.find_first_of(",", flag) + 1; } tmp.push_back(test.substr(flag, string::npos)); return tmp; } int main(int argc, char *argv[]) { phimage main(argc, argv); //dir * = opendir("./"); } //change the next line too (buffer=) new char, and then pass to pixbufloader reinterpret_cast(buffer)