void TouchscreenButton::DebugRender(const vec3& position, const vec3& texture_size, fplbase::Renderer& renderer) const { #if defined(DEBUG_RENDER_BOUNDS) if (debug_shader_ && draw_bounds_) { const vec2 window_size = vec2(renderer.window_size()); static const float kButtonZDepth = 0.0f; static const fplbase::Attribute kFormat[] = {fplbase::kPosition3f, fplbase::kEND }; static const unsigned short kIndices[] = {0, 1, 1, 3, 2, 3, 2, 0}; const vec3 bottom_left = position - (texture_size / 2.0f); const vec3 top_right = position + (texture_size / 2.0f); // vertex format is [x, y, z] float vertices[] = { bottom_left.x(), bottom_left.y(), bottom_left.z(), top_right.x(), bottom_left.y(), bottom_left.z(), bottom_left.x(), top_right.y(), top_right.z(), top_right.x(), top_right.y(), top_right.z(), }; renderer.set_color(vec4(1.0f, 0.0f, 1.0f, 1.0f)); debug_shader_->Set(renderer); fplbase::Mesh::RenderArray(fplbase::Mesh::kLines, 8, kFormat, sizeof(float) * 3, reinterpret_cast<const char*>(vertices), kIndices); renderer.set_color(vec4(1.0f, 1.0f, 0.0f, 1.0f)); debug_shader_->Set(renderer); static unsigned short indicesButtonDef[] = {1, 0, 1, 2, 2, 3, 3, 0}; float verticesButtonDef[] = { button_def()->top_left()->x() * window_size.x(), button_def()->top_left()->y() * window_size.y(), kButtonZDepth, button_def()->top_left()->x() * window_size.x(), button_def()->bottom_right()->y() * window_size.y(), kButtonZDepth, button_def()->bottom_right()->x() * window_size.x(), button_def()->bottom_right()->y() * window_size.y(), kButtonZDepth, button_def()->bottom_right()->x() * window_size.x(), button_def()->top_left()->y() * window_size.y(), kButtonZDepth, }; fplbase::Mesh::RenderArray(fplbase::Mesh::kLines, 8, kFormat, sizeof(float) * 3, reinterpret_cast<const char*>(verticesButtonDef), indicesButtonDef); } #else (void)position; (void)texture_size; (void)renderer; #endif // DEBUG_RENDER_BOUNDS }
void TouchscreenButton::Render(fplbase::Renderer& renderer) { static const float kButtonZDepth = 0.0f; if (!is_visible_) { return; } renderer.set_color(vec4(color_)); auto mat = (button_.is_down() && down_material_ != nullptr) ? down_material_ : up_current_ < up_materials_.size() ? up_materials_[up_current_] : nullptr; if (!mat) return; // This is an invisible button. const vec2 window_size = vec2(renderer.window_size()); const float texture_scale = window_size.y() * one_over_cannonical_window_height_; vec2 base_size = LoadVec2( is_highlighted_ ? button_def_->draw_scale_highlighted() : (button_.is_down() ? button_def_->draw_scale_pressed() : button_def_->draw_scale_normal())); auto pulse = sinf(static_cast<float>(elapsed_time_) / 100.0f); if (is_highlighted_) { base_size += mathfu::kOnes2f * pulse * 0.05f; } vec3 texture_size = texture_scale * vec3(mat->textures()[0]->size().x() * base_size.x(), -mat->textures()[0]->size().y() * base_size.y(), 0); vec3 position = vec3(button_def()->texture_position()->x() * window_size.x(), button_def()->texture_position()->y() * window_size.y(), kButtonZDepth); renderer.set_color(mathfu::kOnes4f); if (is_active_ || inactive_shader_ == nullptr) { shader_->Set(renderer); } else { inactive_shader_->Set(renderer); } mat->Set(renderer); fplbase::Mesh::RenderAAQuadAlongX(position - (texture_size / 2.0f), position + (texture_size / 2.0f), vec2(0, 1), vec2(1, 0)); #if defined(DEBUG_RENDER_BOUNDS) DebugRender(position, texture_size, renderer); #endif // DEBUG_RENDER_BOUNDS }
static void RenderSettingsGear(fplbase::Renderer& renderer, World* world) { vec2i res = renderer.window_size(); renderer.set_model_view_projection(mathfu::mat4::Ortho( 0.0f, static_cast<float>(res.x), static_cast<float>(res.y), 0.0f, -1.0f, 1.0f)); renderer.set_color(mathfu::kOnes4f); auto shader = world->asset_manager->LoadShader("shaders/textured"); world->cardboard_settings_gear->Set(renderer); shader->Set(renderer); fplbase::Mesh::RenderAAQuadAlongX( vec3((res.x - kGearSize) / 2.0f, res.y - kGearSize, 0.0f), vec3((res.x + kGearSize) / 2.0f, res.y, 0.0f)); }
void StaticImage::Render(fplbase::Renderer& renderer) { if (!Valid()) return; if (!is_visible_) return; renderer.set_color(vec4(color_)); auto material = materials_[current_material_index_]; const vec2 window_size = vec2(renderer.window_size()); const float texture_scale = window_size.y() * one_over_cannonical_window_height_; const vec2 texture_size = texture_scale * vec2(material->textures()[0]->size()) * vec2(scale_); const vec2 position_percent = vec2(texture_position_); const vec2 position = window_size * position_percent; const vec3 position3d(position.x(), position.y(), image_def_->z_depth()); const vec3 texture_size3d(texture_size.x(), -texture_size.y(), 0.0f); shader_->Set(renderer); material->Set(renderer); fplbase::Mesh::RenderAAQuadAlongX(position3d - texture_size3d * 0.5f, position3d + texture_size3d * 0.5f, vec2(0, 1), vec2(1, 0)); }
void RenderWorld(fplbase::Renderer& renderer, World* world, Camera& camera, Camera* cardboard_camera, fplbase::InputSystem* input_system) { vec2 window_size = vec2(renderer.window_size()); world->river_component.UpdateRiverMeshes(); if (world->rendering_mode() == kRenderingStereoscopic) { window_size.x = window_size.x / 2; cardboard_camera->set_viewport_resolution(window_size); } camera.set_viewport_resolution(window_size); if (world->rendering_mode() == kRenderingStereoscopic) { // This takes care of setting/clearing the framebuffer for us. RenderStereoscopic(renderer, world, camera, cardboard_camera, input_system); } else { // Always clear the framebuffer, even though we overwrite it with the // skybox, since it's a speedup on tile-based architectures, see .e.g.: // http://www.seas.upenn.edu/~pcozzi/OpenGLInsights/OpenGLInsights-TileBasedArchitectures.pdf renderer.ClearFrameBuffer(mathfu::kZeros4f); if (world->RenderingOptionEnabled(kShadowEffect)) { world->world_renderer->RenderShadowMap(camera, renderer, world); } world->world_renderer->RenderWorld(camera, renderer, world); } }
static float AspectRatio(const fplbase::Renderer& renderer) { return static_cast<float>(renderer.window_size().x) / renderer.window_size().y; }