Compare commits

...

3 Commits

9 changed files with 49 additions and 124 deletions

BIN
res/gui/crosschair.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 B

BIN
res/gui/polygun_header.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 661 B

View File

@ -27,11 +27,9 @@ SOFTWARE.
#include "game/audio/audio.hpp"
#include "common/logger.hpp"
#include "game/world/chunk_renderer.hpp"
#include "game/screens/main_menu_screen.hpp"
using namespace polygun::renderer;
using namespace polygun::world;
static int sizex = SCR_WIDTH, sizey = SCR_HEIGHT;

View File

@ -82,3 +82,17 @@ void GUIRenderer::fill_rect(const glm::vec2& pos, const glm::vec2& size, const g
mesh_renderer->render(m_rect_mesh, color);
mesh_renderer->set_alpha_blending_mode(false);
}
void GUIRenderer::render_texture(const glm::vec2& pos, Texture* texture, const glm::vec2& scale, float angle, const glm::vec4& color) {
MeshRenderer* mesh_renderer = m_master_renderer->get_mesh_renderer();
mesh_renderer->set_camera(&m_camera);
mesh_renderer->set_shader(m_textured_shader);
//mesh_renderer->set_alpha_blending_mode(true);
mesh_renderer->set_3d_rendering_mode(false);
mesh_renderer->translate(pos);
mesh_renderer->scale(scale);
mesh_renderer->rotate(glm::vec2(1, 0), angle);
mesh_renderer->render(m_rect_mesh, color);
//mesh_renderer->set_alpha_blending_mode(false);
}

View File

@ -32,13 +32,15 @@ SOFTWARE.
#include "game/renderer/shader.hpp"
#include "game/renderer/mesh.hpp"
#include "game/renderer/texture.hpp"
#include "game/renderer/gui_renderer.hpp"
#if defined(BUILD_SERVER)
#include "server/server.hpp"
#endif
using namespace polygun::screens;
int x_d, y_d, z_d, id_d;
static int x_d, y_d, z_d;
static unsigned id_d;
static const std::vector<float> vertices = {
-0.1f , -0.1f, -0.1f,
@ -127,6 +129,12 @@ static const std::vector<float> uvs={
0.0f, 0.0f,
0.0f, 1.0f
};
static void scroll_callback(GLFWwindow* window, double xoffset, double yoffset) {
//std::cout << "scroll_callback" << std::endl;
// change id_d
if(id_d != sizeof(polygun::world::nodes) / sizeof(polygun::world::nodes[0]) && yoffset > 0 || id_d != 0 && yoffset < 0)
id_d += yoffset;
}
GameSessionScreen::GameSessionScreen(const std::string& ip, unsigned short port, const std::string& player_nick, bool start_server) :
@ -147,25 +155,7 @@ GameSessionScreen::GameSessionScreen(const std::string& ip, unsigned short port,
m_game_state(GameState::GAME_STATE_JOINING),
m_texture_atlas()
{}
/*
class GUIRenderer {
public:
GUIRenderer(MasterRenderer* master_renderer);
virtual ~GUIRenderer();
void on_viewport_resize(int width, int height);
virtual void fill_rect(const glm::vec2& pos, const glm::vec2& size, const glm::vec4& color, float angle = 0);
virtual void render_texture(const glm::vec2& pos, Texture* texture, const glm::vec2& scale = glm::vec2(1, 1), float angle = 0, const glm::vec4& color = glm::vec4(1, 1, 1, 1)) = 0;
protected:
MasterRenderer* m_master_renderer;
Shader* m_textured_shader;
Shader* m_solid_shader;
Mesh* m_rect_mesh;
OrthoCamera m_camera;
};
*/
void GameSessionScreen::begin() {
#if defined(BUILD_SERVER)
if(m_start_server) {
@ -182,7 +172,6 @@ void GameSessionScreen::begin() {
indices.push_back((int)i/3);
m_node_mesh->load_from_memory(vertices, indices, uvs);
//for(int i = 0; i<6; i++) {
for(int i = 0; i< sizeof(world::nodes) / sizeof(world::nodes[0]); i++) {
m_texture_atlas[i] = m_engine->get_master_renderer().create_texture();
if(!m_texture_atlas[i]->load_from_file(world::nodes[i].texture))
@ -190,6 +179,7 @@ void GameSessionScreen::begin() {
}
glfwSetCursorPosCallback(m_engine->get_window(), m_camera.mouse_callback);
glfwSetScrollCallback(m_engine->get_window(), scroll_callback);
glfwSetInputMode(m_engine->get_window(), GLFW_CURSOR, GLFW_CURSOR_DISABLED);
m_engine->get_mesh_renderer()->set_shader(m_chunk_shader);
@ -200,7 +190,7 @@ void GameSessionScreen::begin() {
m_connection_thread.reset(new std::thread(&GameSessionScreen::connection_thread_func, this));
}
static float clearcolor[3] = { 1.0f, 1.0f, 1.0f };
static float clearcolor[3] = { 0.0f, 0.0f, 0.0f };
void GameSessionScreen::render() {
m_engine->get_master_renderer().clear_screen(clearcolor[0], clearcolor[1], clearcolor[2]);
// rendering
@ -228,6 +218,11 @@ void GameSessionScreen::render() {
case GameState::GAME_STATE_FINISHED:
break;
case GameState::GAME_STATE_RUNNING:{
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
renderer::MeshRenderer* mesh_renderer = m_engine->get_mesh_renderer();
mesh_renderer->set_3d_rendering_mode(true);
for (unsigned int x = 0; x < 32; x++) {
@ -246,11 +241,9 @@ void GameSessionScreen::render() {
}
}
// imgui
m_engine->get_gui_renderer()->render_texture(glm::vec2(1,1), m_texture_atlas[id_d+1], glm::vec2(10,10), 0.0f, glm::vec4(1.0f,1.0f,1.0f,1.0f));
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// imgui
ImGui::Begin("Debug");
@ -268,8 +261,6 @@ void GameSessionScreen::render() {
ImGui::Text("Player Pos: %.3f, %.3f, %.3f", m_camera.m_position.x, m_camera.m_position.y, m_camera.m_position.z);
// Camera rot
ImGui::Text("Player Rot: %.3f, %.3f", m_camera.m_yaw, m_camera.m_pitch);
ImGui::InputInt("ID", &id_d);
ImGui::InputInt("X", &x_d);
ImGui::InputInt("Y", &y_d);
ImGui::InputInt("Z", &z_d);
@ -277,18 +268,14 @@ void GameSessionScreen::render() {
// camera fov
ImGui::InputFloat("FOV", &m_camera.m_fov);
if (ImGui::Button("Place Block")) {
m_chnk.add_node(id_d, glm::vec3(x_d, y_d, z_d));
}
if (ImGui::Button("Place Block"))
m_chnk.add_node(id_d+1, glm::vec3(x_d, y_d, z_d));
ImGui::NewLine();
if(ImGui::Button("Quit Game"))
m_engine->get_screen_manager().pop_screen();
// clear color chooser
//define clearcolor
ImGui::ColorEdit3("clear color", (float*)&clearcolor);
ImGui::End();
@ -330,6 +317,12 @@ void GameSessionScreen::update(double delta) {
m_is_esc_pressed = false;
// right mouse button click check then m_chnk.add_node(id_d+1, glm::vec3(x_d, y_d, z_d));
if (glfwGetMouseButton(m_engine->get_window(), GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS) {
m_chnk.add_node(id_d+1, glm::vec3(x_d, y_d, z_d));
}
if (glfwGetKey(m_engine->get_window(), GLFW_KEY_W) == GLFW_PRESS) {
m_camera.process_movement(polygun::engine::FORWARD, delta);
m_engine->get_mesh_renderer()->set_camera(&m_camera);
@ -455,4 +448,4 @@ void GameSessionScreen::show_imgui_error_message(const std::string& title, const
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
ImGui::EndFrame();
}
}

View File

@ -37,6 +37,8 @@ void MainMenuScreen::begin() {
memset(m_player_nick, 0, sizeof(m_player_nick));
ImGui::SetNextWindowSize(ImVec2(340, 200));
logo_texture = m_engine->get_master_renderer().create_texture();
logo_texture->load_from_file("res/gui/polygun_header.png");
}
void MainMenuScreen::render() {
@ -44,6 +46,8 @@ void MainMenuScreen::render() {
// FIXME: This main menu should be replaced as soon as possible after our own
// GUI system is implemented
m_engine->get_gui_renderer()->render_texture(glm::vec2(50,200), logo_texture, glm::vec2(10,15), 180, glm::vec4(1,1,1,1));
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
@ -65,6 +69,7 @@ void MainMenuScreen::render() {
m_engine->get_screen_manager().push_screen(std::move(game_session_screen));
}
ImGui::NewLine();
ImGui::Text("Host game");
#if defined(BUILD_SERVER)

View File

@ -26,6 +26,7 @@ SOFTWARE.
#define POLYGUN_SCREENS_MAIN_MENU_SCREEN_HPP
#include "game/engine/screen.hpp"
#include "game/renderer/texture.hpp"
namespace polygun::screens {
class MainMenuScreen final : public engine::Screen {
@ -41,6 +42,7 @@ namespace polygun::screens {
char m_multiplayer_ip[46]; // Max IPv6 address length (45) + null terminator
int m_multiplayer_port;
char m_player_nick[256];
renderer::Texture* logo_texture;
};
}

View File

@ -1,53 +0,0 @@
#include "game/world/chunk_renderer.hpp"
#include "common/logger.hpp"
#include "game/renderer/shader.hpp"
#include "game/renderer/mesh.hpp"
#include "game/engine/engine.hpp"
namespace polygun::world {
ChunkRenderer::ChunkRenderer(engine::Engine& engine) :
texture(0),
chunk_shader(engine.get_master_renderer().create_shader()),
mesh(engine.get_master_renderer().create_mesh())
{
chunk_shader->load_from_file("chunk");
}
ChunkRenderer::~ChunkRenderer() {
delete chunk_shader;
delete mesh;
}
void ChunkRenderer::init() {/*
float vertices[] = {
// Add your vertex data here
};
GLsizei v_size = sizeof(vertices);
GLuint indices[] = {
// Add your indices data here
};
GLsizei i_size = sizeof(indices);
vertex_array = polygun::renderer::VertexArray(vertices, v_size, indices, i_size);
// Load and configure textures here
chunk_shader.bind();
chunk_shader.set_uniform("texture", 0);*/
}
void ChunkRenderer::render(const glm::mat4& view, const glm::mat4& projection) {
/*
Note: Temporarily commented out ~mrkubax10
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
chunk_shader.bind();
chunk_shader.set_uniform("projection", projection);
chunk_shader.set_uniform("view", view);
vertex_array.draw_elements();*/
}
}

View File

@ -1,34 +0,0 @@
#ifndef POLYGUN_ENGINE_CHUNK_RENDERER_HPP
#define POLYGUN_ENGINE_CHUNK_RENDERER_HPP
#include <glm/glm.hpp>
#include "game/world/chunk.hpp"
namespace polygun::renderer {
class Shader;
class Mesh;
}
namespace polygun::engine {
class Engine;
}
namespace polygun::world {
class ChunkRenderer {
public:
ChunkRenderer(engine::Engine& engine);
~ChunkRenderer();
void init();
void render(const glm::mat4& view, const glm::mat4& projection);
private:
unsigned int texture;
renderer::Shader* chunk_shader;
renderer::Mesh* mesh;
};
}
#endif //POLYGUN_ENGINE_CHUNK_RENDERER_HPP