Advertising
- Anonymous
- Monday, March 5th, 2007 at 3:44:36pm UTC
- //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 <GL/glut.h> // Header File For The GLUT Library
- #include <GL/gl.h> // Header File For The OpenGL32 Library
- #include <GL/glu.h> // Header File For The GLu32 Library
- #include <gtk/gtk.h>
- #include <gdk-pixbuf/gdk-pixbuf.h>
- #include <unistd.h> // needed to sleep
- #include <stdio.h>
- #include <iostream>
- #include <fstream>
- #include <string.h>
- using namespace std;
- class TextureLoader
- {
- private:
- int idl, buffersize, tilesize;
- float nix, niy;
- bool tilequality;
- string filename;
- bool closed;
- bool resize;
- GdkPixbufLoader *pixbuf;
- GdkPixbuf *pixbuf_new, *pixbuf_old;
- ifstream file;
- public:
- TextureLoader(string, int, int, int, bool);
- bool next_chunk();
- GdkPixbuf* transfer();
- int get_width();
- int get_height();
- };
- TextureLoader::TextureLoader(string in_filename, int in_idl, int in_buffersize, int in_tilesize, bool 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);
- ifstream file ("/home/pete/NeHe.bmp", ios::in | ios::binary);
- file.seekg(0, ios::beg);
- char *buffer;
- buffer = new char [16];
- file.read(buffer, 16);
- cout << file.fail();
- cout << file.tellg();
- cout << file.eof();
- }
- bool TextureLoader::next_chunk()
- {
- float ix, iy;
- char *buffer;
- int size;
- GError *error;
- size = 16;
- buffer = new char [size];
- cout << file.is_open();
- cout << "r";
- if (!closed)
- {
- cout << file.eof();
- if (file.eof())
- {
- bool idiot;
- cout << "!!!!!!!!!!!passed";
- idiot = gdk_pixbuf_loader_close(pixbuf, &error);
- cout << error->message;
- cout << idiot;
- file.close();
- closed = true;
- pixbuf_old = gdk_pixbuf_loader_get_pixbuf(pixbuf);
- //gdk_pixbuf_save(pixbuf_old, "/home/pete/opengl/test2.png", "png", NULL, NULL);
- 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 false;
- }
- else
- {
- cout << "Reading";
- cout << size;
- cout << file.good();
- file.read (buffer, size);
- cout << file.good();
- //cout << buffer;
- gdk_pixbuf_loader_write(pixbuf, reinterpret_cast<const guchar*>(buffer), size, NULL);
- cout << file.fail();
- cout << file.tellg();
- return true;
- }
- }
- // return false;
- }
- GdkPixbuf* TextureLoader::transfer()
- {
- // gdk_pixbuf_save(pixbuf_old, "/home/pete/opengl/test2.png", "png", NULL, NULL);
- return pixbuf_old;
- }
- int TextureLoader::get_width()
- {
- return (int)nix;
- }
- int TextureLoader::get_height()
- {
- return (int)niy;
- }
- int main(int argc, char *argv[]) {
- GdkPixbuf *man;
- gtk_init(&argc, &argv);
- TextureLoader test("/home/pete/NeHe.bmp", 0, 16000000, 512, 1);
- //while (test.next_chunk());
- test.next_chunk();
- test.next_chunk();
- //man = test.transfer();
- //gdk_pixbuf_save(man, "/home/pete/opengl/test.png", "png", NULL, NULL);
- //GtkWidget *testw;
- //char *buffer;
- //buffer = new char [16000000];
- //ifstream file ("/home/pete/NeHe.bmp", ios::in | ios::binary);
- //cout <<file.eof();
- //file.seekg(0);
- //file.read (buffer, 16000000);
- //cout <<file.eof();
- //size_t len;
- //GdkPixbufLoader *test2;
- //test2 = gdk_pixbuf_loader_new();
- //gdk_pixbuf_loader_write(test2, reinterpret_cast<const guchar*>(buffer), 16000000, NULL);
- //GdkPixbuf *only;
- //only = gdk_pixbuf_loader_get_pixbuf(test2);
- //gdk_pixbuf_save(only, "/home/pete/opengl/test.png", "png", NULL, NULL);
- //test.Add();
- }
- //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.
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.