Conquer Space 0.0.0
A space themed grand strategy game set in the near future, with realistic orbital mechanics, and an emphasis on economics and politics.
starsystemrenderer.h
Go to the documentation of this file.
1/* Conquer Space
2 * Copyright (C) 2021-2025 Conquer Space
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include <map>
20#include <string>
21#include <vector>
22
29#include "core/universe.h"
30#include "engine/application.h"
35#include "entt/entt.hpp"
36#include "glm/glm.hpp"
37
38namespace cqsp::client::systems {
39/*
40 * Main renderer for the solar system
41 */
43 public:
45 void Initialize();
46 void OnTick();
47 void Render(float delta_time);
48 void SeeStarSystem();
49 void Update(float delta_time);
50 void DoUI(float delta_time);
51
54
55 double min_zoom = 1;
56 // Light year sized
57 double max_zoom = 9.4605284e15;
58
59 double GetDivider() { return divider; }
60
61 void DrawAllOrbits();
62
64
65 private:
68
73
81
92#if FALSE
93 // Disabled for now
94 asset::ShaderProgram_t no_light_shader;
95#endif
96
97 void DrawStars();
98 void DrawBodies();
99 void DrawShips();
100 void DrawSkybox();
101 void DrawModels();
102
103 void DrawEntityName(glm::vec3 &object_pos, entt::entity ent_id);
104 void DrawPlanetBillboard(const entt::entity &ent_id, const glm::vec3 &object_pos);
105 void DrawShipIcon(const glm::vec3 &object_pos);
106 void DrawCityIcon(const glm::vec3 &object_pos, float alpha_value);
107
108 void DrawAllCities(auto &bodies);
109
110 void DrawAllPlanets(auto &bodies);
112
113 void DrawTexturedPlanet(const glm::vec3 &object_pos, const entt::entity entity);
114 void GetPlanetTexture(const entt::entity entity, bool &have_normal, bool &have_roughness, bool &have_province);
115 void DrawTerrainlessPlanet(const entt::entity &entity, glm::vec3 &object_pos);
116
117 void DrawStar(const entt::entity &entity, glm::vec3 &object_pos);
118 void RenderCities(glm::vec3 &object_pos, const entt::entity &body_entity);
119 bool CityIsVisible(glm::vec3 city_pos, glm::vec3 planet_pos, glm::vec3 cam_pos);
120
121 asset::ShaderProgram_t ConstructShader(const std::string &key);
122
123 void LoadPlanetTextures();
125 void LoadProvinceMap();
126 void InitializeMeshes();
127
128 void DrawOrbit(const entt::entity &entity);
129
130 glm::vec3 CalculateFutureObjectPos(const entt::entity &);
131
132 glm::vec3 TranslateToNormalized(const glm::vec3 &);
133
137 glm::vec4 CalculateGLPosition(const glm::vec3 &object_pos);
141 bool GLPositionNotInBounds(const glm::vec4 &gl_Position, const glm::vec3 &pos);
142 glm::mat4 GetBillboardMatrix(const glm::vec3 &pos);
143 glm::vec3 GetBillboardPosition(const glm::vec3 &object_pos);
144 void SetBillboardProjection(cqsp::asset::ShaderProgram_t &shader, glm::mat4 mat);
145
147
148 float GetWindowRatio();
149
150 float Lerp(float a, float b, float t);
151
152 // How much to scale the the star system.
153 const double divider = 0.01;
155
156 const float circle_size = 0.01f;
157
158 glm::vec3 sun_position;
159 glm::vec3 sun_color;
160
162
167
168 float view_scale = 10.f;
169
170 const int sphere_resolution = 64;
171
172 bool have_province = false;
173
175};
176} // namespace cqsp::client::systems
Definition: starsystemcontroller.h:30
Definition: starsystemviewui.h:25
Definition: sysorbitgeometry.h:27
Definition: starsystemrenderer.h:42
glm::vec4 CalculateGLPosition(const glm::vec3 &object_pos)
Calculates the GL position for a log renderbuffer.
Definition: starsystemrenderer.cpp:649
void DrawTexturedPlanet(const glm::vec3 &object_pos, const entt::entity entity)
Definition: starsystemrenderer.cpp:334
int ship_icon_layer
Definition: starsystemrenderer.h:163
engine::Renderable sun
Definition: starsystemrenderer.h:80
SysOrbitGeometry orbit_geometry
Definition: starsystemrenderer.h:72
void SeeStarSystem()
Definition: starsystemrenderer.cpp:149
asset::ShaderProgram_t sun_shader
Definition: starsystemrenderer.h:89
void DrawPlanetBillboard(const entt::entity &ent_id, const glm::vec3 &object_pos)
Definition: starsystemrenderer.cpp:280
void GetPlanetTexture(const entt::entity entity, bool &have_normal, bool &have_roughness, bool &have_province)
Definition: starsystemrenderer.cpp:378
float Lerp(float a, float b, float t)
Definition: starsystemrenderer.cpp:683
void DrawAllOrbits()
Definition: starsystemrenderer.cpp:721
asset::ShaderProgram_t model_shader
Definition: starsystemrenderer.h:82
engine::Renderable ship_overlay
Definition: starsystemrenderer.h:78
void DrawOrbit(const entt::entity &entity)
Definition: starsystemrenderer.cpp:737
glm::vec3 CalculateFutureObjectPos(const entt::entity &)
Definition: starsystemrenderer.cpp:636
void DrawShipIcon(const glm::vec3 &object_pos)
Definition: starsystemrenderer.cpp:320
asset::ShaderProgram_t orbit_shader
Definition: starsystemrenderer.h:83
void DrawAllCities(auto &bodies)
Definition: starsystemrenderer.cpp:313
void InitializeMeshes()
Definition: starsystemrenderer.cpp:595
asset::ShaderProgram_t near_shader
Definition: starsystemrenderer.h:84
double GetDivider()
Definition: starsystemrenderer.h:59
engine::Renderable planet
Definition: starsystemrenderer.h:74
void OnTick()
Definition: starsystemrenderer.cpp:106
glm::vec3 TranslateToNormalized(const glm::vec3 &)
Definition: starsystemrenderer.cpp:645
void Initialize()
Definition: starsystemrenderer.cpp:91
float window_ratio
Definition: starsystemrenderer.h:154
bool have_province
Definition: starsystemrenderer.h:172
glm::mat4 GetBillboardMatrix(const glm::vec3 &pos)
Definition: starsystemrenderer.cpp:664
void LoadProvinceMap()
Definition: starsystemrenderer.cpp:593
glm::vec3 GetBillboardPosition(const glm::vec3 &object_pos)
Definition: starsystemrenderer.cpp:673
double max_zoom
Definition: starsystemrenderer.h:57
engine::Application & app
Definition: starsystemrenderer.h:67
int skybox_layer
Definition: starsystemrenderer.h:166
asset::ShaderProgram_t skybox_shader
Definition: starsystemrenderer.h:90
engine::Renderable planet_circle
Definition: starsystemrenderer.h:77
void DrawShips()
Definition: starsystemrenderer.cpp:202
double previous_mouseX
Definition: starsystemrenderer.h:52
void DrawModels()
Definition: starsystemrenderer.cpp:240
void DrawStars()
Definition: starsystemrenderer.cpp:165
bool CityIsVisible(glm::vec3 city_pos, glm::vec3 planet_pos, glm::vec3 cam_pos)
Definition: starsystemrenderer.cpp:518
void InitializeFramebuffers()
Definition: starsystemrenderer.cpp:584
asset::ShaderProgram_t circle_shader
Definition: starsystemrenderer.h:86
void CheckResourceDistRender()
Definition: starsystemrenderer.cpp:692
float GetWindowRatio()
Definition: starsystemrenderer.cpp:719
glm::vec3 sun_color
Definition: starsystemrenderer.h:159
float view_scale
Definition: starsystemrenderer.h:168
void SetBillboardProjection(cqsp::asset::ShaderProgram_t &shader, glm::mat4 mat)
Definition: starsystemrenderer.cpp:677
void DrawEntityName(glm::vec3 &object_pos, entt::entity ent_id)
Definition: starsystemrenderer.cpp:270
const float circle_size
Definition: starsystemrenderer.h:156
void DrawAllPlanetBillboards(auto &bodies)
Definition: starsystemrenderer.cpp:427
asset::ShaderProgram_t textured_planet_shader
Definition: starsystemrenderer.h:88
engine::Renderable sky
Definition: starsystemrenderer.h:76
void Update(float delta_time)
Definition: starsystemrenderer.cpp:161
double previous_mouseY
Definition: starsystemrenderer.h:53
asset::ShaderProgram_t buffer_shader
Definition: starsystemrenderer.h:91
engine::LayerRenderer renderer
Definition: starsystemrenderer.h:161
void DrawSkybox()
Definition: starsystemrenderer.cpp:226
friend StarSystemViewUI
Definition: starsystemrenderer.h:174
void Render(float delta_time)
Definition: starsystemrenderer.cpp:113
StarSystemViewUI user_interface
Definition: starsystemrenderer.h:71
asset::ShaderProgram_t ConstructShader(const std::string &key)
Definition: starsystemrenderer.cpp:580
void RenderCities(glm::vec3 &object_pos, const entt::entity &body_entity)
Definition: starsystemrenderer.cpp:478
engine::Renderable textured_planet
Definition: starsystemrenderer.h:75
asset::ShaderProgram_t planet_shader
Definition: starsystemrenderer.h:87
void DrawBodies()
Definition: starsystemrenderer.cpp:179
void DrawStar(const entt::entity &entity, glm::vec3 &object_pos)
Definition: starsystemrenderer.cpp:445
const int sphere_resolution
Definition: starsystemrenderer.h:170
int physical_layer
Definition: starsystemrenderer.h:165
engine::Renderable city
Definition: starsystemrenderer.h:79
glm::vec3 sun_position
Definition: starsystemrenderer.h:158
SysStarSystemRenderer(core::Universe &, engine::Application &)
Definition: starsystemrenderer.cpp:83
const double divider
Definition: starsystemrenderer.h:153
double min_zoom
Definition: starsystemrenderer.h:55
StarSystemController controller
Definition: starsystemrenderer.h:70
core::Universe & universe
Definition: starsystemrenderer.h:66
void LoadPlanetTextures()
Definition: starsystemrenderer.cpp:526
bool GLPositionNotInBounds(const glm::vec4 &gl_Position, const glm::vec3 &pos)
Check if the GL position is within the window
Definition: starsystemrenderer.cpp:659
asset::ShaderProgram_t vis_shader
Definition: starsystemrenderer.h:85
void DrawAllPlanets(auto &bodies)
Definition: starsystemrenderer.cpp:405
StarSystemCamera camera
Definition: starsystemrenderer.h:69
void DrawTerrainlessPlanet(const entt::entity &entity, glm::vec3 &object_pos)
Definition: starsystemrenderer.cpp:461
int planet_icon_layer
Definition: starsystemrenderer.h:164
void DrawCityIcon(const glm::vec3 &object_pos, float alpha_value)
Definition: starsystemrenderer.cpp:299
void DoUI(float delta_time)
Definition: starsystemrenderer.cpp:163
Definition: universe.h:38
Definition: application.h:48
Renders a series of framebuffers onto screen. This is a relatively simple way of allowing organizatio...
Definition: framebuffer.h:138
Definition: renderable.h:27
std::shared_ptr< ShaderProgram > ShaderProgram_t
The preferred way of using a shader program.
Definition: shader.h:113
Definition: imguidebugger.cpp:19
Definition: bodies.h:29
Definition: starsystemcamera.h:28