Blob Blame Raw
#include <iostream>

#include <gdkmm.h>
#include <gtkmm.h>

#include "surface.h"
#include "generator.h"


int main(int argc, char **argv) {
	std::cout << "Lab: prototype of perspective transformation" << std::endl;
	Glib::RefPtr<Gtk::Application> application = Gtk::Application::create(
		argc, argv, "org.morevnaproject.lab.perspective");

	std::cout << "generate" << std::endl;
	Generator generator;
	DataSurface surface(256, 256);
	generator.generate(surface, Vector2(0, 0), Vector2(16, 16));
	
	std::cout << "convert" << std::endl;
	Glib::RefPtr<Gdk::Pixbuf> pixbuf = Gdk::Pixbuf::create(
		Gdk::COLORSPACE_RGB, true, 8, surface.width(), surface.height() );
	guint8 *pixel = pixbuf->get_pixels();
	for(int r = 0; r < surface.height(); ++r) {
		Color *row = surface[r];
		for(int c = 0; c < surface.width(); ++c) {
			const Color &color = row[c];
			*(pixel++) = (guint8)(color.r*255.9);
			*(pixel++) = (guint8)(color.g*255.9);
			*(pixel++) = (guint8)(color.b*255.9);
			*(pixel++) = (guint8)(color.a*255.9);
		}
	}
	
	std::cout << "create window" << std::endl;
	Gtk::Window window;
	window.set_default_size(200, 200);
	Gtk::Image image(pixbuf);
	window.add(image);
	window.show_all();
	
	std::cout << "run" << std::endl;
	int result = application->run(window);
	
	std::cout << "finished with code " << result << std::endl;
}