Exemplo n.º 1
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;
}
Exemplo n.º 2
0
    ortho() :
      pump_factor_(4) 
    {

//         glVertexPointer(4, GL_FLOAT, 0, ptr);
        //glEnableClientState( GL_VERTEX_ARRAY );
//         glColorPointer(

        //std::ifstream is( "cryistal-castle-hidden-ramp.txt" );
//         std::ifstream is( "house1.txt" );
        //std::ifstream is( "cryistal-castle-tree-wave.txt" );

//         assert( is.good() );
//         height_fields_ = crystal_bits::load_crystal(is, pump_factor_);
//         std::cout << "hf: " << height_fields_.size() << "\n";
//         
//         
//         
//         scene_static_.init_solid(height_fields_);
//         
        
//         scene_static_.init_solid_from_crystal(is, pump_factor_);
        

//         scene_static_.init_planes();

//         uint64_t scene_hash = scene_static_.hash();
//         
//         try {
//             std::ifstream is( "ff.bin" );
//             
//             
//             light_static_ = light_static( is, scene_hash );
//         } catch( std::runtime_error x ) {
//             
//             std::cerr << "load failed. recreating. error:\n" << x.what() << std::endl;
//             
//             light_static_ = setup_formfactors(scene_static_.planes(), scene_static_.solid());    
//         }
//         
//         if( !false ) {
//             std::ofstream os( "ff.bin" );
//             light_static_.write(os, scene_hash);
//         }
//         
//         
//         light_dynamic_ = light_dynamic(scene_static_.planes().size() );
        
        CL_OpenGLWindowDescription desc;
        desc.set_size( CL_Size( 1024, 768 ), true );

        desc.set_depth_size(16);
        //std::cout << "depth: " << desc.get_depth_size();
        
        wnd_ = CL_DisplayWindow(desc);

        CL_GraphicContext_GL gc = wnd_.get_gc();
//      //CL_Mat4f proj = CL_Mat4f::ortho( 0, 1024, 0, 768, 100, -100 );


        gc.set_active();
#ifdef TEST_OPENCL
        try {
            init_opencl();
        } catch( cl::Error x ) {
            
//             std::array<void*, 256> bt;
//             //void *bt[256];
//             
//             size_t size = backtrace( bt.data(), bt.size() );
//             char **strings = backtrace_symbols( bt.data(), size );
//             std::cout << "backtrace: " << size << "\n";
//             for( size_t i = 0; i < size; ++i ) {
//                 std::cout << i << " " << strings[i] << "\n";
//             }
//             free( strings );
            
            std::cerr << "opencl initialization failed\ncall: " << x.what() << "\nerror code: " << cl_str_error( x.err() ) << "\n";            
            throw;
        }
#endif
      //  throw 0;
        
        glMatrixMode(GL_PROJECTION);                        //hello

        
        

        CL_Mat4f proj = CL_Mat4f::perspective( 60, 1.5, 2, 200 );
//      CL_Mat4f proj = CL_Mat4f::ortho( -20.0 * pump_factor_, 20.0 * pump_factor_, -15.0 * pump_factor_, 15.0 * pump_factor_, 0, 200 );
        //CL_Mat4f proj = CL_Mat4f::ortho( -40, 40, -30, 30, 0, 200 );


        glLoadMatrixf( proj.matrix );


        //CL_Texture tex(gc, 64, 64 );


        struct texel {
            GLubyte col[3];
            GLubyte alpha;

            texel() {
                col[0] = 128;
                col[1] = 128;
                col[2] = 128;
                alpha = 255;

            }
        };

        std::array<texel,64 * 64> tex_data;

        glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 0.0);
//      glGenTextures(1, &texName);
//      glBindTexture(GL_TEXTURE_2D, texName);
//      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
//      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_data.data());


//      gc.set_map_mode(cl_user_projection);
//      gc.set_projection(proj);
//
//      gc.flush_batcher();
//      glMatrixMode(GL_PROJECTION);


        glMatrixMode(GL_MODELVIEW);


        glEnable(GL_DEPTH_TEST);
        glDepthMask(GL_TRUE);
        glDepthFunc(GL_LESS);
        
        glEnable(GL_TEXTURE_2D);
        glShadeModel(GL_FLAT);
    }
Exemplo n.º 3
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;
}
Exemplo n.º 4
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;
}