Browse Source

Put classes related to high-level rendering into render namespace

master
C. J. Howard 1 month ago
parent
commit
54d9c199f5
80 changed files with 666 additions and 804 deletions
  1. +1
    -0
      CMakeLists.txt
  2. +1
    -1
      src/animation/screen-transition.cpp
  3. +6
    -6
      src/animation/screen-transition.hpp
  4. +3
    -3
      src/entity/components/model.hpp
  5. +2
    -2
      src/entity/components/terrain.hpp
  6. +1
    -1
      src/entity/systems/astronomy.cpp
  7. +3
    -3
      src/entity/systems/astronomy.hpp
  8. +3
    -3
      src/entity/systems/painting.cpp
  9. +3
    -5
      src/entity/systems/painting.hpp
  10. +1
    -2
      src/entity/systems/render.cpp
  11. +3
    -4
      src/entity/systems/render.hpp
  12. +11
    -11
      src/entity/systems/subterrain.cpp
  13. +6
    -8
      src/entity/systems/subterrain.hpp
  14. +10
    -10
      src/entity/systems/terrain.cpp
  15. +4
    -4
      src/entity/systems/terrain.hpp
  16. +0
    -192
      src/entity/systems/ui.cpp
  17. +0
    -89
      src/entity/systems/ui.hpp
  18. +1
    -1
      src/entity/systems/vegetation.cpp
  19. +40
    -42
      src/game/bootloader.cpp
  20. +43
    -33
      src/game/context.hpp
  21. +1
    -1
      src/game/states/brood.cpp
  22. +1
    -1
      src/game/states/forage.cpp
  23. +95
    -66
      src/game/states/loading.cpp
  24. +1
    -2
      src/game/states/nuptial-flight.cpp
  25. +2
    -2
      src/game/tools.cpp
  26. +0
    -2
      src/input/control-set.hpp
  27. +0
    -2
      src/input/gamepad.hpp
  28. +0
    -2
      src/input/mapping.hpp
  29. +8
    -5
      src/render/compositor.cpp
  30. +14
    -11
      src/render/compositor.hpp
  31. +0
    -0
      src/render/context.hpp
  32. +0
    -0
      src/render/material-flags.hpp
  33. +4
    -1
      src/render/material-property.cpp
  34. +6
    -3
      src/render/material-property.hpp
  35. +4
    -2
      src/render/material.cpp
  36. +9
    -6
      src/render/material.hpp
  37. +4
    -2
      src/render/model.cpp
  38. +11
    -7
      src/render/model.hpp
  39. +2
    -1
      src/render/operation.hpp
  40. +7
    -4
      src/render/pass.cpp
  41. +11
    -7
      src/render/pass.hpp
  42. +7
    -4
      src/render/passes/bloom-pass.cpp
  43. +8
    -6
      src/render/passes/bloom-pass.hpp
  44. +6
    -2
      src/render/passes/clear-pass.cpp
  45. +33
    -5
      src/render/passes/clear-pass.hpp
  46. +8
    -5
      src/render/passes/final-pass.cpp
  47. +9
    -7
      src/render/passes/final-pass.hpp
  48. +12
    -10
      src/render/passes/material-pass.cpp
  49. +13
    -10
      src/render/passes/material-pass.hpp
  50. +12
    -9
      src/render/passes/outline-pass.cpp
  51. +8
    -5
      src/render/passes/outline-pass.hpp
  52. +10
    -6
      src/render/passes/shadow-map-pass.cpp
  53. +9
    -5
      src/render/passes/shadow-map-pass.hpp
  54. +14
    -11
      src/render/passes/simple-pass.cpp
  55. +15
    -12
      src/render/passes/simple-pass.hpp
  56. +10
    -7
      src/render/passes/sky-pass.cpp
  57. +11
    -6
      src/render/passes/sky-pass.hpp
  58. +9
    -6
      src/render/passes/ui-pass.cpp
  59. +9
    -6
      src/render/passes/ui-pass.hpp
  60. +1
    -1
      src/render/queue.hpp
  61. +28
    -0
      src/render/render.hpp
  62. +8
    -4
      src/render/renderer.cpp
  63. +9
    -16
      src/render/renderer.hpp
  64. +5
    -1
      src/render/shader-template.cpp
  65. +7
    -3
      src/render/shader-template.hpp
  66. +7
    -31
      src/render/vertex-attribute.hpp
  67. +2
    -2
      src/resources/entity-archetype-loader.cpp
  68. +17
    -17
      src/resources/material-loader.cpp
  69. +7
    -7
      src/resources/model-loader.cpp
  70. +3
    -3
      src/resources/shader-program-loader.cpp
  71. +1
    -2
      src/scene/billboard.cpp
  72. +5
    -6
      src/scene/billboard.hpp
  73. +1
    -1
      src/scene/camera.cpp
  74. +7
    -9
      src/scene/camera.hpp
  75. +8
    -8
      src/scene/model-instance.cpp
  76. +12
    -13
      src/scene/model-instance.hpp
  77. +4
    -3
      src/scene/object.hpp
  78. +2
    -3
      src/scene/text.cpp
  79. +5
    -5
      src/scene/text.hpp
  80. +2
    -0
      src/ui/ui.hpp

+ 1
- 0
CMakeLists.txt View File

@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.7)
option(VERSION_STRING "Project version string" "0.0.0")
project(antkeeper VERSION ${VERSION_STRING} LANGUAGES CXX)

+ 1
- 1
src/animation/screen-transition.cpp View File

@ -18,7 +18,7 @@
*/
#include "screen-transition.hpp"
#include "renderer/material-flags.hpp"
#include "render/material-flags.hpp"
#include <functional>
screen_transition::screen_transition()

+ 6
- 6
src/animation/screen-transition.hpp View File

@ -21,8 +21,8 @@
#define ANTKEEPER_SCREEN_TRANSITION_HPP
#include "animation/animation.hpp"
#include "renderer/material.hpp"
#include "renderer/material-property.hpp"
#include "render/material.hpp"
#include "render/material-property.hpp"
#include "scene/billboard.hpp"
/**
@ -36,13 +36,13 @@ public:
void transition(float duration, bool reverse, animation<float>::interpolator_type interpolator);
scene::billboard* get_billboard();
::material* get_material();
render::material* get_material();
::animation<float>* get_animation();
private:
scene::billboard billboard;
::material material;
material_property<float>* progress;
render::material material;
render::material_property<float>* progress;
::animation<float> animation;
::animation<float>::channel* channel;
};
@ -52,7 +52,7 @@ inline scene::billboard* screen_transition::get_billboard()
return &billboard;
}
inline material* screen_transition::get_material()
inline render::material* screen_transition::get_material()
{
return &material;
}

+ 3
- 3
src/entity/components/model.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_ENTITY_COMPONENT_MODEL_HPP
#define ANTKEEPER_ENTITY_COMPONENT_MODEL_HPP
#include "renderer/model.hpp"
#include "render/model.hpp"
#include <unordered_map>
namespace entity {
@ -28,8 +28,8 @@ namespace component {
struct model
{
::model* render_model;
std::unordered_map<int, material*> materials;
render::model* render_model;
std::unordered_map<int, render::material*> materials;
int instance_count;
unsigned int layers;
};

+ 2
- 2
src/entity/components/terrain.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_ENTITY_COMPONENT_TERRAIN_HPP
#define ANTKEEPER_ENTITY_COMPONENT_TERRAIN_HPP
#include "renderer/material.hpp"
#include "render/material.hpp"
#include <functional>
namespace entity {
@ -35,7 +35,7 @@ struct terrain
std::size_t max_lod;
/// Material for terrain patches;
material* patch_material;
render::material* patch_material;
};
} // namespace component

+ 1
- 1
src/entity/systems/astronomy.cpp View File

@ -261,7 +261,7 @@ void astronomy::set_sun_light(scene::directional_light* light)
sun_light = light;
}
void astronomy::set_sky_pass(::sky_pass* pass)
void astronomy::set_sky_pass(::render::sky_pass* pass)
{
this->sky_pass = pass;
}

+ 3
- 3
src/entity/systems/astronomy.hpp View File

@ -25,7 +25,7 @@
#include "scene/directional-light.hpp"
#include "utility/fundamental-types.hpp"
#include "physics/frame.hpp"
#include "renderer/passes/sky-pass.hpp"
#include "render/passes/sky-pass.hpp"
#include "entity/components/atmosphere.hpp"
#include "entity/components/celestial-body.hpp"
#include "entity/components/orbit.hpp"
@ -80,7 +80,7 @@ public:
void set_sun_light(scene::directional_light* light);
void set_sky_pass(sky_pass* pass);
void set_sky_pass(::render::sky_pass* pass);
private:
void on_celestial_body_construct(entity::registry& registry, entity::id entity_id, entity::component::celestial_body& celestial_body);
@ -102,7 +102,7 @@ private:
physics::frame<double> ezs_to_sez;
scene::directional_light* sun_light;
sky_pass* sky_pass;
::render::sky_pass* sky_pass;
};
} // namespace system

+ 3
- 3
src/entity/systems/painting.cpp View File

@ -24,14 +24,14 @@
#include "event/event-dispatcher.hpp"
#include "resources/resource-manager.hpp"
#include "math/math.hpp"
#include "renderer/material.hpp"
#include "renderer/model.hpp"
#include "render/material.hpp"
#include "render/model.hpp"
#include "utility/fundamental-types.hpp"
#include "entity/commands.hpp"
#include "entity/components/collision.hpp"
#include "entity/components/transform.hpp"
#include "gl/vertex-buffer.hpp"
#include "renderer/vertex-attribute.hpp"
#include "render/vertex-attribute.hpp"
#include "geom/mesh-functions.hpp"
#include <limits>

+ 3
- 5
src/entity/systems/painting.hpp View File

@ -28,14 +28,12 @@
#include "scene/collection.hpp"
#include "scene/model-instance.hpp"
#include "gl/vertex-buffer.hpp"
#include "render/model.hpp"
#include <vector>
#include <optional>
class material;
class event_dispatcher;
class resource_manager;
class model;
class model_group;
namespace entity {
namespace system {
@ -82,8 +80,8 @@ private:
std::size_t vertex_stride;
std::size_t vertex_count;
model* stroke_model;
model_group* stroke_model_group;
::render::model* stroke_model;
::render::model_group* stroke_model_group;
gl::vertex_buffer* stroke_vbo;
bool midstroke;

+ 1
- 2
src/entity/systems/render.cpp View File

@ -20,7 +20,6 @@
#include "render.hpp"
#include "entity/components/transform.hpp"
#include "entity/components/camera.hpp"
#include "renderer/renderer.hpp"
#include "scene/point-light.hpp"
#include "scene/directional-light.hpp"
#include "scene/ambient-light.hpp"
@ -121,7 +120,7 @@ void render::remove_layers()
layers.clear();
}
void render::set_renderer(::renderer* renderer)
void render::set_renderer(::render::renderer* renderer)
{
this->renderer = renderer;
}

+ 3
- 4
src/entity/systems/render.hpp View File

@ -27,11 +27,10 @@
#include "entity/components/model.hpp"
#include "entity/components/light.hpp"
#include "entity/id.hpp"
#include "render/renderer.hpp"
#include <unordered_map>
#include <vector>
class renderer;
namespace entity {
namespace system {
@ -47,7 +46,7 @@ public:
void add_layer(scene::collection* layer);
void remove_layers();
void set_renderer(::renderer* renderer);
void set_renderer(::render::renderer* renderer);
scene::model_instance* get_model_instance(entity::id entity_id);
scene::light* get_light(entity::id entity_id);
@ -66,7 +65,7 @@ private:
double t;
double dt;
renderer* renderer;
::render::renderer* renderer;
std::vector<scene::collection*> layers;
std::unordered_map<entity::id, scene::model_instance*> model_instances;
std::unordered_map<entity::id, scene::light*> lights;

+ 11
- 11
src/entity/systems/subterrain.cpp View File

@ -21,10 +21,10 @@
#include "entity/components/model.hpp"
#include "entity/components/cavity.hpp"
#include "entity/id.hpp"
#include "renderer/model.hpp"
#include "renderer/material.hpp"
#include "render/model.hpp"
#include "render/material.hpp"
#include "geom/mesh-functions.hpp"
#include "renderer/vertex-attribute.hpp"
#include "render/vertex-attribute.hpp"
#include "gl/vertex-attribute.hpp"
#include "gl/drawing-mode.hpp"
#include "gl/vertex-buffer.hpp"
@ -195,22 +195,22 @@ subterrain::subterrain(entity::registry& registry, ::resource_manager* resource_
{
// Load subterrain materials
subterrain_inside_material = resource_manager->load<material>("subterrain-inside.mtl");
subterrain_inside_material = resource_manager->load<material>("subterrain-outside.mtl");
subterrain_inside_material = resource_manager->load<::render::material>("subterrain-inside.mtl");
subterrain_inside_material = resource_manager->load<::render::material>("subterrain-outside.mtl");
// Allocate subterrain model
subterrain_model = new model();
subterrain_model = new ::render::model();
// Create inside model group
subterrain_inside_group = subterrain_model->add_group("inside");
subterrain_inside_group->set_material(resource_manager->load<material>("subterrain-inside.mtl"));
subterrain_inside_group->set_material(resource_manager->load<::render::material>("subterrain-inside.mtl"));
subterrain_inside_group->set_drawing_mode(gl::drawing_mode::triangles);
subterrain_inside_group->set_start_index(0);
subterrain_inside_group->set_index_count(0);
// Create outside model group
subterrain_outside_group = subterrain_model->add_group("outside");
subterrain_outside_group->set_material(resource_manager->load<material>("subterrain-outside.mtl"));
subterrain_outside_group->set_material(resource_manager->load<::render::material>("subterrain-outside.mtl"));
subterrain_outside_group->set_drawing_mode(gl::drawing_mode::triangles);
subterrain_outside_group->set_start_index(0);
subterrain_outside_group->set_index_count(0);
@ -253,9 +253,9 @@ subterrain::subterrain(entity::registry& registry, ::resource_manager* resource_
attribute_offset += barycentric_attribute.components * sizeof(float);
// Bind vertex attributes to VAO
vao->bind(render::vertex_attribute::position, position_attribute);
vao->bind(render::vertex_attribute::normal, normal_attribute);
vao->bind(render::vertex_attribute::barycentric, barycentric_attribute);
vao->bind(::render::vertex_attribute::position, position_attribute);
vao->bind(::render::vertex_attribute::normal, normal_attribute);
vao->bind(::render::vertex_attribute::barycentric, barycentric_attribute);
// Calculate adjusted bounds to fit isosurface resolution
//isosurface_resolution = 0.325f;

+ 6
- 8
src/entity/systems/subterrain.hpp View File

@ -25,13 +25,11 @@
#include "geom/aabb.hpp"
#include "scene/collection.hpp"
#include "scene/model-instance.hpp"
#include "render/model.hpp"
#include "utility/fundamental-types.hpp"
#include <unordered_map>
class resource_manager;
class model;
class model_group;
class material;
namespace entity {
namespace system {
@ -104,11 +102,11 @@ private:
resource_manager* resource_manager;
geom::mesh* subterrain_mesh;
model* subterrain_model;
material* subterrain_inside_material;
material* subterrain_outside_material;
model_group* subterrain_inside_group;
model_group* subterrain_outside_group;
::render::model* subterrain_model;
::render::material* subterrain_inside_material;
::render::material* subterrain_outside_material;
::render::model_group* subterrain_inside_group;
::render::model_group* subterrain_outside_group;
int subterrain_model_vertex_size;
int subterrain_model_vertex_stride;
geom::aabb<float> subterrain_bounds;

+ 10
- 10
src/entity/systems/terrain.cpp View File

@ -29,7 +29,7 @@
#include "gl/vertex-attribute.hpp"
#include "math/constants.hpp"
#include "math/quaternion-operators.hpp"
#include "renderer/vertex-attribute.hpp"
#include "render/vertex-attribute.hpp"
#include "utility/fundamental-types.hpp"
#include <functional>
#include <iostream>
@ -405,7 +405,7 @@ geom::mesh* terrain::generate_patch_mesh(std::uint8_t face_index, quadtree_node_
return patch_mesh;
}
model* terrain::generate_patch_model(const geom::mesh& patch_mesh, material* patch_material) const
::render::model* terrain::generate_patch_model(const geom::mesh& patch_mesh, ::render::material* patch_material) const
{
// Barycentric coordinates
static const float3 barycentric[3] =
@ -470,7 +470,7 @@ model* terrain::generate_patch_model(const geom::mesh& patch_mesh, material* pat
std::size_t patch_triangle_count = patch_mesh.get_faces().size();
// Allocate patch model
model* patch_model = new model();
::render::model* patch_model = new ::render::model();
// Get model VBO and VAO
gl::vertex_buffer* vbo = patch_model->get_vertex_buffer();
@ -536,15 +536,15 @@ model* terrain::generate_patch_model(const geom::mesh& patch_mesh, material* pat
attribute_offset += target_attribute.components * sizeof(float);
// Bind vertex attributes to VAO
vao->bind(render::vertex_attribute::position, position_attribute);
vao->bind(render::vertex_attribute::uv, uv_attribute);
vao->bind(render::vertex_attribute::normal, normal_attribute);
vao->bind(render::vertex_attribute::tangent, tangent_attribute);
vao->bind(render::vertex_attribute::barycentric, barycentric_attribute);
vao->bind(render::vertex_attribute::target, target_attribute);
vao->bind(::render::vertex_attribute::position, position_attribute);
vao->bind(::render::vertex_attribute::uv, uv_attribute);
vao->bind(::render::vertex_attribute::normal, normal_attribute);
vao->bind(::render::vertex_attribute::tangent, tangent_attribute);
vao->bind(::render::vertex_attribute::barycentric, barycentric_attribute);
vao->bind(::render::vertex_attribute::target, target_attribute);
// Create model group
model_group* patch_model_group = patch_model->add_group("terrain");
::render::model_group* patch_model_group = patch_model->add_group("terrain");
patch_model_group->set_material(patch_material);
patch_model_group->set_drawing_mode(gl::drawing_mode::triangles);
patch_model_group->set_start_index(0);

+ 4
- 4
src/entity/systems/terrain.hpp View File

@ -27,8 +27,8 @@
#include "geom/quadtree.hpp"
#include "geom/mesh.hpp"
#include "utility/fundamental-types.hpp"
#include "renderer/model.hpp"
#include "renderer/material.hpp"
#include "render/model.hpp"
#include "render/material.hpp"
#include "scene/model-instance.hpp"
#include "scene/collection.hpp"
#include <unordered_map>
@ -75,7 +75,7 @@ private:
struct terrain_patch
{
geom::mesh* mesh;
model* model;
::render::model* model;
scene::model_instance* model_instance;
float error;
float morph;
@ -112,7 +112,7 @@ private:
/**
* Generates a model for a terrain patch given the patch's mesh.
*/
model* generate_patch_model(const geom::mesh& patch_mesh, material* patch_material) const;
::render::model* generate_patch_model(const geom::mesh& patch_mesh, ::render::material* patch_material) const;

+ 0
- 192
src/entity/systems/ui.cpp View File

@ -1,192 +0,0 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ui.hpp"
#include "resources/resource-manager.hpp"
namespace entity {
namespace system {
ui::ui(::resource_manager* resource_manager):
resource_manager(resource_manager),
tool_menu_control(nullptr),
camera(nullptr),
scene_collection(nullptr)
{
// Setup lighting
indirect_light.set_intensity(0.25f);
indirect_light.update_tweens();
direct_light.look_at({-0.1f, 0.0f, 1.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, -1.0f});
direct_light.set_intensity(1.0f);
direct_light.update_tweens();
// Setup modal background
modal_bg_material.set_shader_program(resource_manager->load<gl::shader_program>("ui-element-untextured.glsl"));
modal_bg_material.set_flags(1);
modal_bg_material.add_property<float4>("tint")->set_value({0, 0, 0, 0.25f});
modal_bg.set_material(&modal_bg_material);
modal_bg.set_translation({0, 0, -10.0f});
// Setup tool selector background
tool_selector_bg.set_material(resource_manager->load<material>("tool-selector.mtl"));
tool_selector_bg.set_translation({0, 0, -4.0f});
tool_selector_bg.set_scale({270, 270, 270});
// Setup scene
//scene.add_object(&camera);
//scene.add_object(&indirect_light);
//scene.add_object(&direct_light);
}
void ui::update(float dt)
{}
void ui::set_viewport(const float4& viewport)
{
this->viewport = viewport;
// Calculate viewport center
viewport_center[0] = (viewport[2] - viewport[0]) * 0.5f;
viewport_center[1] = (viewport[3] - viewport[1]) * 0.5f;
// Resize modal BG
modal_bg.set_scale({viewport[2] * 0.5f, viewport[3] * 0.5f, 1.0f});
modal_bg.update_tweens();
update_projection();
}
void ui::set_tool_menu_control(input::control* control)
{
tool_menu_control = control;
if (tool_menu_control)
{
tool_menu_control->set_activated_callback(std::bind(&ui::open_tool_menu, this));
tool_menu_control->set_deactivated_callback(std::bind(&ui::close_tool_menu, this));
}
}
void ui::set_camera(scene::camera* camera)
{
this->camera = camera;
if (camera)
{
camera->look_at({0.0f, 0.0f, 500.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f});
update_projection();
}
}
void ui::set_scene(scene::collection* collection)
{
this->scene_collection = collection;
}
void ui::handle_event(const mouse_moved_event& event)
{
if (tool_menu_control && tool_menu_control->is_active())
{
tool_selection_vector.x += event.dx;
tool_selection_vector.y += event.dy;
float max_length = 200.0f;
float selection_threshold = 20.0f;
int sector_count = 6;
float sector_angle = math::two_pi<float> / static_cast<float>(sector_count);
float length_squared = math::length_squared(tool_selection_vector);
// Select tool if length of selection vector within threshold
if (length_squared >= selection_threshold * selection_threshold)
{
// Limit length of tool selection vector
if (length_squared > max_length * max_length)
{
tool_selection_vector = (tool_selection_vector / std::sqrt(length_squared)) * max_length;
}
float2 selection_direction = tool_selection_vector / std::sqrt(length_squared);
float selection_angle = std::atan2(-selection_direction.y, selection_direction.x) - math::radians(90.0f);
selection_angle = (selection_angle >= 0.0f ? selection_angle : (math::two_pi<float> + selection_angle));
int sector = static_cast<int>((selection_angle + sector_angle * 0.5f) / sector_angle) % sector_count;
float rotation_angle = static_cast<float>(sector) * sector_angle;
tool_selector_bg.set_rotation(math::angle_axis(rotation_angle, {0, 0, 1}));
tool_selector_bg.update_tweens();
}
}
mouse_position[0] = event.x;
mouse_position[1] = event.y;
}
void ui::handle_event(const window_resized_event& event)
{
set_viewport({0.0f, 0.0f, static_cast<float>(event.w), static_cast<float>(event.h)});
}
void ui::update_projection()
{
if (camera)
{
float clip_left = -viewport[2] * 0.5f;
float clip_right = viewport[2] * 0.5f;
float clip_top = -viewport[3] * 0.5f;
float clip_bottom = viewport[3] * 0.5f;
float clip_near = 0.0f;
float clip_far = 1000.0f;
camera->set_orthographic(clip_left, clip_right, clip_top, clip_bottom, clip_near, clip_far);
}
}
void ui::open_tool_menu()
{
if (scene_collection)
{
scene_collection->add_object(&modal_bg);
scene_collection->add_object(&tool_selector_bg);
}
tool_selection_vector = {0, 0};
}
void ui::close_tool_menu()
{
if (scene_collection)
{
scene_collection->remove_object(&modal_bg);
scene_collection->remove_object(&tool_selector_bg);
}
}
void ui::open_elevator_menu()
{
}
void ui::close_elevator_menu()
{
}
} // namespace system
} // namespace entity

+ 0
- 89
src/entity/systems/ui.hpp View File

@ -1,89 +0,0 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ENTITY_SYSTEM_UI_HPP
#define ANTKEEPER_ENTITY_SYSTEM_UI_HPP
#include "event/event-handler.hpp"
#include "event/input-events.hpp"
#include "event/window-events.hpp"
#include "scene/collection.hpp"
#include "scene/camera.hpp"
#include "scene/directional-light.hpp"
#include "scene/ambient-light.hpp"
#include "scene/model-instance.hpp"
#include "scene/billboard.hpp"
#include "renderer/material.hpp"
#include "math/math.hpp"
#include "input/control.hpp"
class resource_manager;
namespace entity {
namespace system {
class ui:
public event_handler<mouse_moved_event>,
public event_handler<window_resized_event>
{
public:
ui(::resource_manager* resource_manager);
void update(float dt);
void set_viewport(const float4& viewport);
void set_tool_menu_control(input::control* control);
void set_camera(scene::camera* camera);
void set_scene(scene::collection* collection);
private:
virtual void handle_event(const mouse_moved_event& event);
virtual void handle_event(const window_resized_event& event);
void update_projection();
void open_tool_menu();
void close_tool_menu();
void open_elevator_menu();
void close_elevator_menu();
resource_manager* resource_manager;
scene::collection* scene_collection;
scene::camera* camera;
scene::ambient_light indirect_light;
scene::directional_light direct_light;
scene::billboard tool_selector_bg;
material modal_bg_material;
scene::billboard modal_bg;
scene::billboard underground_bg;
float2 mouse_position;
float4 viewport;
float2 viewport_center;
float2 tool_selection_vector;
input::control* tool_menu_control;
};
} // namespace system
} // namespace entity
#endif // ANTKEEPER_ENTITY_SYSTEM_UI_HPP

+ 1
- 1
src/entity/systems/vegetation.cpp View File

@ -23,7 +23,7 @@
#include "scene/model-instance.hpp"
#include "scene/lod-group.hpp"
#include "scene/collection.hpp"
#include "renderer/material.hpp"
#include "render/material.hpp"
#include "geom/aabb.hpp"
#include "utility/fundamental-types.hpp"
#include <cmath>

+ 40
- 42
src/game/bootloader.cpp View File

@ -37,19 +37,19 @@
#include "gl/vertex-array.hpp"
#include "gl/vertex-attribute.hpp"
#include "gl/vertex-buffer.hpp"
#include "renderer/material-flags.hpp"
#include "renderer/material-property.hpp"
#include "renderer/passes/bloom-pass.hpp"
#include "renderer/passes/clear-pass.hpp"
#include "renderer/passes/final-pass.hpp"
#include "renderer/passes/material-pass.hpp"
#include "renderer/passes/outline-pass.hpp"
#include "renderer/passes/shadow-map-pass.hpp"
#include "renderer/passes/sky-pass.hpp"
#include "renderer/simple-render-pass.hpp"
#include "renderer/vertex-attribute.hpp"
#include "renderer/compositor.hpp"
#include "renderer/renderer.hpp"
#include "render/material-flags.hpp"
#include "render/material-property.hpp"
#include "render/passes/bloom-pass.hpp"
#include "render/passes/clear-pass.hpp"
#include "render/passes/final-pass.hpp"
#include "render/passes/material-pass.hpp"
#include "render/passes/outline-pass.hpp"
#include "render/passes/shadow-map-pass.hpp"
#include "render/passes/sky-pass.hpp"
#include "render/passes/simple-pass.hpp"
#include "render/vertex-attribute.hpp"
#include "render/compositor.hpp"
#include "render/renderer.hpp"
#include "resources/resource-manager.hpp"
#include "resources/resource-manager.hpp"
#include "scene/scene.hpp"
@ -64,7 +64,6 @@
#include "entity/systems/samara.hpp"
#include "entity/systems/subterrain.hpp"
#include "entity/systems/terrain.hpp"
#include "entity/systems/ui.hpp"
#include "entity/systems/vegetation.hpp"
#include "entity/systems/spatial.hpp"
#include "entity/systems/painting.hpp"
@ -498,16 +497,16 @@ void setup_rendering(game::context* ctx)
gl::texture_2d* blue_noise_map = ctx->resource_manager->load<gl::texture_2d>("blue-noise.tex");
// Load fallback material
ctx->fallback_material = ctx->resource_manager->load<material>("fallback.mtl");
ctx->fallback_material = ctx->resource_manager->load<render::material>("fallback.mtl");
// Setup common render passes
{
ctx->common_bloom_pass = new bloom_pass(ctx->rasterizer, ctx->framebuffer_bloom, ctx->resource_manager);
ctx->common_bloom_pass = new render::bloom_pass(ctx->rasterizer, ctx->framebuffer_bloom, ctx->resource_manager);
ctx->common_bloom_pass->set_source_texture(ctx->framebuffer_hdr_color);
ctx->common_bloom_pass->set_brightness_threshold(1.0f);
ctx->common_bloom_pass->set_blur_iterations(5);
ctx->common_final_pass = new ::final_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), ctx->resource_manager);
ctx->common_final_pass = new render::final_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), ctx->resource_manager);
ctx->common_final_pass->set_color_texture(ctx->framebuffer_hdr_color);
ctx->common_final_pass->set_bloom_texture(ctx->bloom_texture);
ctx->common_final_pass->set_blue_noise_texture(blue_noise_map);
@ -515,30 +514,30 @@ void setup_rendering(game::context* ctx)
// Setup UI compositor
{
ctx->ui_clear_pass = new clear_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer());
ctx->ui_clear_pass = new render::clear_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer());
ctx->ui_clear_pass->set_cleared_buffers(false, true, false);
ctx->ui_clear_pass->set_clear_depth(0.0f);
ctx->ui_material_pass = new material_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), ctx->resource_manager);
ctx->ui_material_pass = new render::material_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), ctx->resource_manager);
ctx->ui_material_pass->set_fallback_material(ctx->fallback_material);
ctx->ui_compositor = new compositor();
ctx->ui_compositor = new render::compositor();
ctx->ui_compositor->add_pass(ctx->ui_clear_pass);
ctx->ui_compositor->add_pass(ctx->ui_material_pass);
}
// Setup underground compositor
{
ctx->underground_clear_pass = new clear_pass(ctx->rasterizer, ctx->framebuffer_hdr);
ctx->underground_clear_pass = new render::clear_pass(ctx->rasterizer, ctx->framebuffer_hdr);
ctx->underground_clear_pass->set_cleared_buffers(true, true, false);
ctx->underground_clear_pass->set_clear_color({1, 0, 1, 0});
ctx->underground_clear_pass->set_clear_depth(0.0f);
ctx->underground_material_pass = new material_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
ctx->underground_material_pass = new render::material_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
ctx->underground_material_pass->set_fallback_material(ctx->fallback_material);
ctx->app->get_event_dispatcher()->subscribe<mouse_moved_event>(ctx->underground_material_pass);
ctx->underground_compositor = new compositor();
ctx->underground_compositor = new render::compositor();
ctx->underground_compositor->add_pass(ctx->underground_clear_pass);
ctx->underground_compositor->add_pass(ctx->underground_material_pass);
ctx->underground_compositor->add_pass(ctx->common_bloom_pass);
@ -547,31 +546,31 @@ void setup_rendering(game::context* ctx)
// Setup surface compositor
{
ctx->surface_shadow_map_clear_pass = new clear_pass(ctx->rasterizer, ctx->shadow_map_framebuffer);
ctx->surface_shadow_map_clear_pass = new render::clear_pass(ctx->rasterizer, ctx->shadow_map_framebuffer);
ctx->surface_shadow_map_clear_pass->set_cleared_buffers(false, true, false);
ctx->surface_shadow_map_clear_pass->set_clear_depth(1.0f);
ctx->surface_shadow_map_pass = new shadow_map_pass(ctx->rasterizer, ctx->shadow_map_framebuffer, ctx->resource_manager);
ctx->surface_shadow_map_pass = new render::shadow_map_pass(ctx->rasterizer, ctx->shadow_map_framebuffer, ctx->resource_manager);
ctx->surface_shadow_map_pass->set_split_scheme_weight(0.75f);
ctx->surface_clear_pass = new clear_pass(ctx->rasterizer, ctx->framebuffer_hdr);
ctx->surface_clear_pass = new render::clear_pass(ctx->rasterizer, ctx->framebuffer_hdr);
ctx->surface_clear_pass->set_cleared_buffers(true, true, true);
ctx->surface_clear_pass->set_clear_depth(0.0f);
ctx->surface_sky_pass = new sky_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
ctx->surface_sky_pass = new render::sky_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
ctx->app->get_event_dispatcher()->subscribe<mouse_moved_event>(ctx->surface_sky_pass);
ctx->surface_material_pass = new material_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
ctx->surface_material_pass = new render::material_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
ctx->surface_material_pass->set_fallback_material(ctx->fallback_material);
ctx->surface_material_pass->shadow_map_pass = ctx->surface_shadow_map_pass;
ctx->surface_material_pass->shadow_map = ctx->shadow_map_depth_texture;
ctx->app->get_event_dispatcher()->subscribe<mouse_moved_event>(ctx->surface_material_pass);
ctx->surface_outline_pass = new outline_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
ctx->surface_outline_pass = new render::outline_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
ctx->surface_outline_pass->set_outline_width(0.25f);
ctx->surface_outline_pass->set_outline_color(float4{1.0f, 1.0f, 1.0f, 1.0f});
ctx->surface_compositor = new compositor();
ctx->surface_compositor = new render::compositor();
ctx->surface_compositor->add_pass(ctx->surface_shadow_map_clear_pass);
ctx->surface_compositor->add_pass(ctx->surface_shadow_map_pass);
ctx->surface_compositor->add_pass(ctx->surface_clear_pass);
@ -637,7 +636,7 @@ void setup_rendering(game::context* ctx)
}
// Create renderer
ctx->renderer = new renderer();
ctx->renderer = new render::renderer();
ctx->renderer->set_billboard_vao(ctx->billboard_vao);
logger->pop_task(EXIT_SUCCESS);
@ -659,6 +658,14 @@ void setup_scenes(game::context* ctx)
// Setup UI camera
ctx->ui_camera = new scene::camera();
ctx->ui_camera->set_compositor(ctx->ui_compositor);
auto viewport = ctx->app->get_viewport_dimensions();
float clip_left = -viewport[0] * 0.5f;
float clip_right = viewport[0] * 0.5f;
float clip_top = -viewport[1] * 0.5f;
float clip_bottom = viewport[1] * 0.5f;
float clip_near = 0.0f;
float clip_far = 1000.0f;
ctx->ui_camera->set_orthographic(clip_left, clip_right, clip_top, clip_bottom, clip_near, clip_far);
// Setup underground camera
ctx->underground_camera = new scene::camera();
@ -680,7 +687,7 @@ void setup_scenes(game::context* ctx)
const gl::texture_2d* splash_texture = ctx->resource_manager->load<gl::texture_2d>("splash.tex");
auto splash_dimensions = splash_texture->get_dimensions();
ctx->splash_billboard_material = new material();
ctx->splash_billboard_material = new render::material();
ctx->splash_billboard_material->set_shader_program(ctx->resource_manager->load<gl::shader_program>("ui-element-textured.glsl"));
ctx->splash_billboard_material->add_property<const gl::texture_2d*>("background")->set_value(splash_texture);
ctx->splash_billboard_material->add_property<float4>("tint")->set_value(float4{1, 1, 1, 1});
@ -693,7 +700,7 @@ void setup_scenes(game::context* ctx)
// Create camera flash billboard
material* flash_material = new material();
render::material* flash_material = new render::material();
flash_material->set_shader_program(ctx->resource_manager->load<gl::shader_program>("ui-element-untextured.glsl"));
auto flash_tint = flash_material->add_property<float4>("tint");
flash_tint->set_value(float4{1, 1, 1, 1});
@ -895,14 +902,6 @@ void setup_systems(game::context* ctx)
ctx->render_system->add_layer(ctx->surface_scene);
ctx->render_system->add_layer(ctx->ui_scene);
ctx->render_system->set_renderer(ctx->renderer);
// Setup UI system
ctx->ui_system = new entity::system::ui(ctx->resource_manager);
ctx->ui_system->set_camera(ctx->ui_camera);
ctx->ui_system->set_scene(ctx->ui_scene);
ctx->ui_system->set_viewport(viewport);
event_dispatcher->subscribe<mouse_moved_event>(ctx->ui_system);
event_dispatcher->subscribe<window_resized_event>(ctx->ui_system);
}
void setup_controls(game::context* ctx)
@ -988,7 +987,6 @@ void setup_callbacks(game::context* ctx)
ctx->painting_system->update(t, dt);
ctx->proteome_system->update(t, dt);
ctx->ui_system->update(dt);
ctx->render_system->update(t, dt);
ctx->animator->animate(dt);
}

+ 43
- 33
src/game/context.hpp View File

@ -45,27 +45,19 @@
#include <unordered_map>
#include "resources/json.hpp"
#include "type/typeface.hpp"
#include "type/bitmap-font.hpp"
#include "render/material.hpp"
#include "render/material-property.hpp"
// Forward declarations
class animator;
class application;
class bloom_pass;
class clear_pass;
class compositor;
class final_pass;
class material;
class material_pass;
class resource_manager;
class screen_transition;
class shadow_map_pass;
class simple_render_pass;
class sky_pass;
class timeline;
class renderer;
class outline_pass;
template <typename T> class animation;
template <typename T> class material_property;
namespace debug
{
@ -80,7 +72,6 @@ namespace entity
class subterrain;
class terrain;
class vegetation;
class ui;
class spatial;
class painting;
class astronomy;
@ -100,6 +91,20 @@ namespace entity
}
}
namespace render
{
class bloom_pass;
class clear_pass;
class compositor;
class final_pass;
class material_pass;
class renderer;
class outline_pass;
class shadow_map_pass;
class simple_render_pass;
class sky_pass;
}
namespace game {
/// Structure containing the state of a game.
@ -141,6 +146,12 @@ struct context
string_table_map string_table_map;
std::unordered_map<std::string, std::string>* strings;
std::unordered_map<std::string, type::typeface*> typefaces;
type::bitmap_font debug_font;
type::bitmap_font menu_font;
type::bitmap_font title_font;
render::material debug_font_material;
render::material menu_font_material;
render::material title_font_material;
// Framebuffers
gl::framebuffer* shadow_map_framebuffer;
@ -153,31 +164,31 @@ struct context
// Rendering
gl::rasterizer* rasterizer;
renderer* renderer;
render::renderer* renderer;
gl::vertex_buffer* billboard_vbo;
gl::vertex_array* billboard_vao;
material* fallback_material;
material* splash_billboard_material;
render::material* fallback_material;
render::material* splash_billboard_material;
// Compositing
clear_pass* ui_clear_pass;
material_pass* ui_material_pass;
compositor* ui_compositor;
render::clear_pass* ui_clear_pass;
render::material_pass* ui_material_pass;
render::compositor* ui_compositor;
bloom_pass* common_bloom_pass;
final_pass* common_final_pass;
render::bloom_pass* common_bloom_pass;
render::final_pass* common_final_pass;
clear_pass* underground_clear_pass;
material_pass* underground_material_pass;
compositor* underground_compositor;
render::clear_pass* underground_clear_pass;
render::material_pass* underground_material_pass;
render::compositor* underground_compositor;
clear_pass* surface_shadow_map_clear_pass;
shadow_map_pass* surface_shadow_map_pass;
clear_pass* surface_clear_pass;
sky_pass* surface_sky_pass;
material_pass* surface_material_pass;
outline_pass* surface_outline_pass;
compositor* surface_compositor;
render::clear_pass* surface_shadow_map_clear_pass;
render::shadow_map_pass* surface_shadow_map_pass;
render::clear_pass* surface_clear_pass;
render::sky_pass* surface_sky_pass;
render::material_pass* surface_material_pass;
render::outline_pass* surface_outline_pass;
render::compositor* surface_compositor;
// Scene utilities
scene::collection* active_scene;
@ -205,7 +216,7 @@ struct context
animation<float>* radial_transition_in;
animation<float>* radial_transition_out;
screen_transition* fade_transition;
material_property<float3>* fade_transition_color;
render::material_property<float3>* fade_transition_color;
screen_transition* radial_transition_inner;
screen_transition* radial_transition_outer;
animation<float>* equip_tool_animation;
@ -237,7 +248,6 @@ struct context
entity::system::samara* samara_system;
entity::system::subterrain* subterrain_system;
entity::system::terrain* terrain_system;
entity::system::ui* ui_system;
entity::system::vegetation* vegetation_system;
entity::system::spatial* spatial_system;
entity::system::painting* painting_system;

+ 1
- 1
src/game/states/brood.cpp View File

@ -31,7 +31,7 @@
#include "animation/screen-transition.hpp"
#include "animation/ease.hpp"
#include "resources/resource-manager.hpp"
#include "renderer/passes/sky-pass.hpp"
#include "render/passes/sky-pass.hpp"
#include "application.hpp"
#include <iostream>

+ 1
- 1
src/game/states/forage.cpp View File

@ -56,7 +56,7 @@ void enter(game::context* ctx)
// Create biome terrain component
entity::component::terrain biome_terrain;
biome_terrain.max_lod = 18;
biome_terrain.patch_material = ctx->resource_manager->load<material>("desert-terrain.mtl");
biome_terrain.patch_material = ctx->resource_manager->load<render::material>("desert-terrain.mtl");
biome_terrain.elevation = [](double, double) -> double
{
return 0.0;

+ 95
- 66
src/game/states/loading.cpp View File

@ -42,15 +42,16 @@
#include "gl/vertex-buffer.hpp"
#include "physics/light/photometry.hpp"
#include "physics/orbit/orbit.hpp"
#include "renderer/material.hpp"
#include "renderer/model.hpp"
#include "renderer/passes/shadow-map-pass.hpp"
#include "renderer/vertex-attribute.hpp"
#include "render/material.hpp"
#include "render/model.hpp"
#include "render/passes/shadow-map-pass.hpp"
#include "render/vertex-attribute.hpp"
#include "resources/resource-manager.hpp"
#include "scene/ambient-light.hpp"
#include "scene/directional-light.hpp"
#include "utility/timestamp.hpp"
#include "type/type.hpp"
#include "configuration.hpp"
#include <stb/stb_image_write.h>
#include <unordered_set>
#include <codecvt>
@ -58,7 +59,7 @@
#include "gl/texture-wrapping.hpp"
#include "gl/texture-filter.hpp"
#include "scene/text.hpp"
#include "renderer/material-flags.hpp"
#include "render/material-flags.hpp"
namespace game {
namespace state {
@ -235,6 +236,43 @@ void load_controls(game::context* ctx)
ctx->controls["menu_right"]->set_activation_threshold(menu_activation_threshold);
}
static void build_bitmap_font(const type::typeface& typeface, float size, const std::unordered_set<char32_t>& charset, type::bitmap_font& font, render::material& material, gl::shader_program* shader_program)
{
// Get font metrics for given size
if (type::font_metrics metrics; typeface.get_metrics(size, metrics))
font.set_font_metrics(metrics);
// Format font bitmap
image& font_bitmap = font.get_bitmap();
font_bitmap.format(sizeof(std::byte), 1);
// For each UTF-32 character code in the character set
for (char32_t code: charset)
{
// Skip missing glyphs
if (!typeface.has_glyph(code))
continue;
// Add glyph to font
type::bitmap_glyph& glyph = font[code];
typeface.get_metrics(size, code, glyph.metrics);
typeface.get_bitmap(size, code, glyph.bitmap);
}
// Pack glyph bitmaps into the font bitmap
font.pack();
// Create font texture from bitmap
gl::texture_2d* font_texture = new gl::texture_2d(font_bitmap.get_width(), font_bitmap.get_height(), gl::pixel_type::uint_8, gl::pixel_format::r, gl::color_space::linear, font_bitmap.get_pixels());
font_texture->set_wrapping(gl::texture_wrapping::extend, gl::texture_wrapping::extend);
font_texture->set_filters(gl::texture_min_filter::linear, gl::texture_mag_filter::linear);
// Create font material
material.set_flags(MATERIAL_FLAG_TRANSLUCENT);
material.add_property<const gl::texture_2d*>("font_bitmap")->set_value(font_texture);
material.set_shader_program(shader_program);
}
void load_fonts(game::context* ctx)
{
// Load typefaces
@ -265,65 +303,56 @@ void load_fonts(game::context* ctx)
}
}
// Build bitmap fonts
// Load bitmap font shader
gl::shader_program* bitmap_font_shader = ctx->resource_manager->load<gl::shader_program>("bitmap-font.glsl");
// Build debug font
if (auto it = ctx->typefaces.find("monospace"); it != ctx->typefaces.end())
{
build_bitmap_font(*it->second, 22.0f, charset, ctx->debug_font, ctx->debug_font_material, bitmap_font_shader);
}
// Build menu font
if (auto it = ctx->typefaces.find("sans_serif"); it != ctx->typefaces.end())
{
type::typeface* typeface = it->second;
type::bitmap_font* font = new type::bitmap_font();
// Get font metrics
const float size = 28.0f;
if (type::font_metrics metrics; typeface->get_metrics(size, metrics))
font->set_font_metrics(metrics);
// Format font bitmap
image& font_bitmap = font->get_bitmap();
font_bitmap.format(sizeof(unsigned char), 1);
// For each UTF-32 character code in the character set
for (char32_t code: charset)
{
if (!typeface->has_glyph(code))
continue;
type::bitmap_glyph& glyph = (*font)[code];
typeface->get_metrics(size, code, glyph.metrics);
typeface->get_bitmap(size, code, glyph.bitmap);
}
// Pack glyph bitmaps into the font bitmap
font->pack();
// Create font texture from bitmap
gl::texture_2d* font_texture = new gl::texture_2d(font_bitmap.get_width(), font_bitmap.get_height(), gl::pixel_type::uint_8, gl::pixel_format::r, gl::color_space::linear, font_bitmap.get_pixels());
font_texture->set_wrapping(gl::texture_wrapping::extend, gl::texture_wrapping::extend);
font_texture->set_filters(gl::texture_min_filter::linear, gl::texture_mag_filter::linear);
// Create font material
material* font_material = new material();
font_material->set_flags(MATERIAL_FLAG_TRANSLUCENT);
font_material->add_property<const gl::texture_2d*>("font_bitmap")->set_value(font_texture);
font_material->set_shader_program(ctx->resource_manager->load<gl::shader_program>("bitmap-font.glsl"));
// Create text scene object
scene::text* text_object = new scene::text();
text_object->set_material(font_material);
text_object->set_font(font);
text_object->set_color({1.0f, 1.0f, 1.0f, 1.0f});
//text_object->set_content("Hello, World!");
if (auto it = ctx->strings->find("continue"); it != ctx->strings->end())
text_object->set_content(it->second);
// Add text object to UI scene
ctx->ui_scene->add_object(text_object);
// Center text object
const auto& text_aabb = static_cast<const geom::aabb<float>&>(text_object->get_local_bounds());
float text_w = text_aabb.max_point.x - text_aabb.min_point.x;
float text_h = text_aabb.max_point.y - text_aabb.min_point.y;
text_object->set_translation({std::round(-text_w * 0.5f), std::round(-text_h * 0.5f), 0.0f});
build_bitmap_font(*it->second, 28.0f, charset, ctx->menu_font, ctx->menu_font_material, bitmap_font_shader);
}
// Build title font
if (auto it = ctx->typefaces.find("serif"); it != ctx->typefaces.end())
{
build_bitmap_font(*it->second, 96.0f, charset, ctx->title_font, ctx->title_font_material, bitmap_font_shader);
}
// Create title text
scene::text* title_text = new scene::text();
title_text->set_material(&ctx->title_font_material);
title_text->set_font(&ctx->title_font);
title_text->set_color({1.0f, 1.0f, 1.0f, 1.0f});
title_text->set_content((*ctx->strings)["title"]);
ctx->ui_scene->add_object(title_text);
// Align title text
const auto& title_aabb = static_cast<const geom::aabb<float>&>(title_text->get_local_bounds());
float title_w = title_aabb.max_point.x - title_aabb.min_point.x;
float title_h = title_aabb.max_point.y - title_aabb.min_point.y;
title_text->set_translation({std::round(-title_w * 0.5f), std::round(-title_h * 0.5f), 0.0f});
// Create version string text
scene::text* version_text = new scene::text();
version_text->set_material(&ctx->debug_font_material);
version_text->set_font(&ctx->debug_font);
version_text->set_color({1.0f, 1.0f, 1.0f, 1.0f});
version_text->set_content(ANTKEEPER_VERSION_STRING);
ctx->ui_scene->add_object(version_text);
// Align version string
const auto& version_aabb = static_cast<const geom::aabb<float>&>(version_text->get_local_bounds());
float version_w = version_aabb.max_point.x - version_aabb.min_point.x;
float version_h = version_aabb.max_point.y - version_aabb.min_point.y;
const float version_padding = 12.0f;
auto viewport = ctx->app->get_viewport_dimensions();
version_text->set_translation({viewport[0] * 0.5f - version_w - version_padding, -viewport[1] * 0.5f + version_padding, 0.0f});
}
void cosmogenesis(game::context* ctx)
@ -446,7 +475,7 @@ void planetogenesis(game::context* ctx)
ctx->astronomy_system->set_reference_body(planet_eid);
// Load sky model
ctx->surface_sky_pass->set_sky_model(ctx->resource_manager->load<model>("sky-dome.mdl"));
ctx->surface_sky_pass->set_sky_model(ctx->resource_manager->load<render::model>("sky-dome.mdl"));
}
void selenogenesis(game::context* ctx)
@ -456,7 +485,7 @@ void selenogenesis(game::context* ctx)
ctx->entities["moon"] = moon_eid;
// Pass moon model to sky pass
ctx->surface_sky_pass->set_moon_model(ctx->resource_manager->load<model>("moon.mdl"));
ctx->surface_sky_pass->set_moon_model(ctx->resource_manager->load<render::model>("moon.mdl"));
}
void extrasolar_heliogenesis(game::context* ctx)
@ -539,7 +568,7 @@ void extrasolar_heliogenesis(game::context* ctx)
ctx->resource_manager->unload("stars.csv");
// Allocate stars model
model* stars_model = new model();
render::model* stars_model = new render::model();
// Get model VBO and VAO
gl::vertex_buffer* vbo = stars_model->get_vertex_buffer();
@ -576,10 +605,10 @@ void extrasolar_heliogenesis(game::context* ctx)
vao->bind(render::vertex_attribute::color, color_attribute);
// Load star material
material* star_material = ctx->resource_manager->load<material>("fixed-star.mtl");
render::material* star_material = ctx->resource_manager->load<render::material>("fixed-star.mtl");
// Create model group
model_group* stars_model_group = stars_model->add_group("stars");
render::model_group* stars_model_group = stars_model->add_group("stars");
stars_model_group->set_material(star_material);
stars_model_group->set_drawing_mode(gl::drawing_mode::points);
stars_model_group->set_start_index(0);

+ 1
- 2
src/game/states/nuptial-flight.cpp View File

@ -26,7 +26,6 @@
#include "entity/components/transform.hpp"