awl::main::exit_code const example_main( awl::main::function_context const & ) try { sge::systems::instance< brigand::list< sge::systems::with_window, sge::systems::with_renderer< sge::systems::renderer_caps::ffp >, sge::systems::with_input, sge::systems::with_image2d > > const sys( sge::systems::make_list ( sge::systems::window( sge::systems::window_source( sge::systems::original_window( sge::window::title( FCPPT_TEXT("sge sprite color texture example") ) ) ) ) ) ( sge::systems::renderer( sge::renderer::pixel_format::object( sge::renderer::pixel_format::color::depth32, sge::renderer::pixel_format::depth_stencil::off, sge::renderer::pixel_format::optional_multi_samples(), sge::renderer::pixel_format::srgb::no ), sge::renderer::display_mode::parameters( sge::renderer::display_mode::vsync::on, sge::renderer::display_mode::optional_object() ), sge::viewport::optional_resize_callback{ sge::viewport::fill_on_resize() } ) ) ( sge::systems::input( sge::systems::cursor_option_field::null() ) ) ( sge::systems::image2d( sge::media::optional_extension_set( sge::media::extension_set{ sge::media::extension( FCPPT_TEXT("png") ) } ) ) ) ( sge::systems::config() .log_settings( sge::systems::log_settings( sge::log::option_container{ sge::log::option{ sge::log::location(), fcppt::log::level::debug } } ) ) ) ); typedef sge::image::color::rgba8_format color_format; typedef sge::sprite::config::choices< sge::sprite::config::type_choices< sge::sprite::config::unit_type< int >, sge::sprite::config::float_type< float > >, sge::sprite::config::pos< sge::sprite::config::pos_option::pos >, sge::sprite::config::normal_size< sge::sprite::config::texture_size_option::always >, brigand::list< sge::sprite::config::with_color< color_format >, sge::sprite::config::with_texture< sge::sprite::config::texture_level_count< 1u >, sge::sprite::config::texture_coordinates::automatic, sge::sprite::config::texture_ownership::shared > > > sprite_choices; typedef sge::sprite::buffers::with_declaration< sge::sprite::buffers::single< sprite_choices > > sprite_buffers_type; typedef sge::sprite::object< sprite_choices > sprite_object; typedef sge::sprite::state::all_choices sprite_state_choices; typedef sge::sprite::state::object< sprite_state_choices > sprite_state_object; typedef sge::sprite::state::parameters< sprite_state_choices > sprite_state_parameters; sprite_state_object sprite_state( sys.renderer_device_ffp(), sprite_state_parameters() ); sge::renderer::texture::planar_unique_ptr const texture( sge::renderer::texture::create_planar_from_path( sge::config::media_path() / FCPPT_TEXT("images") / FCPPT_TEXT("grass.png"), sys.renderer_device_core(), sys.image_system(), sge::renderer::texture::mipmap::off(), sge::renderer::resource_flags_field::null(), sge::renderer::texture::emulate_srgb_from_caps( sys.renderer_device_ffp().caps() ) ) ); sprite_buffers_type sprite_buffers( sys.renderer_device_ffp(), sge::sprite::buffers::option::dynamic ); sprite_object const spr{ sge::sprite::roles::pos{} = fcppt::math::vector::null< sprite_object::vector >(), sge::sprite::roles::color{} = sge::image::color::convert< color_format >( sge::image::color::predef::red() ), sge::sprite::roles::texture0{} = sprite_object::texture_type{ fcppt::make_shared_ptr< sge::texture::part_raw_ref >( *texture ) } }; auto const draw( [ &spr, &sprite_buffers, &sprite_state, &sys ]{ sge::renderer::context::scoped_ffp const scoped_block( sys.renderer_device_ffp(), sys.renderer_device_ffp().onscreen_target() ); scoped_block.get().clear( sge::renderer::clear::parameters() .back_buffer( sge::image::color::any::object{ sge::image::color::predef::black() } ) ); sge::sprite::process::one( scoped_block.get(), spr, sprite_buffers, sprite_state ); } ); return sge::window::loop( sys.window_system(), sge::window::loop_function{ [ &sys, &draw ]( awl::event::base const &_event ) { sge::systems::quit_on_escape( sys, _event ); fcppt::optional::maybe_void( fcppt::cast::dynamic< sge::renderer::event::render const >( _event ), [ &draw ]( fcppt::reference< sge::renderer::event::render const > ) { draw(); } ); } } ); } catch( fcppt::exception const &_error ) { awl::show_error( _error.string() ); return awl::main::exit_failure(); } catch( std::exception const &_error ) { awl::show_error_narrow( _error.what() ); return awl::main::exit_failure(); }
awl::main::exit_code const example_main( awl::main::function_context const & ) try { sge::systems::instance< boost::mpl::vector4< sge::systems::with_renderer< sge::systems::renderer_caps::ffp >, sge::systems::with_window, sge::systems::with_input< boost::mpl::vector1< sge::systems::keyboard_collector > >, sge::systems::with_image2d > > const sys( sge::systems::make_list ( sge::systems::window( sge::systems::window_source( sge::systems::original_window( sge::window::title( FCPPT_TEXT("sge lighting example") ) ) ) ) ) ( sge::systems::renderer( sge::renderer::pixel_format::object( sge::renderer::pixel_format::color::depth32, sge::renderer::pixel_format::depth_stencil::off, sge::renderer::pixel_format::optional_multi_samples(), sge::renderer::pixel_format::srgb::no ), sge::renderer::display_mode::parameters( sge::renderer::display_mode::vsync::on, sge::renderer::display_mode::optional_object() ), sge::viewport::optional_resize_callback{ sge::viewport::fill_on_resize() } ) ) ( sge::systems::image2d( sge::media::optional_extension_set( sge::media::extension_set{ sge::media::extension( FCPPT_TEXT("png") ) } ) ) ) ( sge::systems::input( sge::systems::cursor_option_field::null() ) ) ); typedef sge::sprite::config::choices< sge::sprite::config::type_choices< sge::sprite::config::unit_type< int >, sge::sprite::config::float_type< float > >, sge::sprite::config::pos< sge::sprite::config::pos_option::pos >, sge::sprite::config::normal_size< sge::sprite::config::texture_size_option::always >, boost::mpl::vector1< sge::sprite::config::with_texture< sge::sprite::config::texture_level_count< 1u >, sge::sprite::config::texture_coordinates::automatic, sge::sprite::config::texture_ownership::reference > > > sprite_choices; typedef sge::sprite::object< sprite_choices > sprite_object; typedef sge::sprite::buffers::with_declaration< sge::sprite::buffers::single< sprite_choices > > sprite_buffers_type; sprite_buffers_type sprite_buffers( sys.renderer_device_ffp(), sge::sprite::buffers::option::dynamic ); typedef sge::sprite::state::all_choices sprite_state_choices; typedef sge::sprite::state::object< sprite_state_choices > sprite_state_object; typedef sge::sprite::state::parameters< sprite_state_choices > sprite_state_parameters; sprite_state_object sprite_state( sys.renderer_device_ffp(), sprite_state_parameters() ); sge::image2d::file_unique_ptr const image( sge::image2d::load_exn( sys.image_system(), sge::config::media_path() / FCPPT_TEXT("images") / FCPPT_TEXT("grass.png") ) ); sge::renderer::texture::planar_unique_ptr const image_texture( sge::renderer::texture::create_planar_from_view( sys.renderer_device_ffp(), image->view(), sge::renderer::texture::mipmap::off(), sge::renderer::resource_flags_field::null(), sge::renderer::texture::emulate_srgb_from_caps( sys.renderer_device_ffp().caps() ) ) ); sge::texture::part_raw_ref const texture_part( *image_texture ); sprite_object const my_object( sge::sprite::roles::pos{} = fcppt::math::vector::null< sprite_object::vector >(), sge::sprite::roles::texture0{} = sprite_object::texture_type{ texture_part } ); fcppt::signal::auto_connection const escape_connection{ sge::systems::quit_on_escape( sys ) }; sge::renderer::state::ffp::lighting::object_unique_ptr const light_state{ sys.renderer_device_ffp().create_lighting_state( sge::renderer::state::ffp::lighting::parameters{ sge::renderer::state::ffp::lighting::variant{ sge::renderer::state::ffp::lighting::enabled{ sge::renderer::state::ffp::lighting::ambient_color{ sge::image::color::predef::black() }, sge::renderer::state::ffp::lighting::diffuse_from_vertex{ false } } } } ) }; sge::renderer::state::ffp::lighting::light::object_unique_ptr const light{ sys.renderer_device_ffp().create_light_state( sge::renderer::state::ffp::lighting::light::parameters{ sge::renderer::state::ffp::lighting::diffuse_color{ sge::image::color::predef::black() }, sge::renderer::state::ffp::lighting::specular_color{ sge::image::color::predef::black() }, sge::renderer::state::ffp::lighting::ambient_color{ sge::image::color::predef::yellow() }, sge::renderer::state::ffp::lighting::light::variant{ sge::renderer::state::ffp::lighting::light::point{ sge::renderer::state::ffp::lighting::light::position{ fcppt::math::vector::construct( fcppt::math::vector::structure_cast< sge::renderer::vector2, fcppt::cast::int_to_float_fun >( my_object.center() ), -1.f ) }, sge::renderer::state::ffp::lighting::light::attenuation{ sge::renderer::state::ffp::lighting::light::constant_attenuation{ 1.f }, sge::renderer::state::ffp::lighting::light::linear_attenuation{ 0.f }, sge::renderer::state::ffp::lighting::light::quadratic_attenuation{ 0.f } } } } } ) }; while( sys.window_system().poll() ) { sge::renderer::context::scoped_ffp const scoped_block( sys.renderer_device_ffp(), sys.renderer_device_ffp().onscreen_target() ); scoped_block.get().clear( sge::renderer::clear::parameters() .back_buffer( sge::image::color::predef::black() ) ); sge::renderer::state::ffp::lighting::scoped const scoped_lighting{ scoped_block.get(), *light_state }; sge::renderer::state::ffp::lighting::light::scoped const scoped_lights{ scoped_block.get(), sge::renderer::state::ffp::lighting::light::const_object_ref_vector{ fcppt::make_cref( *light ) } }; sge::sprite::process::one( scoped_block.get(), my_object, sprite_buffers, sprite_state ); } return sys.window_system().exit_code(); } catch( fcppt::exception const &_exception ) { fcppt::io::cerr() << FCPPT_TEXT("caught sge exception: ") << _exception.string() << FCPPT_TEXT('\n'); return awl::main::exit_failure(); } catch( std::exception const &_exception ) { std::cerr << "caught std exception: " << _exception.what() << '\n'; return awl::main::exit_failure(); }