grouped files in subdirs.
This commit is contained in:
parent
7d8585c5d9
commit
aedda9d48e
14 changed files with 281 additions and 11 deletions
|
@ -8,12 +8,13 @@ set(GAME_SRC
|
||||||
main.cpp
|
main.cpp
|
||||||
opengl.cpp
|
opengl.cpp
|
||||||
glclasses.cpp
|
glclasses.cpp
|
||||||
renderer.cpp
|
|
||||||
game_window.cpp
|
game_window.cpp
|
||||||
renderer_polygon_2d.cpp
|
renderer.cpp
|
||||||
renderer_polygon_3d.cpp
|
renderer_polygon_2d/renderer_polygon_2d.cpp
|
||||||
renderer_ray_tracer.cpp
|
renderer_polygon_3d/renderer_polygon_3d.cpp
|
||||||
session.cpp
|
renderer_ray_tracer/renderer_ray_tracer.cpp
|
||||||
|
|
||||||
|
network/session.cpp
|
||||||
|
|
||||||
util.cpp
|
util.cpp
|
||||||
game.cpp
|
game.cpp
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
#include "opengl.hpp"
|
#include "opengl.hpp"
|
||||||
#include "renderer.hpp"
|
#include "renderer.hpp"
|
||||||
#include "renderer_polygon_2d.hpp"
|
|
||||||
#include "renderer_polygon_3d.hpp"
|
#include "renderer_polygon_2d/renderer_polygon_2d.hpp"
|
||||||
#include "renderer_ray_tracer.hpp"
|
#include "renderer_polygon_3d/renderer_polygon_3d.hpp"
|
||||||
|
#include "renderer_ray_tracer/renderer_ray_tracer.hpp"
|
||||||
|
|
||||||
#include "game.hpp"
|
#include "game.hpp"
|
||||||
|
|
||||||
|
@ -20,8 +21,8 @@ class GameWindow : public endofthejedi::GLWindow {
|
||||||
private:
|
private:
|
||||||
Game* m_game;
|
Game* m_game;
|
||||||
//endofthejedi::RendererPolygon2d m_renderer;
|
//endofthejedi::RendererPolygon2d m_renderer;
|
||||||
endofthejedi::RendererPolygon3d m_renderer;
|
//endofthejedi::RendererPolygon3d m_renderer;
|
||||||
//endofthejedi::RendererRayTracer m_renderer;
|
endofthejedi::RendererRayTracer m_renderer;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void init() override {
|
void init() override {
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#include "opengl.hpp"
|
#include "opengl.hpp"
|
||||||
#include "game_window.hpp"
|
#include "game_window.hpp"
|
||||||
#include "server.hpp"
|
#include "network/server.hpp"
|
||||||
#include "options.hpp"
|
#include "options.hpp"
|
||||||
|
|
||||||
uint64_t optionsFlags;
|
uint64_t optionsFlags;
|
||||||
|
|
81
game/renderer_polygon_2d/renderer_polygon_2d.cpp
Normal file
81
game/renderer_polygon_2d/renderer_polygon_2d.cpp
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
#include "renderer_polygon_2d.hpp"
|
||||||
|
|
||||||
|
namespace endofthejedi {
|
||||||
|
void RendererPolygon2d::drawCircle(float x, float y, float radius,
|
||||||
|
float r, float g, float b,
|
||||||
|
int numSides) {
|
||||||
|
glBegin(GL_TRIANGLE_FAN);
|
||||||
|
glColor3f(r, g, b);
|
||||||
|
glVertex2f(x, y); // center of circle
|
||||||
|
for (int i = 0; i <= numSides; i++) {
|
||||||
|
glVertex2f(x + (radius * cos(i * 2 * M_PI / numSides)),
|
||||||
|
y + (radius * sin(i * 2 * M_PI / numSides)));
|
||||||
|
}
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RendererPolygon2d::drawShip(const glm::vec2 &pos,
|
||||||
|
float radius) {
|
||||||
|
// std::cout<<"draw ship @ " << pos.x << ", " << pos.y << std::endl;
|
||||||
|
glm::vec3 color = glm::vec3(0.2, 1.0, 0.3);
|
||||||
|
|
||||||
|
drawCircle(pos.x, pos.y, radius, color.x, color.y, color.z, 12);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RendererPolygon2d::drawPlanet(const glm::vec2 &pos,
|
||||||
|
float radius) {
|
||||||
|
glm::vec3 color = glm::vec3(0.7, 0.1, 0.2);
|
||||||
|
|
||||||
|
// std::cout<<"draw planet @ " << pos.x << ", " << pos.y << std::endl;
|
||||||
|
drawCircle(pos.x, pos.y, radius, color.x, color.y, color.z, 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RendererPolygon2d::drawMissile(const glm::vec2 &pos) {
|
||||||
|
glm::vec3 color = glm::vec3(1.0, 1.0, 0.3);
|
||||||
|
drawCircle(pos.x, pos.y, 0.01, color.x, color.y, color.z, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RendererPolygon2d::drawTrace(const game::Trace *trace) {
|
||||||
|
for (const game::Trace::TracePoint &p : trace->points) {
|
||||||
|
glm::vec3 color = glm::vec3(0.1, 0.3, 1.0) / (1.0f + 500.0f * p.speed);
|
||||||
|
drawCircle(p.position.x, p.position.y, 0.005, color.x, color.y, color.z,
|
||||||
|
3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RendererPolygon2d::drawExplosion(
|
||||||
|
const game::Explosion *explosion) {
|
||||||
|
// TODO: transparent
|
||||||
|
// TODO: with glow in the middle
|
||||||
|
float r = explosion->maxRadius * (explosion->age / explosion->maxAge);
|
||||||
|
|
||||||
|
// TODO: transparency?
|
||||||
|
glm::vec3 color = glm::vec3(1.0, 0.9, 0.1);
|
||||||
|
drawCircle(explosion->position.x, explosion->position.y, r, color.x,
|
||||||
|
color.y, color.z, 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RendererPolygon2d::render(const game::State *state) {
|
||||||
|
for (const game::Planet *planet : state->planets) {
|
||||||
|
drawPlanet(planet->position, planet->radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const game::Trace *trace : state->traces) {
|
||||||
|
drawTrace(trace);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const game::Explosion *explosion : state->explosions) {
|
||||||
|
drawExplosion(explosion);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const game::Ship *ship : state->ships) {
|
||||||
|
drawShip(ship->position, ship->radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const game::Player *player : state->players) {
|
||||||
|
for (const game::Missile *missile : player->missiles) {
|
||||||
|
drawMissile(missile->position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
34
game/renderer_polygon_2d/renderer_polygon_2d.hpp
Normal file
34
game/renderer_polygon_2d/renderer_polygon_2d.hpp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "renderer.hpp"
|
||||||
|
|
||||||
|
#include "glclasses.hpp"
|
||||||
|
|
||||||
|
#include "game.hpp"
|
||||||
|
#include "state/trace.hpp"
|
||||||
|
#include "state/object.hpp"
|
||||||
|
#include "state/missile.hpp"
|
||||||
|
#include "state/player.hpp"
|
||||||
|
#include "state/planet.hpp"
|
||||||
|
#include "state/ship.hpp"
|
||||||
|
#include "state/explosion.hpp"
|
||||||
|
|
||||||
|
namespace endofthejedi {
|
||||||
|
|
||||||
|
class RendererPolygon2d : Renderer {
|
||||||
|
private:
|
||||||
|
void drawCircle(float x, float y, float radius, float r, float g,
|
||||||
|
float b, int numSides = 12);
|
||||||
|
|
||||||
|
void drawShip(const glm::vec2 &pos, float radius);
|
||||||
|
void drawPlanet(const glm::vec2 &pos, float radius);
|
||||||
|
void drawMissile(const glm::vec2 &pos);
|
||||||
|
void drawTrace(const game::Trace *trace);
|
||||||
|
void drawExplosion(const game::Explosion *explosion);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
public:
|
||||||
|
void render(const game::State *state) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
17
game/renderer_polygon_3d/renderer_polygon_3d.cpp
Normal file
17
game/renderer_polygon_3d/renderer_polygon_3d.cpp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#include "renderer_polygon_3d.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace endofthejedi {
|
||||||
|
void RendererPolygon3d::setup()
|
||||||
|
{
|
||||||
|
std::cout<<"setup 3d" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RendererPolygon3d::render(const game::State *state)
|
||||||
|
{
|
||||||
|
(void) state;
|
||||||
|
|
||||||
|
//std::cout<<"render 3d" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
25
game/renderer_polygon_3d/renderer_polygon_3d.hpp
Normal file
25
game/renderer_polygon_3d/renderer_polygon_3d.hpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#include "renderer.hpp"
|
||||||
|
|
||||||
|
#include "glclasses.hpp"
|
||||||
|
|
||||||
|
#include "game.hpp"
|
||||||
|
|
||||||
|
#include "state/trace.hpp"
|
||||||
|
#include "state/object.hpp"
|
||||||
|
#include "state/missile.hpp"
|
||||||
|
#include "state/player.hpp"
|
||||||
|
#include "state/planet.hpp"
|
||||||
|
#include "state/ship.hpp"
|
||||||
|
#include "state/explosion.hpp"
|
||||||
|
|
||||||
|
namespace endofthejedi {
|
||||||
|
|
||||||
|
class RendererPolygon3d : Renderer {
|
||||||
|
private:
|
||||||
|
protected:
|
||||||
|
public:
|
||||||
|
void setup();
|
||||||
|
void render(const game::State *state) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
88
game/renderer_ray_tracer/renderer_ray_tracer.cpp
Normal file
88
game/renderer_ray_tracer/renderer_ray_tracer.cpp
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
#include "renderer_ray_tracer.hpp"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "glm/glm.hpp"
|
||||||
|
#include "glm/vec2.hpp"
|
||||||
|
#include "glm/vec3.hpp"
|
||||||
|
#include "glm/gtc/type_ptr.hpp"
|
||||||
|
|
||||||
|
static const char *vss =
|
||||||
|
#include "raycaster.vs"
|
||||||
|
;
|
||||||
|
|
||||||
|
static const char *fss =
|
||||||
|
#include "raycaster.fs"
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
namespace endofthejedi {
|
||||||
|
RendererRayTracer::RendererRayTracer() {
|
||||||
|
m_shader.load(vss, GL_VERTEX_SHADER);
|
||||||
|
m_shader.load(fss, GL_FRAGMENT_SHADER);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RendererRayTracer::render(const game::State *state) {
|
||||||
|
m_shader.bind();
|
||||||
|
|
||||||
|
std::vector<glm::vec3> positions;
|
||||||
|
std::vector<glm::vec4> colors;
|
||||||
|
std::vector<GLfloat> radii;
|
||||||
|
std::vector<GLfloat> reflections;
|
||||||
|
|
||||||
|
for (const game::Planet *planet : state->planets) {
|
||||||
|
positions.push_back(glm::vec3(planet->position, -5.0f));
|
||||||
|
radii.push_back(planet->radius);
|
||||||
|
colors.push_back(glm::vec4(1.0f, 0.0f, 0.0f, 0.5f));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const game::Ship *ship : state->ships) {
|
||||||
|
positions.push_back(glm::vec3(ship->position, -3.0f));
|
||||||
|
radii.push_back(ship->radius);
|
||||||
|
colors.push_back(glm::vec4(1.0f, 0.0f, 0.0f, 0.5f));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const game::Player *player : state->players) {
|
||||||
|
for (const game::Missile *missile : player->missiles) {
|
||||||
|
positions.push_back(glm::vec3(missile->position, -3.0f));
|
||||||
|
radii.push_back(0.01f);
|
||||||
|
colors.push_back(glm::vec4(1.0f, 0.0f, 0.0f, 0.5f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &pos : positions) {
|
||||||
|
pos.x *= 5;
|
||||||
|
pos.y *= 5;
|
||||||
|
}
|
||||||
|
for (auto &rad : radii) {
|
||||||
|
rad *= 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
for (const game::Trace *trace : state->traces) {
|
||||||
|
positions.push_back(glm::vec3(trace->position, -3.0f));
|
||||||
|
radii.push_back(trace->radius);
|
||||||
|
colors.push_back(glm::vec4(0.0f, 1.0f, 0.0f, 0.5f));
|
||||||
|
}*/
|
||||||
|
|
||||||
|
glUniform1f(m_shader.location("aspectratio"), 1.0f);
|
||||||
|
glUniform1i(m_shader.location("reflections"), 1);
|
||||||
|
glUniform3f(m_shader.location("l_position"), 0.6f, 0.1f, 0.0f);
|
||||||
|
glUniform1f(m_shader.location("l_radius"), 1.0f);
|
||||||
|
glUniform3fv(m_shader.location("s_positions"), positions.size(),
|
||||||
|
glm::value_ptr(positions[0]));
|
||||||
|
|
||||||
|
glUniform4fv(m_shader.location("s_colors"), colors.size(),
|
||||||
|
glm::value_ptr(colors[0]));
|
||||||
|
|
||||||
|
glUniform1fv(m_shader.location("s_radii"), radii.size(), &radii[0]);
|
||||||
|
glUniform1i(m_shader.location("s_length"), positions.size());
|
||||||
|
|
||||||
|
// render fullscreen quad with legacy opengl (too lazy, sorry)
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glVertex2f(-1.0f, -1.0f);
|
||||||
|
glVertex2f(1.0f, -1.0f);
|
||||||
|
glVertex2f(1.0f, 1.0f);
|
||||||
|
glVertex2f(-1.0f, 1.0f);
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
}
|
23
game/renderer_ray_tracer/renderer_ray_tracer.hpp
Normal file
23
game/renderer_ray_tracer/renderer_ray_tracer.hpp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "renderer.hpp"
|
||||||
|
|
||||||
|
#include "glclasses.hpp"
|
||||||
|
#include "game.hpp"
|
||||||
|
#include "state/planet.hpp"
|
||||||
|
#include "state/trace.hpp"
|
||||||
|
#include "state/player.hpp"
|
||||||
|
#include "state/ship.hpp"
|
||||||
|
|
||||||
|
namespace endofthejedi {
|
||||||
|
|
||||||
|
class RendererRayTracer: Renderer {
|
||||||
|
private:
|
||||||
|
Shader m_shader;
|
||||||
|
protected:
|
||||||
|
public:
|
||||||
|
RendererRayTracer();
|
||||||
|
void render(const game::State *state) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue