From e1a41a526d5b2aad1061b96599671bb227f4fc24 Mon Sep 17 00:00:00 2001 From: jedi Date: Wed, 9 Mar 2022 00:56:20 +0100 Subject: [PATCH 1/2] wip --- data/shader/postprocess.frag | 14 +++--- game/game_window.hpp | 2 +- .../renderer_polygon_3d.cpp | 43 ++++++++++--------- .../renderer_polygon_3d.hpp | 1 + game/state/commands.cpp | 1 + game/state/missile.cpp | 3 +- game/state/missile.hpp | 3 +- game/state/state.cpp | 4 +- 8 files changed, 38 insertions(+), 33 deletions(-) diff --git a/data/shader/postprocess.frag b/data/shader/postprocess.frag index 488ecc2..24b5e28 100644 --- a/data/shader/postprocess.frag +++ b/data/shader/postprocess.frag @@ -7,19 +7,19 @@ varying vec2 uv; const int gaussRadius = 11; const float gaussFilter[gaussRadius] = float[gaussRadius]( - 0.0402,0.0623,0.0877,0.1120,0.1297,0.1362,0.1297,0.1120,0.0877,0.0623,0.0402 + 0.0402,0.0623,0.0877,0.1120,0.1297,0.1362,0.1297,0.1120,0.0877,0.0623,0.0402 ); uniform vec2 scale; void main() { - vec2 texCoord = uv.xy - float(int(gaussRadius/2)) * scale; - vec3 color = vec3(0.0, 0.0, 0.0); - for (int i=0; irender(); } } + + + + /* void RendererPolygon3d::renderSun() { m_planetModel->bind(); @@ -553,8 +553,8 @@ void RendererPolygon3d::renderMissiles() { m_missileModel->bind(); for (const game::Missile *missile : m_missiles) { - glm::vec3 c = glm::vec3(1.0, 1.0, 0.3); - glUniform3f(m_shader_game_objects.location("materialColor"), c.x, c.y, c.z); + glm::vec3 c = glm::vec3(missile->color); + glUniform3f(m_shader_game_objects.location("materialColor"), c.x/2, c.y/2, c.z/2); // TODO: rename functions so their name represents what args they // take @@ -665,6 +665,7 @@ void RendererPolygon3d::renderMissiles() { glUseProgram(0); // TODO dont use line mode. make that with own quads + glPolygonMode(GL_FRONT, GL_LINE); for (const game::Trace *trace : m_state->traces) { float fade_out = 1.0; @@ -680,7 +681,7 @@ void RendererPolygon3d::renderMissiles() { } glEnd(); } - glLineWidth(1.0f); + glLineWidth(1.0f); glPolygonMode(GL_FRONT, GL_FILL); } diff --git a/game/renderer_polygon_3d/renderer_polygon_3d.hpp b/game/renderer_polygon_3d/renderer_polygon_3d.hpp index 76b4f44..a92cb1b 100644 --- a/game/renderer_polygon_3d/renderer_polygon_3d.hpp +++ b/game/renderer_polygon_3d/renderer_polygon_3d.hpp @@ -38,6 +38,7 @@ namespace endofthejedi { void renderMissiles(); void renderShips(); void renderParticles(); + void renderText(const char *text, float x, float y, float sx, float sy); void addModel(const std::string &filename, PolygonModel **dest); diff --git a/game/state/commands.cpp b/game/state/commands.cpp index 443e673..0b2c7c4 100644 --- a/game/state/commands.cpp +++ b/game/state/commands.cpp @@ -19,6 +19,7 @@ namespace game { state->generateId(), player, player->ship->position, + player->color, -util::deg2rad(m_angle), 0.005*player->speed); diff --git a/game/state/missile.cpp b/game/state/missile.cpp index bef9f01..35471e3 100644 --- a/game/state/missile.cpp +++ b/game/state/missile.cpp @@ -11,9 +11,10 @@ #include namespace game { - Missile::Missile(size_t id, Player *player, const glm::vec2 &pos, float angle, float speed) + Missile::Missile(size_t id, Player *player, const glm::vec2 &pos, const glm::vec3 &col, float angle, float speed) : Object(id, pos) , player(player) + , color(col) { velocity = speed * glm::vec2(std::sin(angle), std::cos(angle)); diff --git a/game/state/missile.hpp b/game/state/missile.hpp index e58cad2..b31ef22 100644 --- a/game/state/missile.hpp +++ b/game/state/missile.hpp @@ -58,7 +58,7 @@ namespace game { size_t planetId; }; - Missile(size_t id, Player *player, const glm::vec2 &pos, float angle, float speed); + Missile(size_t id, Player *player, const glm::vec2 &pos, const glm::vec3 &col, float angle, float speed); ~Missile(); // try to advance. if something will be hit, return the first hit in @@ -68,6 +68,7 @@ namespace game { Player *player; // owner won't be hit by own missiles glm::vec2 velocity; Trace *trace; + glm::vec3 color; }; } diff --git a/game/state/state.cpp b/game/state/state.cpp index c5af8d1..e3324ec 100644 --- a/game/state/state.cpp +++ b/game/state/state.cpp @@ -164,10 +164,10 @@ namespace game { Player *player = playerForId(playerId); if (player != nullptr) { for (Missile *missile : player->missiles) { - player->missiles.remove(missile); + player->missiles.remove(missile); missile->player = nullptr; m_nextEvents.push_back(new MissileEvent(LifeCycle::Destroy, missile)); - } + } if (player->ship != nullptr) { ships.remove(player->ship); From 3a0715575607bfd07f1cc34f58ff64486420283f Mon Sep 17 00:00:00 2001 From: Tim Blume Date: Wed, 9 Mar 2022 01:01:07 +0100 Subject: [PATCH 2/2] end foo --- .gitignore | 1 + game/game_window.hpp | 2 -- game/opengl.cpp | 8 ++++++++ game/renderer_polygon_3d/polygon_model.cpp | 5 ++--- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 1c4ab77..9208d91 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ tests/tests *.swp *.core vgcore* +.cache diff --git a/game/game_window.hpp b/game/game_window.hpp index daf06ae..0ecf84a 100644 --- a/game/game_window.hpp +++ b/game/game_window.hpp @@ -51,8 +51,6 @@ class GameWindow : public endofthejedi::GLWindow { void resize() override { - //std::cout<<"resize()" << std::endl; - glViewport(0, 0, getwidth(), getheight()); // resize the game diff --git a/game/opengl.cpp b/game/opengl.cpp index a64cb36..8fc8a6b 100644 --- a/game/opengl.cpp +++ b/game/opengl.cpp @@ -99,7 +99,15 @@ namespace endofthejedi { m_width = attribs.width; m_height = attribs.height; resize(); + } else if (event.type == ConfigureNotify) { + XConfigureEvent xce = event.xconfigure; + if ((unsigned int)xce.width != m_width|| + (unsigned int)xce.height != m_height) { + m_width = xce.width; + m_height = xce.height; + resize(); + } } else if (event.type == ClientMessage) { if (event.xclient.data.l[0] == (int) m_atomWmDeleteWindow) { stop(); diff --git a/game/renderer_polygon_3d/polygon_model.cpp b/game/renderer_polygon_3d/polygon_model.cpp index de2895f..3d6d1fb 100644 --- a/game/renderer_polygon_3d/polygon_model.cpp +++ b/game/renderer_polygon_3d/polygon_model.cpp @@ -1,6 +1,7 @@ #include "polygon_model.hpp" #include +#include namespace endofthejedi { PolygonModel::PolygonModel(const std::string &filename) @@ -99,9 +100,7 @@ namespace endofthejedi { return false; } - aiNode *node = scene->mRootNode; - const aiMesh* mesh = scene->mMeshes[node->mMeshes[0]]; - + const aiMesh* mesh = scene->mMeshes[0]; // 3 vertices per face, 3 floats per vertex m_numVertices = mesh->mNumFaces*3;