void LabyrinthWidget::initialize() {
    scene_ = create_scene(); //new QGraphicsScene( this );

    view_ = new QGraphicsView( scene_, this );
    view_->show();
    QGridLayout* layout = new QGridLayout;
    layout->addWidget(view_,0,0);
    layout->setContentsMargins( 0, 0, 0, 0 );
    setLayout(layout);
}
Esempio n. 2
0
bool Demo::create()
{
    renderer.set_auto_clear(false, false);
    renderer.set_viewport(render_size);

    create_scene();
    create_arcball();
    create_lights();

    return true;
}
/* External functions
 */
Game* create_game(void)
{
    int ii;
    Game* G = (Game*)calloc(1, sizeof(Game));
    G->timer = create_timer();
    G->graphics = create_graphics();
    G->ui = create_ui(G->graphics);

    /* Set up camera */
    G->camera = transform_zero;
    G->camera.orientation = quat_from_euler(0, -0.75f * kPi, 0);
    G->camera.position.x = 4.0f;
    G->camera.position.y = 2;
    G->camera.position.z = 7.5f;

    /* Load scene */
    reset_timer(G->timer);
    G->scene = create_scene("lightHouse.obj");
    G->sun_light.position = vec3_create(-4.0f, 5.0f, 2.0f);
    G->sun_light.color = vec3_create(1, 1, 1);
    G->sun_light.size = 35.0f;

    G->lights[0].color = vec3_create(1, 0, 0);
    G->lights[1].color = vec3_create(1, 1, 0);
    G->lights[2].color = vec3_create(0, 1, 0);
    G->lights[3].color = vec3_create(1, 0, 1);
    G->lights[4].color = vec3_create(0, 0, 1);
    G->lights[5].color = vec3_create(0, 1, 1);

    for(ii=0;ii<NUM_LIGHTS;++ii) {
        float x = (20.0f/NUM_LIGHTS) * ii - 8.0f;
        G->lights[ii].color = vec3_create(_rand_float(), _rand_float(), _rand_float());
        G->lights[ii].color = vec3_normalize(G->lights[ii].color);
        if(ii % 2)
            G->lights[ii].position = vec3_create(x, _rand_float()*3 + 2.0f, 0.0f);
        else
            G->lights[ii].position = vec3_create(0.0f, _rand_float()*3 + 2.0f, x);
        G->lights[ii].size = 5;
    }

    get_model(G->scene, 3)->material->specular_color = vec3_create(0.5f, 0.5f, 0.5f);
    get_model(G->scene, 3)->material->specular_coefficient = 1.0f;

    G->dynamic_lights = 1;

    reset_timer(G->timer);
    return G;
}
bool application::setup()
{
    root = new Ogre::Root(plugin_cfg);

    setup_resources();

    if (!configure()) return false;

    choose_scene_mgr();
    create_camera();
    create_viewports();

    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);

    create_resource_listener();
    load_resources();

    create_scene();
    create_frame_listener();

    return true;
}
Esempio n. 5
0
void		ft_render2(t_env env)
{
	t_color3	rgba;
	t_ray	ray;
	float	y;
	float	x;
	t_object arr[16];
	t_object light[16];
	float invW = 1 / (float)env.resolution.width;
	float invH = 1 / (float)env.resolution.height;
	float ratio = env.resolution.width / (float)env.resolution.height;
	float angle = tanf(M_PI * 0.5f * env.fov / 180.);

	ft_bzero(arr, sizeof(t_object) * 16);
	ft_bzero(light, sizeof(t_object) * 16);
	create_scene(parser(env.file), arr, light);
	y = 0;
	while (y < env.resolution.height)
	{
		x = 0;
		while (x < env.resolution.width)
		{
			ray.pos = env.pos_absolute_camera;
			ray.dir.x = (2. *(x * invW) - 1.) * angle * ratio;
			ray.dir.y = (1. - 2. * (y * invH)) * angle;
			ray.dir.z = 1;
			ray.dir = vector_unit(ray.dir);
			rgba = ft_trace_ray(arr, light, ray, 0, NULL, env);
			ft_put_pixel_to_image(env.img, x, y, rgba);
			x++;
		}
		y++;
	}
	dprintf(2, "The end\n");
	mlx_put_image_to_window(env.mlx, env.win, env.img.ptr, 0, 0);
}
Esempio n. 6
0
int main(int argc, char *argv[]) {
	// initialize the engine
	e = new engine(argv[0], (const char*)"../../data/");
	e->init();
	e->set_caption(APPLICATION_NAME);
	const xml::xml_doc& config_doc = e->get_config_doc();
	
	// init class pointers
	fio = e->get_file_io();
	eevt = e->get_event();
	egfx = e->get_gfx();
	t = e->get_texman();
	ocl = e->get_opencl();
	exts = e->get_ext();
	s = e->get_shader();
	r = e->get_rtt();
	f = new fft(config_doc.get<bool>("config.audio.fake_spectrum", false));
	ah = new audio_handler(f, config_doc.get<bool>("config.audio.playback", false));
	
	sce = new scene(e);
	cam = new camera(e);
	
	// for debugging purposes
	debug_tex = a2e_texture(new texture_object());
	debug_tex->width = e->get_width();
	debug_tex->height = e->get_height();
	
	// compile additional shaders
	const string ar_shaders[][2] = {
		{ "IR_GP_SKINNING", "inferred/gp_skinning.a2eshd" },
		{ "IR_MP_SKINNING", "inferred/mp_skinning.a2eshd" },
		{ "RTT_MESH", "misc/rtt_mesh.a2eshd" },
		{ "PARTICLE DEBUG", "particle/particle_debug.a2eshd" },
		{ "MOTION BLUR", "misc/motion_blur.a2eshd" },
	};
	for(size_t i = 0; i < A2E_ARRAY_LENGTH(ar_shaders); i++) {
		if(!s->add_a2e_shader(ar_shaders[i][0], ar_shaders[i][1])) {
			a2e_error("couldn't add a2e-shader \"%s\"!", ar_shaders[i][1]);
			done = true;
		}
	}
	
	// compile additional kernels
	const string ar_kernels[][4] = {
		// identifier, kernel name, file name, build options
		{ "PARTICLE MESH INIT", "particle_init", "particle_mesh_spawn.cl", " -DA2E_PARTICLE_INIT" },
		{ "PARTICLE MESH RESPAWN", "particle_respawn", "particle_mesh_spawn.cl", "" },
		{ "PARTICLE MESH COMPUTE", "particle_compute", "particle_mesh_compute.cl",
			" -DSPECTRUM_WIDTH="+size_t2string(FFT_CL_BUFFER_WIDTH)
			+" -DSPECTRUM_HEIGHT="+size_t2string(FFT_CL_BUFFER_HEIGHT) },
	};
	for(size_t i = 0; i < A2E_ARRAY_LENGTH(ar_kernels); i++) {
		bool success = ocl->add_kernel_file(ar_kernels[i][0],
											ocl->make_kernel_path(ar_kernels[i][2].c_str()),
											ar_kernels[i][1],
											ar_kernels[i][3].c_str()) != nullptr;
		if(!success) {
			a2e_error("couldn't add opencl kernel \"%s\"!", ar_kernels[i][2]);
			done = true;
		}
	}
	
	// initialize the camera
	cam->set_rotation_speed(300.0f);
	cam->set_cam_speed(5.0f);
	cam->set_mouse_input(false);
	cam->set_keyboard_input(true);
	cam->set_wasd_input(true);
	
	// get camera settings from the config
	const float3 cam_pos = config_doc.get<float3>("config.camera.position", float3(0.0f, -12.0f, -5.0f));
	const float2 cam_rot = config_doc.get<float2>("config.camera.rotation", float2(0.0f, 180.0f));
	cam->set_position(cam_pos);
	cam->set_rotation(cam_rot.x, cam_rot.y, 0.0f);
	
	// create the scene
	create_scene();
	
	// load model
	model_loader ml(e);
	bmodel = ml.load(e->data_path("NI-Elem.txt"),
					 e->data_path("NI-Vrts.txt"),
					 e->data_path("NI-Tex0.txt"),
					 e->data_path("NI-boneW.txt"),
					 e->data_path("NI-boneI.txt"),
					 e->data_path("NI-bindMatrix-CM.txt"));
	
	// render mesh border and mesh push
	mesh_border* mb = new mesh_border();
	mb->load(e->data_path("NI-Border1.txt"), e->data_path("NI-Border2.txt"));
	mb->render();
	
	mesh_push* mp = new mesh_push();
	mp->load(e->data_path("NI-Push1.txt"));
	mp->render();
	
	// init openni
	const string oni_file = (argc > 1 ? string(argv[1]) : "");
	const int init_ret = ni_handler::init(oni_file, mb, mp);
	if(init_ret != XN_STATUS_OK) {
		a2e_error("couldn't initialize openni: %u", init_ret);
		done = true;
	}
	
	// add event handlers
	event::handler key_handler_fnctr(&key_handler);
	eevt->add_event_handler(key_handler_fnctr, EVENT_TYPE::KEY_DOWN, EVENT_TYPE::KEY_UP, EVENT_TYPE::KEY_PRESSED);
	event::handler mouse_handler_fnctr(&mouse_handler);
	eevt->add_event_handler(mouse_handler_fnctr, EVENT_TYPE::MOUSE_RIGHT_CLICK);
	event::handler quit_handler_fnctr(&quit_handler);
	eevt->add_event_handler(quit_handler_fnctr, EVENT_TYPE::QUIT);
	
	// additional debug stuff
	const int2 buffer_size(1024);
	particle_debug_fbo = r->add_buffer(buffer_size.x, buffer_size.y, GL_TEXTURE_2D, texture_object::TF_POINT, rtt::TAA_NONE, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT, 1, rtt::DT_NONE);
	
	// main loop
	while(!done) {
		// event handling
		eevt->handle_events();
		
		// set caption (app name and fps count)
		if(e->is_new_fps_count()) {
			static stringstream caption;
			caption << APPLICATION_NAME << " | FPS: " << e->get_fps();
			caption << " | Cam: " << float3(-*e->get_position());
			caption << " " << cam->get_rotation();
			e->set_caption(caption.str().c_str());
			core::reset(&caption);
		}
		
		// render
		e->start_draw();
		
		if(ni_update) ni->run();
		
		cam->run();
		sce->draw();
		
		// draw debug texture
		if(show_debug_texture) {
			if(debug_tex->width > 0 && debug_tex->height > 0) {
				e->start_2d_draw();
				size_t draw_width = debug_tex->width, draw_height = debug_tex->height;
				float ratio = float(draw_width) / float(draw_height);
				float scale = 1.0f;
				if(ratio >= 1.0f && draw_width > e->get_width()) {
					scale = float(e->get_width()) / float(draw_width);
				}
				else if(ratio < 1.0f && draw_height > e->get_height()) {
					scale = float(e->get_height()) / float(draw_height);
				}
				draw_width *= scale;
				draw_height *= scale;
				egfx->draw_textured_color_rectangle(gfx::rect(0, 0,
															  (unsigned int)draw_width,
															  (unsigned int)draw_height),
													coord(0.0f, 1.0f), coord(1.0f, 0.0f),
													float4(1.0f, 1.0f, 1.0f, 0.0f),
													float4(0.0f, 0.0f, 0.0f, 1.0f),
													debug_tex->tex());
				e->stop_2d_draw();
			}
		}
		
		e->stop_draw();
		
		// for debugging purposes only: reset players (set if opencl kernels are reloaded)
		if(debug_players_reset) {
			debug_players_reset = false;
			ni_handler::reset_players();
		}
	}
	debug_tex->tex_num = 0;
	
	// cleanup
	eevt->remove_event_handler(key_handler_fnctr);
	eevt->remove_event_handler(mouse_handler_fnctr);
	eevt->remove_event_handler(quit_handler_fnctr);
	r->delete_buffer(particle_debug_fbo);
	delete ah;
	delete f;
	ni_handler::destroy();
	delete mb;
	delete mp;
	delete mat;
	for(const auto& model : models) {
		delete model;
	}
	models.clear();
	for(const auto& l : lights) {
		delete l;
	}
	lights.clear();
	
	if(bmodel != nullptr) delete bmodel;
	
	delete sce;
	delete cam;
	delete e;
	
	return 0;
}
Esempio n. 7
0
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	quit = false;

	CL_OpenGLWindowDescription desc;
	desc.set_title("ClanLib Light Surface Example");
	desc.set_size(CL_Size(900, 700), true);
	desc.set_multisampling(4);
	desc.set_allow_resize(true);
	desc.set_depth_size(16);

	CL_DisplayWindow window(desc);

	// Connect the Window close event
	CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close);

	// Connect a keyboard handler to on_key_up()
	CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

	// Set up GUI
	CL_String theme;
	if (CL_FileHelp::file_exists("../../../Resources/GUIThemeAero/theme.css"))
		theme = "../../../Resources/GUIThemeAero";
	else if (CL_FileHelp::file_exists("../../../Resources/GUIThemeBasic/theme.css"))
		theme = "../../../Resources/GUIThemeBasic";
	else
		throw CL_Exception("No themes found");

	CL_GUIWindowManagerTexture wm(window);
	CL_GUIManager gui(wm, theme);

	// Get the graphic context
	CL_GraphicContext gc = window.get_gc();

	// Deleted automatically by the GUI
	Options *options = new Options(gui, CL_Rect(8, 8, CL_Size(340, 600)));
	options->request_repaint();

	// Setup graphic store
	GraphicStore graphic_store(gc);
	scene.gs = &graphic_store;

	// Prepare the display
	gc.set_map_mode(cl_user_projection);

	CL_PolygonRasterizer polygon_rasterizer;
	polygon_rasterizer.set_culled(true);
	polygon_rasterizer.set_face_cull_mode(cl_cull_back);
	polygon_rasterizer.set_front_face(cl_face_side_clockwise);
	gc.set_polygon_rasterizer(polygon_rasterizer);

	create_scene(gc);

	CL_Font font(gc, "tahoma", 24);

	graphic_store.image_grid = CL_Image(gc, "../../Display_Render/Blend/Resources/grid.png");

	FramerateCounter framerate_counter;

	unsigned int time_last = CL_System::get_time();
	// Run until someone presses escape
	while (!quit)
	{
		framerate_counter.frame_shown();

		unsigned int time_now = CL_System::get_time();
		time_delta = time_now - time_last;
		time_last = time_now;

		// Copy direction options
		light_distant->rotation_y = options->light_direction_heading;
		light_distant->rotation_x = options->light_direction_pitch;

		// Set material options

		float shininess = options->material_shininess;

		// Convert shininess from a percentage, using Lightwave 3d's method
		shininess = shininess / 100.0f;
		shininess = pow(2, (10.0f * shininess) + 2);

		teapot->model.SetMaterial(
			shininess,		// material_shininess
			CL_Vec4f(options->material_emission_color.r, options->material_emission_color.g, options->material_emission_color.b, options->material_emission_color.a),	// material_emission
			CL_Vec4f(options->material_ambient_color.r, options->material_ambient_color.g, options->material_ambient_color.b, options->material_ambient_color.a),	// material_ambient
			CL_Vec4f(options->material_specular_color.r, options->material_specular_color.g, options->material_specular_color.b, options->material_specular_color.a)	//material_specular
			);

		rotate_teapot();

		calculate_matricies(gc);

		update_light(gc, options);

		polygon_rasterizer.set_culled(true);
		gc.set_polygon_rasterizer(polygon_rasterizer);
		render(gc);

		gc.set_modelview(CL_Mat4f::identity());
		gc.set_map_mode(cl_map_2d_upper_left);
		polygon_rasterizer.set_culled(false);
		gc.set_polygon_rasterizer(polygon_rasterizer);

		CL_String fps(cl_format("%1 fps", framerate_counter.get_framerate()));
		font.draw_text(gc, 16-2, gc.get_height()-16-2, fps, CL_Colorf(0.0f, 0.0f, 0.0f, 1.0f));
		font.draw_text(gc, 16, gc.get_height()-16-2, fps, CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f));

		wm.process();
		wm.draw_windows(gc);

		// Use flip(1) to lock the fps
		window.flip(0);

		// This call processes user input and other events
		CL_KeepAlive::process();
	}

	return 0;
}
Esempio n. 8
0
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	quit = false;

	CL_OpenGLWindowDescription desc;
	desc.set_title("ClanLib Geometry Shader Example");
	desc.set_size(CL_Size(900, 700), true);
	desc.set_multisampling(0);
	desc.set_allow_resize(false);
	desc.set_depth_size(16);
	desc.set_version(3, 2, false);

	CL_DisplayWindow window(desc);

	// Connect the Window close event
	CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close);

	// Connect a keyboard handler to on_key_up()
	CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

	// Get the graphic context
	CL_GraphicContext gc = window.get_gc();

	// Setup graphic store
	GraphicStore graphic_store(gc);
	scene.gs = &graphic_store;

	// Prepare the display
	gc.set_map_mode(cl_user_projection);

	CL_PolygonRasterizer polygon_rasterizer;
	polygon_rasterizer.set_culled(false);
	polygon_rasterizer.set_face_cull_mode(cl_cull_back);
	polygon_rasterizer.set_front_face(cl_face_side_clockwise);
	gc.set_polygon_rasterizer(polygon_rasterizer);

	create_scene(gc);

	camera_angle = 0.0f;

	CL_Font font(gc, "tahoma", 24);

	FramerateCounter framerate_counter;

	unsigned int time_last = CL_System::get_time();
	// Run until someone presses escape
	while (!quit)
	{
		framerate_counter.frame_shown();

		unsigned int time_now = CL_System::get_time();
		time_delta = time_now - time_last;
		time_last = time_now;

		control_camera();
		calculate_matricies(gc);

		gc.set_polygon_rasterizer(polygon_rasterizer);

		gc.clear_depth(1.0f);
		// ** If enabling below, change the graphic from alpha_ball2.png to alpha_ball.png in graphic_store.cpp
		//render_depth_buffer(gc);	// Render to depth buffer first, to fake sorting the particles
		render(gc);	// Render scene

		gc.set_modelview(CL_Mat4f::identity());
		gc.set_map_mode(cl_map_2d_upper_left);

		CL_String fps(cl_format("fps = %1", framerate_counter.get_framerate()));
		font.draw_text(gc, 16-2, gc.get_height()-16-2, fps, CL_Colorf(0.0f, 0.0f, 0.0f, 1.0f));
		font.draw_text(gc, 16, gc.get_height()-16-2, fps, CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f));

		CL_String info(cl_format("Drawing %1 particles", ParticleObject::num_points));
		font.draw_text(gc, 16, 30, info);

		// Use flip(1) to lock the fps
		window.flip(0);

		// This call processes user input and other events
		CL_KeepAlive::process();
	}

	return 0;
}
Esempio n. 9
0
// The start of the Application
int App::start(const std::vector<std::string> &args)
{
	quit = false;

	DisplayWindowDescription desc;
	desc.set_title("ClanLib Quaternion's Example");
	desc.set_size(Size(900, 700), true);
	desc.set_multisampling(4);
	desc.set_allow_resize(true);
	desc.set_depth_size(16);

	DisplayWindow window(desc);

	// Connect the Window close event
	Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close);

	// Connect a keyboard handler to on_key_up()
	Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

	// Set up GUI
	std::string theme;
	if (FileHelp::file_exists("../../../Resources/GUIThemeAero/theme.css"))
		theme = "../../../Resources/GUIThemeAero";
	else if (FileHelp::file_exists("../../../Resources/GUIThemeBasic/theme.css"))
		theme = "../../../Resources/GUIThemeBasic";
	else
		throw Exception("No themes found");

	GUIWindowManagerTexture wm(window);
	GUIManager gui(wm, theme);

	Canvas canvas(window);

	// Deleted automatically by the GUI
	Options *options = new Options(gui, Rect(8, 8, Size(canvas.get_width()-16, 170)));
	options->request_repaint();

	// Setup graphic store
	GraphicStore graphic_store(canvas);
	scene.gs = &graphic_store;

	RasterizerStateDescription rasterizer_state_desc;
	rasterizer_state_desc.set_culled(true);
	rasterizer_state_desc.set_face_cull_mode(cull_back);
	rasterizer_state_desc.set_front_face(face_clockwise);
	RasterizerState raster_state(canvas, rasterizer_state_desc);

	DepthStencilStateDescription depth_state_desc;
	depth_state_desc.enable_depth_write(true);
	depth_state_desc.enable_depth_test(true);
	depth_state_desc.enable_stencil_test(false);
	depth_state_desc.set_depth_compare_function(compare_lequal);
	DepthStencilState depth_write_enabled(canvas, depth_state_desc);

	create_scene(canvas);

	clan::Font font(canvas, "tahoma", 24);

	FramerateCounter framerate_counter;

	active_lerp = false;
	ubyte64 time_last = System::get_time();
	ubyte64 time_start = time_last;

	// Run until someone presses escape
	while (!quit)
	{
		framerate_counter.frame_shown();

		// Calculate time since last frame
		ubyte64 time_now = System::get_time();
		current_time = time_now - time_start;
		time_delta = time_now - time_last;
		time_last = time_now;

		// Control the target options
		control_target(options);

		// Use the euler angle options
		rotation_euler_a->rotation_y = options->rotation_y;
		rotation_euler_b->rotation_x = options->rotation_x;
		rotation_euler_c->rotation_z = options->rotation_z;

		teapot_euler->rotation_x = options->rotation_x;
		teapot_euler->rotation_y = options->rotation_y;
		teapot_euler->rotation_z = options->rotation_z;

		// Use the target angle options
		rotation_target_a->rotation_y = options->target_y;
		rotation_target_b->rotation_x = options->target_x;
		rotation_target_c->rotation_z = options->target_z;

		teapot_target->rotation_x = options->target_x;
		teapot_target->rotation_y = options->target_y;
		teapot_target->rotation_z = options->target_z;

		// Render the scene using euler angles
		calculate_matricies(canvas);
		update_light(canvas, options);

		canvas.set_depth_stencil_state(depth_write_enabled);
		canvas.set_rasterizer_state(raster_state);
		render(canvas);

		// Show the quaternion teapot
		Mat4f modelview_matrix = scene.gs->camera_modelview;
		modelview_matrix.translate_self(0.0f, 0.0f, 0.0f);
		modelview_matrix = modelview_matrix * options->quaternion.to_matrix();
		modelview_matrix.scale_self(5.0f, 5.0f, 5.0f);
		model_teapot.Draw(canvas, scene.gs, modelview_matrix);

		// Draw information boxes
		canvas.reset_rasterizer_state();
		canvas.reset_depth_stencil_state();
	
		std::string fps(string_format("%1 fps", framerate_counter.get_framerate()));
		font.draw_text(canvas, 16-2, canvas.get_height()-16-2, fps, Colorf(0.0f, 0.0f, 0.0f, 1.0f));
		font.draw_text(canvas, 16, canvas.get_height()-16-2, fps, Colorf(1.0f, 1.0f, 1.0f, 1.0f));

		font.draw_text(canvas, 60, 250, "Euler Orientation");
		font.draw_text(canvas, 330, 250, "Quaternion Orientation");
		font.draw_text(canvas, 600, 250, "Target Euler Orientation");
		font.draw_text(canvas, 16, 630, "(Using YXZ rotation order)");

		wm.process();
		wm.draw_windows(canvas);

		// Use flip(1) to lock the fps
		window.flip(0);

		KeepAlive::process();
	}

	return 0;
}
Esempio n. 10
0
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	quit = false;

	CL_OpenGLWindowDescription desc;
	desc.set_title("ClanLib Shadow Example");
	desc.set_size(CL_Size(640, 640), true);
	desc.set_multisampling(4);
	desc.set_depth_size(16);

	CL_DisplayWindow window(desc);

#ifdef _DEBUG
	//struct aiLogStream stream;
	//stream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL);
	//aiAttachLogStream(&stream);
	//stream = aiGetPredefinedLogStream(aiDefaultLogStream_FILE,"assimp_log.txt");
	//aiAttachLogStream(&stream);
#endif
	aiSetImportPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE,89.53f);

	// Connect the Window close event
	CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close);

	// Connect a keyboard handler to on_key_up()
	CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

	// Get the graphic context
	CL_GraphicContext gc = window.get_gc();

	GraphicStore graphic_store(gc);
	scene.gs = &graphic_store;

	// Prepare the display
	gc.set_map_mode(cl_user_projection);

	CL_PolygonRasterizer polygon_rasterizer;
	polygon_rasterizer.set_culled(true);
	polygon_rasterizer.set_face_cull_mode(cl_cull_back);
	polygon_rasterizer.set_front_face(cl_face_side_clockwise);
	gc.set_polygon_rasterizer(polygon_rasterizer);

	create_scene(gc);

	CL_FrameBuffer framebuffer(gc);

	CL_Texture new_depth_texture(gc, CL_Size(1024, 1024), cl_depth_component);
	new_depth_texture.set_wrap_mode(cl_wrap_clamp_to_edge, cl_wrap_clamp_to_edge, cl_wrap_clamp_to_edge);
	framebuffer.attach_depth_buffer(new_depth_texture);

	scene.gs->texture_shadow = new_depth_texture;

	camera_angle = 0.0f;

	CL_Font font(gc, "tahoma", 24);

	FramerateCounter framerate_counter;

	unsigned int time_last = CL_System::get_time();
	// Run until someone presses escape
	while (!quit)
	{
		framerate_counter.frame_shown();

		unsigned int time_now = CL_System::get_time();
		time_delta = time_now - time_last;
		time_last = time_now;

		rotate_teapot();
		control_camera();
		update_light(gc);

		calculate_matricies(gc);

		render_from_lightsource(gc, framebuffer);
		render_from_camera(gc, framebuffer);

		gc.set_modelview(CL_Mat4f::identity());
		gc.set_map_mode(cl_map_2d_upper_left);

		CL_String fps(cl_format("%1 fps", framerate_counter.get_framerate()));
		font.draw_text(gc, 16-2, gc.get_height()-16-2, fps, CL_Colorf(0.0f, 0.0f, 0.0f, 1.0f));
		font.draw_text(gc, 16, gc.get_height()-16-2, fps, CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f));

		// Use flip(1) to lock the fps
		window.flip(0);

		// This call processes user input and other events
		CL_KeepAlive::process();
	}
	aiDetachAllLogStreams();
	return 0;
}