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

Advertising

Anonymous
Monday, March 5th, 2007 at 3:44:36pm 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.  
  14. using namespace std;
  15.  
  16. class TextureLoader
  17. {
  18.         private:
  19.         int idl, buffersize, tilesize;
  20.         float nix, niy;
  21.         bool tilequality;
  22.         string filename;
  23.         bool closed;
  24.         bool resize;
  25.         GdkPixbufLoader *pixbuf;
  26.         GdkPixbuf *pixbuf_new, *pixbuf_old;
  27.         ifstream file;
  28.         public:
  29.                 TextureLoader(string, int, int, int, bool);
  30.                 bool next_chunk();
  31.                 GdkPixbuf* transfer();
  32.                 int get_width();
  33.                 int get_height();
  34. };
  35.  
  36. TextureLoader::TextureLoader(string in_filename, int in_idl, int in_buffersize, int in_tilesize, bool in_tilequality)
  37. {
  38.         filename = in_filename;
  39.         idl = in_idl;
  40.         buffersize = in_buffersize;
  41.         tilesize = in_tilesize;
  42.         tilequality = in_tilequality;
  43.         closed = false;
  44.         resize = false;
  45.         pixbuf = gdk_pixbuf_loader_new();
  46.         pixbuf_new = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, tilesize, tilesize);
  47.         gdk_pixbuf_fill(pixbuf_new, 0x00000000);
  48.         ifstream file ("/home/pete/NeHe.bmp", ios::in | ios::binary);
  49.         file.seekg(0, ios::beg);
  50.  
  51.         char *buffer;
  52.         buffer = new char [16];
  53.         file.read(buffer, 16);
  54.         cout << file.fail();
  55.         cout << file.tellg();
  56.         cout << file.eof();
  57. }
  58. bool TextureLoader::next_chunk()
  59. {
  60.         float ix, iy;
  61.         char *buffer;
  62.         int size;
  63.         GError *error;
  64.  
  65.         size = 16;
  66.         buffer = new char [size];
  67.  
  68.         cout << file.is_open();
  69.         cout << "r";
  70.  
  71.         if (!closed)
  72.         {
  73.                 cout << file.eof();
  74.                 if (file.eof())
  75.                 {
  76.                         bool idiot;
  77.                         cout << "!!!!!!!!!!!passed";
  78.                         idiot = gdk_pixbuf_loader_close(pixbuf, &error);
  79.                         cout << error->message;
  80.                         cout << idiot;
  81.                         file.close();
  82.                         closed = true;
  83.                         pixbuf_old = gdk_pixbuf_loader_get_pixbuf(pixbuf);
  84.                         //gdk_pixbuf_save(pixbuf_old, "/home/pete/opengl/test2.png", "png", NULL, NULL);
  85.                         pixbuf_old = gdk_pixbuf_add_alpha(pixbuf_old, false, 'a', 'a', 'a');
  86.                         ix = gdk_pixbuf_get_width(pixbuf_old);
  87.                         iy = gdk_pixbuf_get_height(pixbuf_old);
  88.                         if (ix > iy)
  89.                         {
  90.                                 nix = tilesize - 4;
  91.                                 niy = (nix / ix) * iy;
  92.                         }
  93.                         else
  94.                         {
  95.                                 niy = tilesize - 4;
  96.                                 nix = (niy / iy) * ix;
  97.                         }
  98.                         return false;
  99.                 }
  100.  
  101.                 else
  102.                 {
  103.                 cout << "Reading";
  104.                 cout << size;
  105.                 cout << file.good();
  106.                 file.read (buffer, size);
  107.                 cout << file.good();
  108.                 //cout << buffer;
  109.                 gdk_pixbuf_loader_write(pixbuf, reinterpret_cast<const guchar*>(buffer), size, NULL);
  110.                 cout << file.fail();
  111.                 cout << file.tellg();
  112.                 return true;
  113.                 }
  114.         }
  115. //      return false;
  116. }
  117.  
  118. GdkPixbuf* TextureLoader::transfer()
  119. {
  120. //      gdk_pixbuf_save(pixbuf_old, "/home/pete/opengl/test2.png", "png", NULL, NULL);
  121.         return pixbuf_old;
  122. }
  123.  
  124. int TextureLoader::get_width()
  125. {
  126.         return (int)nix;
  127. }
  128.  
  129. int TextureLoader::get_height()
  130. {
  131.         return (int)niy;
  132. }
  133.  
  134.  
  135. int main(int argc, char *argv[]) {
  136. GdkPixbuf *man;
  137.  
  138. gtk_init(&argc, &argv);
  139. TextureLoader test("/home/pete/NeHe.bmp", 0, 16000000, 512, 1);
  140. //while (test.next_chunk());
  141.  
  142. test.next_chunk();
  143. test.next_chunk();
  144. //man = test.transfer();
  145. //gdk_pixbuf_save(man, "/home/pete/opengl/test.png", "png", NULL, NULL);
  146.  
  147. //GtkWidget *testw;
  148. //char *buffer;
  149. //buffer = new char [16000000];
  150. //ifstream file ("/home/pete/NeHe.bmp", ios::in | ios::binary);
  151. //cout <<file.eof();
  152. //file.seekg(0);
  153. //file.read (buffer, 16000000);
  154. //cout <<file.eof();
  155. //size_t len;
  156. //GdkPixbufLoader *test2;
  157. //test2 = gdk_pixbuf_loader_new();
  158. //gdk_pixbuf_loader_write(test2, reinterpret_cast<const guchar*>(buffer), 16000000, NULL);
  159. //GdkPixbuf *only;
  160. //only = gdk_pixbuf_loader_get_pixbuf(test2);
  161. //gdk_pixbuf_save(only, "/home/pete/opengl/test.png", "png", NULL, NULL);
  162. //test.Add();
  163. }
  164.  
  165. //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