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 "common/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 SeeEntity();
50 void Update(float delta_time);
51 void DoUI(float delta_time);
52
55
56 double min_zoom = 1;
57 // Light year sized
58 double max_zoom = 9.4605284e15;
59
60 double GetDivider() { return divider; }
61
62 void DrawAllOrbits();
63
65
66 private:
69
74
82
93#if FALSE
94 // Disabled for now
95 asset::ShaderProgram_t no_light_shader;
96#endif
97
98 void DrawStars();
99 void DrawBodies();
100 void DrawShips();
101 void DrawSkybox();
102 void DrawModels();
103
104 void DrawEntityName(glm::vec3 &object_pos, entt::entity ent_id);
105 void DrawPlanetBillboard(const entt::entity &ent_id, const glm::vec3 &object_pos);
106 void DrawShipIcon(const glm::vec3 &object_pos);
107 void DrawCityIcon(const glm::vec3 &object_pos);
108
109 void DrawAllCities(auto &bodies);
110
111 void DrawAllPlanets(auto &bodies);
113
114 void DrawTexturedPlanet(const glm::vec3 &object_pos, const entt::entity entity);
115 void GetPlanetTexture(const entt::entity entity, bool &have_normal, bool &have_roughness, bool &have_province);
116 void DrawTerrainlessPlanet(const entt::entity &entity, glm::vec3 &object_pos);
117
118 void DrawStar(const entt::entity &entity, glm::vec3 &object_pos);
119 void RenderCities(glm::vec3 &object_pos, const entt::entity &body_entity);
120 bool CityIsVisible(glm::vec3 city_pos, glm::vec3 planet_pos, glm::vec3 cam_pos);
121
122 asset::ShaderProgram_t ConstructShader(const std::string &key);
123
124 void LoadPlanetTextures();
126 void LoadProvinceMap();
127 void InitializeMeshes();
128
129 void DrawOrbit(const entt::entity &entity);
130
131 glm::vec3 CalculateFutureObjectPos(const entt::entity &);
132
133 glm::vec3 TranslateToNormalized(const glm::vec3 &);
134
138 glm::vec4 CalculateGLPosition(const glm::vec3 &object_pos);
142 bool GLPositionNotInBounds(const glm::vec4 &gl_Position, const glm::vec3 &pos);
143 glm::mat4 GetBillboardMatrix(const glm::vec3 &pos);
144 glm::vec3 GetBillboardPosition(const glm::vec3 &object_pos);
145 void SetBillboardProjection(cqsp::asset::ShaderProgram_t &shader, glm::mat4 mat);
146
148
149 float GetWindowRatio();
150
151 // How much to scale the the star system.
152 const double divider = 0.01;
154
155 const float circle_size = 0.01f;
156
157 glm::vec3 sun_position;
158 glm::vec3 sun_color;
159
161
166
167 float view_scale = 10.f;
168
169 const int sphere_resolution = 64;
170
171 bool have_province = false;
172
174};
175} // namespace cqsp::client::systems
Definition: starsystemcontroller.h:30
Definition: starsystemviewui.h:25
Definition: sysorbitgeometry.h:22
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:333
int ship_icon_layer
Definition: starsystemrenderer.h:162
engine::Renderable sun
Definition: starsystemrenderer.h:81
SysOrbitGeometry orbit_geometry
Definition: starsystemrenderer.h:73
void SeeStarSystem()
Definition: starsystemrenderer.cpp:148
asset::ShaderProgram_t sun_shader
Definition: starsystemrenderer.h:90
void DrawPlanetBillboard(const entt::entity &ent_id, const glm::vec3 &object_pos)
Definition: starsystemrenderer.cpp:279
void GetPlanetTexture(const entt::entity entity, bool &have_normal, bool &have_roughness, bool &have_province)
Definition: starsystemrenderer.cpp:377
void DrawAllOrbits()
Definition: starsystemrenderer.cpp:712
asset::ShaderProgram_t model_shader
Definition: starsystemrenderer.h:83
engine::Renderable ship_overlay
Definition: starsystemrenderer.h:79
void DrawOrbit(const entt::entity &entity)
Definition: starsystemrenderer.cpp:728
glm::vec3 CalculateFutureObjectPos(const entt::entity &)
Definition: starsystemrenderer.cpp:636
void DrawShipIcon(const glm::vec3 &object_pos)
Definition: starsystemrenderer.cpp:319
asset::ShaderProgram_t orbit_shader
Definition: starsystemrenderer.h:84
void DrawAllCities(auto &bodies)
Definition: starsystemrenderer.cpp:312
void InitializeMeshes()
Definition: starsystemrenderer.cpp:595
asset::ShaderProgram_t near_shader
Definition: starsystemrenderer.h:85
double GetDivider()
Definition: starsystemrenderer.h:60
engine::Renderable planet
Definition: starsystemrenderer.h:75
void OnTick()
Definition: starsystemrenderer.cpp:105
glm::vec3 TranslateToNormalized(const glm::vec3 &)
Definition: starsystemrenderer.cpp:645
void Initialize()
Definition: starsystemrenderer.cpp:90
void DrawCityIcon(const glm::vec3 &object_pos)
Definition: starsystemrenderer.cpp:298
float window_ratio
Definition: starsystemrenderer.h:153
bool have_province
Definition: starsystemrenderer.h:171
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:58
engine::Application & app
Definition: starsystemrenderer.h:68
int skybox_layer
Definition: starsystemrenderer.h:165
asset::ShaderProgram_t skybox_shader
Definition: starsystemrenderer.h:91
engine::Renderable planet_circle
Definition: starsystemrenderer.h:78
void DrawShips()
Definition: starsystemrenderer.cpp:201
double previous_mouseX
Definition: starsystemrenderer.h:53
void DrawModels()
Definition: starsystemrenderer.cpp:239
void DrawStars()
Definition: starsystemrenderer.cpp:164
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:87
void CheckResourceDistRender()
Definition: starsystemrenderer.cpp:683
float GetWindowRatio()
Definition: starsystemrenderer.cpp:710
glm::vec3 sun_color
Definition: starsystemrenderer.h:158
float view_scale
Definition: starsystemrenderer.h:167
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:269
const float circle_size
Definition: starsystemrenderer.h:155
void DrawAllPlanetBillboards(auto &bodies)
Definition: starsystemrenderer.cpp:426
asset::ShaderProgram_t textured_planet_shader
Definition: starsystemrenderer.h:89
engine::Renderable sky
Definition: starsystemrenderer.h:77
void Update(float delta_time)
Definition: starsystemrenderer.cpp:160
double previous_mouseY
Definition: starsystemrenderer.h:54
asset::ShaderProgram_t buffer_shader
Definition: starsystemrenderer.h:92
engine::LayerRenderer renderer
Definition: starsystemrenderer.h:160
void DrawSkybox()
Definition: starsystemrenderer.cpp:225
friend StarSystemViewUI
Definition: starsystemrenderer.h:173
void Render(float delta_time)
Definition: starsystemrenderer.cpp:112
StarSystemViewUI user_interface
Definition: starsystemrenderer.h:72
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:477
engine::Renderable textured_planet
Definition: starsystemrenderer.h:76
asset::ShaderProgram_t planet_shader
Definition: starsystemrenderer.h:88
void DrawBodies()
Definition: starsystemrenderer.cpp:178
void DrawStar(const entt::entity &entity, glm::vec3 &object_pos)
Definition: starsystemrenderer.cpp:444
const int sphere_resolution
Definition: starsystemrenderer.h:169
SysStarSystemRenderer(common::Universe &, engine::Application &)
Definition: starsystemrenderer.cpp:82
int physical_layer
Definition: starsystemrenderer.h:164
engine::Renderable city
Definition: starsystemrenderer.h:80
glm::vec3 sun_position
Definition: starsystemrenderer.h:157
const double divider
Definition: starsystemrenderer.h:152
double min_zoom
Definition: starsystemrenderer.h:56
StarSystemController controller
Definition: starsystemrenderer.h:71
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
common::Universe & universe
Definition: starsystemrenderer.h:67
asset::ShaderProgram_t vis_shader
Definition: starsystemrenderer.h:86
void DrawAllPlanets(auto &bodies)
Definition: starsystemrenderer.cpp:404
StarSystemCamera camera
Definition: starsystemrenderer.h:70
void DrawTerrainlessPlanet(const entt::entity &entity, glm::vec3 &object_pos)
Definition: starsystemrenderer.cpp:460
int planet_icon_layer
Definition: starsystemrenderer.h:163
void DoUI(float delta_time)
Definition: starsystemrenderer.cpp:162
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:133
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