// Setup the scene and render cube system void cube_system::render() { // Enable depth testing glEnable(GL_DEPTH_TEST); // Disable lighting glDisable(GL_LIGHTING); // Clear the screen and depth buffer glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Set the projection and view setup_projection(); // Render the system render_system(); }
void InitializeOgreBase( const Ogre::String& name ) { Ogre::LogManager* log_manager = new Ogre::LogManager(); log_manager->createLog( "q-gears.log", true, true ); log_manager->getDefaultLog()->setLogDetail( ( Ogre::LoggingLevel )3 ); Ogre::String ressource_cfg(""); Ogre::String plugins_cfg(""); Ogre::String dyn_lib_ext(""); Ogre::String render_system(""); #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 dyn_lib_ext = ".dll"; #else // Assume Linux for now dyn_lib_ext = ".so"; #endif #ifdef NDEBUG ressource_cfg = "resources.cfg"; plugins_cfg = "plugins.cfg"; render_system = "./RenderSystem_GL" + dyn_lib_ext; #else ressource_cfg = "resources_d.cfg"; plugins_cfg = "plugins_d.cfg"; render_system = "./RenderSystem_GL_d" + dyn_lib_ext; #endif // init root early root = new Ogre::Root( plugins_cfg ); // set up resources // Load resource paths from config file Ogre::ConfigFile cf; cf.load( ressource_cfg ); // Go through all sections & settings in the file Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); Ogre::String secName, typeName, archName; Ogre::ResourceGroupManager &res_gm( Ogre::ResourceGroupManager::getSingleton() ); while (seci.hasMoreElements()) { secName = seci.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); Ogre::ConfigFile::SettingsMultiMap::iterator i; for (i = settings->begin(); i != settings->end(); ++i) { typeName = i->first; archName = i->second; res_gm.addResourceLocation( archName, typeName, secName, true ); } } // configure // Show the configuration dialog and initialise the system // You can skip this and use root.restoreConfig() to load configuration // settings if you were sure there are valid ones saved in ogre.cfg if( !root->restoreConfig() && !root->showConfigDialog() ) { root->setRenderSystem( root->getAvailableRenderers()[ 0 ] ); } root->initialise( false ); Ogre::NameValuePairList misc; misc[ "title" ] = name; window = root->createRenderWindow( "QGearsWindow", 800, 600, false, &misc ); // initialize resource Ogre::ResourceGroupManager::getSingleton().addResourceLocation( "./", "FileSystem", "General" ); Ogre::ResourceGroupManager::getSingleton().addResourceLocation( "./exported", "FileSystem", "General" ); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); Ogre::SceneManager* scene_manager; Ogre::Viewport* viewport; Ogre::FontManager* fmgr = new Ogre::FontManager; Ogre::OverlayManager* overlay = new Ogre::OverlayManager(); frame_listener = new DisplayFrameListener( window ); root->addFrameListener( frame_listener ); scene_manager = root->createSceneManager( Ogre::ST_GENERIC, "Scene" ); scene_manager->clearScene(); scene_manager->setAmbientLight( Ogre::ColourValue( 0.5, 0.5, 0.5 ) ); Ogre::Light* directionalLight = scene_manager->createLight("directionalLight"); directionalLight->setType( Ogre::Light::LT_DIRECTIONAL ); directionalLight->setDiffuseColour( Ogre::ColourValue( 0.5, 0.5, 0.5) ); directionalLight->setSpecularColour( Ogre::ColourValue( 0.5, 0.5, 0.5) ); directionalLight->setDirection( Ogre::Vector3( 0, 0, -1 ) ); camera = scene_manager->createCamera( "Camera" ); camera->setNearClipDistance( 0.01f ); camera->setPosition( 0, 5, 10 ); camera->lookAt( 0, 0, 0 ); viewport = window->addViewport( camera ); viewport->setBackgroundColour( Ogre::ColourValue( 0.0f, 0.4f, 0.0f ) ); camera->setAspectRatio( Ogre::Real( viewport->getActualWidth() ) / Ogre::Real( viewport->getActualHeight() ) ); LOGGER = new Logger( "game.log" ); }
void light_system::render_all_lights(augs::renderer& output, const std::array<float, 16> projection_matrix, const viewing_step step, std::function<void()> neon_callback) { const auto& cosmos = step.cosm; const auto dt = step.get_delta(); const float global_time_seconds = static_cast<float>(step.get_interpolated_total_time_passed_in_seconds()); ensure_eq(0, output.get_triangle_count()); output.light_fbo.use(); glClearColor(0.1f, 0.2f, 0.2f, 1.0f); output.clear_current_fbo(); glClearColor(0.f, 0.f, 0.f, 0.f); auto& light_program = *get_resource_manager().find(assets::program_id::LIGHT); auto& default_program = *get_resource_manager().find(assets::program_id::DEFAULT); light_program.use(); const auto light_pos_uniform = glGetUniformLocation(light_program.id, "light_pos"); const auto light_max_distance_uniform = glGetUniformLocation(light_program.id, "max_distance"); const auto light_attenuation_uniform = glGetUniformLocation(light_program.id, "light_attenuation"); const auto light_multiply_color_uniform = glGetUniformLocation(light_program.id, "multiply_color"); const auto projection_matrix_uniform = glGetUniformLocation(light_program.id, "projection_matrix"); const auto& interp = step.session.systems_audiovisual.get<interpolation_system>(); const auto& particles = step.session.systems_audiovisual.get<particles_simulation_system>(); const auto& visible_per_layer = step.visible.per_layer; std::vector<messages::visibility_information_request> requests; std::vector<messages::visibility_information_response> responses; glUniformMatrix4fv(projection_matrix_uniform, 1, GL_FALSE, projection_matrix.data()); for (const auto it : cosmos.get(processing_subjects::WITH_LIGHT)) { messages::visibility_information_request request; request.eye_transform = it.viewing_transform(interp); request.filter = filters::line_of_sight_query(); request.square_side = it.get<components::light>().max_distance.base_value; request.subject = it; requests.push_back(request); } { std::vector<messages::line_of_sight_response> dummy; visibility_system().respond_to_visibility_information_requests(cosmos, {}, requests, dummy, responses); } const auto camera_transform = step.camera.transform; const auto camera_size = step.camera.visible_world_area; const auto camera_offset = -camera_transform.pos + camera_size / 2; glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE); glerr; for (size_t i = 0; i < responses.size(); ++i) { const auto& r = responses[i]; const auto& light_entity = cosmos[requests[i].subject]; const auto& light = light_entity.get<components::light>(); auto& cache = per_entity_cache[light_entity.get_id().pool.indirection_index]; const float delta = dt.in_seconds(); light.constant.variation.update_value(rng, cache.all_variation_values[0], delta); light.linear.variation.update_value(rng, cache.all_variation_values[1], delta); light.quadratic.variation.update_value(rng, cache.all_variation_values[2], delta); light.wall_constant.variation.update_value(rng, cache.all_variation_values[3], delta); light.wall_linear.variation.update_value(rng, cache.all_variation_values[4], delta); light.wall_quadratic.variation.update_value(rng, cache.all_variation_values[5], delta); light.position_variations[0].update_value(rng, cache.all_variation_values[6], delta); light.position_variations[1].update_value(rng, cache.all_variation_values[7], delta); for (size_t t = 0; t < r.get_num_triangles(); ++t) { const auto world_light_tri = r.get_world_triangle(t, requests[i].eye_transform.pos); augs::vertex_triangle renderable_light_tri; renderable_light_tri.vertices[0].pos = world_light_tri.points[0] + camera_offset; renderable_light_tri.vertices[1].pos = world_light_tri.points[1] + camera_offset; renderable_light_tri.vertices[2].pos = world_light_tri.points[2] + camera_offset; auto considered_color = light.color; if (considered_color == black) { considered_color.set_hsv({ fmod(global_time_seconds / 16.f, 1.f), 1.0, 1.0 }); } renderable_light_tri.vertices[0].color = considered_color; renderable_light_tri.vertices[1].color = considered_color; renderable_light_tri.vertices[2].color = considered_color; output.push_triangle(renderable_light_tri); } //for (size_t d = 0; d < r.get_num_discontinuities(); ++d) { // const auto world_discontinuity = *r.get_discontinuity(d); // // if (!world_discontinuity.is_boundary) { // vertex_triangle renderable_light_tri; // // const float distance_from_light = (requests[i].eye_transform.pos - world_discontinuity.points.first).length(); // const float angle = 80.f / ((distance_from_light+0.1f)/50.f); // // //(requests[i].eye_transform.pos - world_discontinuity.points.first).length(); // // if (world_discontinuity.winding == world_discontinuity.RIGHT) { // renderable_light_tri.vertices[0].pos = world_discontinuity.points.first + camera_offset; // renderable_light_tri.vertices[1].pos = world_discontinuity.points.second + camera_offset; // renderable_light_tri.vertices[2].pos = vec2(world_discontinuity.points.second).rotate(-angle, world_discontinuity.points.first) + camera_offset; // } // else { // renderable_light_tri.vertices[0].pos = world_discontinuity.points.first + camera_offset; // renderable_light_tri.vertices[1].pos = world_discontinuity.points.second + camera_offset; // renderable_light_tri.vertices[2].pos = vec2(world_discontinuity.points.second).rotate(angle, world_discontinuity.points.first) + camera_offset; // } // // renderable_light_tri.vertices[0].color = light.color; // renderable_light_tri.vertices[1].color = light.color; // renderable_light_tri.vertices[2].color = light.color; // // output.push_triangle(renderable_light_tri); // } //} vec2 light_displacement = vec2(cache.all_variation_values[6], cache.all_variation_values[7]); auto screen_pos = requests[i].eye_transform - camera_transform; screen_pos.pos.x += camera_size.x * 0.5f; screen_pos.pos.y = camera_size.y - (screen_pos.pos.y + camera_size.y * 0.5f); screen_pos += light_displacement; glUniform2f(light_pos_uniform, screen_pos.pos.x, screen_pos.pos.y); glUniform1f(light_max_distance_uniform, light.max_distance.base_value); glUniform3f(light_attenuation_uniform, cache.all_variation_values[0] + light.constant.base_value, cache.all_variation_values[1] + light.linear.base_value, cache.all_variation_values[2] + light.quadratic.base_value ); glUniform3f(light_multiply_color_uniform, 1.f, 1.f, 1.f); output.call_triangles(); output.clear_triangles(); light_program.use(); glUniform1f(light_max_distance_uniform, light.wall_max_distance.base_value); glUniform3f(light_attenuation_uniform, cache.all_variation_values[3] + light.wall_constant.base_value, cache.all_variation_values[4] + light.wall_linear.base_value, cache.all_variation_values[5] + light.wall_quadratic.base_value ); glUniform3f(light_multiply_color_uniform, light.color.r/255.f, light.color.g/255.f, light.color.b/255.f); render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::DYNAMIC_BODY], step.camera, renderable_drawing_type::NORMAL); output.call_triangles(); output.clear_triangles(); glUniform3f(light_multiply_color_uniform, 1.f, 1.f, 1.f); } default_program.use(); render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::DYNAMIC_BODY], step.camera, renderable_drawing_type::NEON_MAPS); render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::SMALL_DYNAMIC_BODY], step.camera, renderable_drawing_type::NEON_MAPS); render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::FLYING_BULLETS], step.camera, renderable_drawing_type::NEON_MAPS); render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::CAR_INTERIOR], step.camera, renderable_drawing_type::NEON_MAPS); render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::CAR_WHEEL], step.camera, renderable_drawing_type::NEON_MAPS); render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::EFFECTS], step.camera, renderable_drawing_type::NEON_MAPS); render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::ON_GROUND], step.camera, renderable_drawing_type::NEON_MAPS); render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::ON_TILED_FLOOR], step.camera, renderable_drawing_type::NEON_MAPS); { particles_simulation_system::drawing_input in(output.triangles); in.camera = step.camera; in.drawing_type = renderable_drawing_type::NEON_MAPS; particles.draw(render_layer::EFFECTS, in); } neon_callback(); output.call_triangles(); output.clear_triangles(); glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); glerr; augs::graphics::fbo::use_default(); output.set_active_texture(2); output.bind_texture(output.light_fbo); output.set_active_texture(0); }
void standard_rendering(const viewing_step step) { const auto& camera = step.camera; auto& renderer = step.renderer; auto& output = renderer.triangles; const auto& cosmos = step.cosm; const auto& controlled_entity = cosmos[step.viewed_character]; const auto& interp = step.session.systems_audiovisual.get<interpolation_system>(); const float global_time_seconds = static_cast<float>(step.get_interpolated_total_time_passed_in_seconds()); const auto& visible_per_layer = step.visible.per_layer; const auto matrix = augs::orthographic_projection<float>(0, camera.visible_world_area.x, camera.visible_world_area.y, 0, 0, 1); auto& default_shader = *get_resource_manager().find(assets::program_id::DEFAULT); auto& pure_color_highlight_shader = *get_resource_manager().find(assets::program_id::PURE_COLOR_HIGHLIGHT); auto& border_highlight_shader = pure_color_highlight_shader; // the same auto& circular_bars_shader = *get_resource_manager().find(assets::program_id::CIRCULAR_BARS); default_shader.use(); { const auto projection_matrix_uniform = glGetUniformLocation(default_shader.id, "projection_matrix"); glUniformMatrix4fv(projection_matrix_uniform, 1, GL_FALSE, matrix.data()); } for (int i = render_layer::UNDER_GROUND; i > render_layer::DYNAMIC_BODY; --i) { render_system().draw_entities(interp, global_time_seconds,output, visible_per_layer[i], camera, renderable_drawing_type::NORMAL); } renderer.call_triangles(); renderer.clear_triangles(); border_highlight_shader.use(); { const auto projection_matrix_uniform = glGetUniformLocation(border_highlight_shader.id, "projection_matrix"); glUniformMatrix4fv(projection_matrix_uniform, 1, GL_FALSE, matrix.data()); } render_system().draw_entities(interp, global_time_seconds,output, visible_per_layer[render_layer::SMALL_DYNAMIC_BODY], camera, renderable_drawing_type::BORDER_HIGHLIGHTS); renderer.call_triangles(); renderer.clear_triangles(); default_shader.use(); for (int i = render_layer::DYNAMIC_BODY; i >= 0; --i) { render_system().draw_entities(interp, global_time_seconds,output, visible_per_layer[i], camera, renderable_drawing_type::NORMAL); } renderer.call_triangles(); renderer.clear_triangles(); circular_bars_shader.use(); { const auto projection_matrix_uniform = glGetUniformLocation(circular_bars_shader.id, "projection_matrix"); glUniformMatrix4fv(projection_matrix_uniform, 1, GL_FALSE, matrix.data()); vec2 upper(0.0f, 0.0f); vec2 lower(1.0f, 1.0f); (*assets::texture_id::HUD_CIRCULAR_BAR_MEDIUM).get_uv(upper); (*assets::texture_id::HUD_CIRCULAR_BAR_MEDIUM).get_uv(lower); const auto center = (upper + lower) / 2; glUniform2f(glGetUniformLocation(circular_bars_shader.id, "texture_center"), center.x, center.y); } const auto& hud = step.session.hud; const auto& textual_infos = hud.draw_circular_bars_and_get_textual_info(step); renderer.call_triangles(); renderer.clear_triangles(); default_shader.use(); renderer.call_triangles(textual_infos); pure_color_highlight_shader.use(); hud.draw_pure_color_highlights(step); renderer.call_triangles(); renderer.clear_triangles(); default_shader.use(); hud.draw_vertically_flying_numbers(step); if (controlled_entity.has<components::gui_element>()) { components::gui_element::draw_complete_gui_for_camera_rendering_request(output, controlled_entity, step); } renderer.bind_texture(*get_resource_manager().find(assets::atlas_id::GAME_WORLD_ATLAS)); renderer.call_triangles(); renderer.clear_triangles(); renderer.draw_debug_info( camera.visible_world_area, camera.transform, assets::texture_id::BLANK, {}, step.get_delta().view_interpolation_ratio()); }