Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate

Advertising

Mine
Wednesday, March 7th, 2007 at 6:00:32am UTC 

  1. //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
  2.  
  3. #include <GL/glut.h>    // Header File For The GLUT Library
  4. #include <GL/gl.h>      // Header File For The OpenGL32 Library
  5. #include <GL/glu.h>     // Header File For The GLu32 Library
  6. #include <gtk/gtk.h>
  7. #include <gdk-pixbuf/gdk-pixbuf.h>
  8. #include <unistd.h>     // needed to sleep
  9. #include <stdio.h>
  10. #include <iostream>
  11. #include <fstream>
  12. #include <string.h>
  13. #include <dirent.h>
  14. #include <sstream>
  15. #include <vector>
  16.  
  17. using namespace std;
  18.  
  19. class TextureLoader
  20. {
  21.         private:
  22.                 int idl, buffersize, tilesize;
  23.                 float nix, niy;
  24.                 GdkInterpType tilequality;
  25.                 string filename;
  26.                 bool closed;
  27.                 bool resize;
  28.                 GdkPixbufLoader *pixbuf;
  29.                 GdkPixbuf *pixbuf_new, *pixbuf_old;
  30.                 ifstream file;
  31.  
  32.         public:
  33.                 TextureLoader(string, int, int, int, GdkInterpType);
  34.                 bool next_chunk();
  35.                 GdkPixbuf* transfer(void);
  36.                 int get_width();
  37.                 int get_height();
  38. };
  39.  
  40. TextureLoader::TextureLoader(string in_filename, int in_idl, int in_buffersize, int in_tilesize, GdkInterpType in_tilequality)
  41. {
  42.         filename = in_filename;
  43.         idl = in_idl;
  44.         buffersize = in_buffersize;
  45.         tilesize = in_tilesize;
  46.         tilequality = in_tilequality;
  47.         closed = false;
  48.         resize = false;
  49.         pixbuf = gdk_pixbuf_loader_new();
  50.         pixbuf_new = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, tilesize, tilesize);
  51.         gdk_pixbuf_fill(pixbuf_new, 0x00000000);
  52.         file.open("/home/pete/NeHe.bmp", ios::in | ios::binary);
  53.         file.seekg(0, ios::beg);
  54. }
  55.  
  56. bool TextureLoader::next_chunk(void)
  57. {
  58.         float ix, iy;
  59.         char *buffer;
  60.  
  61.         buffer = new char [buffersize];
  62.  
  63.         if (!closed)
  64.         {
  65.                 if (file.eof())
  66.                 {
  67.                         gdk_pixbuf_loader_close(pixbuf, NULL);
  68.                         file.close();
  69.                         closed = true;
  70.                         pixbuf_old = gdk_pixbuf_loader_get_pixbuf(pixbuf);
  71.                         pixbuf_old = gdk_pixbuf_add_alpha(pixbuf_old, false, 'a', 'a', 'a');
  72.                         ix = gdk_pixbuf_get_width(pixbuf_old);
  73.                         iy = gdk_pixbuf_get_height(pixbuf_old);
  74.                         if (ix > iy)
  75.                         {
  76.                                 nix = tilesize - 4;
  77.                                 niy = (nix / ix) * iy;
  78.                         }
  79.                         else
  80.                         {
  81.                                 niy = tilesize - 4;
  82.                                 nix = (niy / iy) * ix;
  83.                         }
  84.                         return true;
  85.                 }
  86.  
  87.                 else
  88.                 {
  89.                 file.read(buffer, buffersize);
  90.                 gdk_pixbuf_loader_write(pixbuf, reinterpret_cast<const guchar*>(buffer), buffersize, NULL);
  91.                 return true;
  92.                 }
  93.         }
  94.         else if (!resize)
  95.         {
  96.                 pixbuf_old = gdk_pixbuf_scale_simple(pixbuf_old, (int)nix, (int)niy, tilequality);
  97.                 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));
  98.                 resize = true;
  99.         }
  100.         return false;
  101. }
  102.  
  103. GdkPixbuf* TextureLoader::transfer()
  104. {
  105.         return pixbuf_new;
  106. }
  107.  
  108. int TextureLoader::get_width()
  109. {
  110.         return (int)nix;
  111. }
  112.  
  113. int TextureLoader::get_height()
  114. {
  115.         return (int)niy;
  116. }
  117.  
  118. class phimage
  119. {
  120.  
  121. gint tilesize, tilequality, buffersize, blendtime, hangtime;
  122. guchar *dir, *resolution, *angle, *constraint, *speed, *distance, *perspective;
  123. gboolean window;
  124. GdkInterpType realtilequality;
  125. vector <string> files;
  126.  
  127.         public:
  128.                 phimage(int, char**);
  129.                 void init_options(int argc, char **argv);
  130.                 void check_options();
  131.                 void get_files();
  132. };
  133.  
  134. phimage::phimage(int argc, char **argv)
  135. {
  136.         this->check_options();
  137.         this->init_options(argc, argv);
  138.         this->get_files;
  139.         GdkPixbuf *man;
  140.  
  141.         gtk_init(&argc, &argv);
  142.  
  143.         ////Example for texture loader function
  144.         //TextureLoader test("/home/pete/NeHe.bmp", 0, 16384, 512, realtilequality);
  145.         //while (test.next_chunk());
  146.         //man = test.transfer();
  147.         //gdk_pixbuf_save(man, "/home/pete/opengl/test.png", "png", NULL, NULL);
  148.  
  149.         ////Example of float to string conversion
  150.         //float jim;
  151.         //string s = "33.2";
  152.         //std::istringstream i(s);
  153.         //i >> jim;
  154.         //cout << jim;
  155.  
  156. }
  157.  
  158. void phimage::get_files()
  159. {
  160.  
  161. }
  162.  
  163. void phimage::check_options()
  164. {
  165.         tilesize=512;
  166.         tilequality=1;
  167.         dir=(guchar *)".";
  168.         angle=(guchar *)"5";
  169.         buffersize=16384;
  170.         blendtime=300;
  171.         hangtime=100;
  172.         constraint=(guchar *)"0.5,0.5,30,30";
  173.         speed=(guchar *)"0.05,0.05";
  174.         resolution=(guchar *)"1024x768:8@75";
  175.         window=false;
  176.         distance=(guchar *)"2.5";
  177.         perspective=(guchar *)"45.0";
  178. }
  179.  
  180. void phimage::init_options(int argc, char **argv)
  181. {
  182. static GOptionEntry entries[] =
  183. {
  184.   { "tilesize", 't', 0, G_OPTION_ARG_INT, &tilesize, "Tile Size", "N" },
  185.   { "tilequality", 'q', 0, G_OPTION_ARG_INT, &tilequality, "Tile Quality", "M" },
  186.   { "dir", 'd', 0, G_OPTION_ARG_STRING, &dir, "Directory", NULL },
  187.   { "angle", 'a', 0, G_OPTION_ARG_STRING, &angle, "Angle", NULL },
  188.  
  189.   { "buffersize", 'b', 0, G_OPTION_ARG_INT, &buffersize, "Buffer Size", "N" },
  190.   { "blendtime", 'B', 0, G_OPTION_ARG_INT, &blendtime, "Blend Time", "M" },
  191.   { "hangtime", 'H', 0, G_OPTION_ARG_INT, &hangtime, "Hang Time", NULL },
  192.   { "constraint", 'c', 0, G_OPTION_ARG_STRING, &constraint, "Constraint", NULL },
  193.  
  194.   { "speed", 's', 0, G_OPTION_ARG_STRING, &speed, "Speed", "N" },
  195.   { "resolution", 'r', 0, G_OPTION_ARG_STRING, &resolution, "Resolution", "M" },
  196.   { "window", 'w', 0, G_OPTION_ARG_NONE, &window, "Window", NULL },
  197.   { "distance", 'D', 0, G_OPTION_ARG_STRING, &distance, "Distance", NULL },
  198.   { "perspective", 'p', 0, G_OPTION_ARG_STRING, &perspective, "Perspective", NULL },
  199.  
  200.   { NULL }
  201. };
  202.   GOptionContext *context;
  203.   context = g_option_context_new ("- test tree model performance");
  204.   g_option_context_add_main_entries (context, entries, NULL);
  205.   g_option_context_add_group (context, gtk_get_option_group (TRUE));
  206.   g_option_context_parse (context, &argc, &argv, NULL);
  207.  
  208. if (tilequality == 0) realtilequality = GDK_INTERP_NEAREST;
  209. else if (tilequality == 1) realtilequality = GDK_INTERP_BILINEAR;
  210. }
  211.  
  212. int main(int argc, char *argv[]) {
  213.  
  214. phimage main(argc, argv);
  215.  
  216.  
  217. //dir * = opendir("./");
  218.  
  219. }
  220.  
  221. //change the next line too (buffer=) new char, and then pass to pixbufloader reinterpret_cast<const guchar*>(buffer)

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right