diff --git a/README.md b/README.md index 1ee271e9..ceffc697 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ cmake ../ cmake --build . ``` -## Instal libs: +## Install libs: #### Debian-based distro: `$ sudo apt install libglfw3-dev libglfw3 libglew-dev libglm-dev libpng-dev libopenal-dev` diff --git a/src/constants.h b/src/constants.h index 988ce2fb..49a97749 100644 --- a/src/constants.h +++ b/src/constants.h @@ -4,6 +4,12 @@ #include #include "typedefs.h" +#define ENGINE_VERSION_MAJOR 0 +#define ENGINE_VERSION_MINOR 15 +#define STR_(x) #x +#define STR(x) STR_(x) +#define ENGINE_VERSION STR(ENGINE_VERSION_MAJOR) "." STR(ENGINE_VERSION_MINOR) + #define CHUNK_W 16 #define CHUNK_H 256 #define CHUNK_D 16 diff --git a/src/frontend/gui/controls.cpp b/src/frontend/gui/controls.cpp index 4f09573a..b9dba5f9 100644 --- a/src/frontend/gui/controls.cpp +++ b/src/frontend/gui/controls.cpp @@ -65,10 +65,26 @@ Button::Button(shared_ptr content, glm::vec4 padding) : Panel(vec2(32,32 Button::Button(wstring text, glm::vec4 padding) : Panel(vec2(32,32), padding, 0) { Label* label = new Label(text); label->align(Align::center); - add(shared_ptr(label)); + this->label = shared_ptr(label); + add(this->label); scrollable(false); } +void Button::text(std::wstring text) { + if (label) { + Label* label = (Label*)(this->label.get()); + label->text(text); + } +} + +wstring Button::text() const { + if (label) { + Label* label = (Label*)(this->label.get()); + return label->text(); + } + return L""; +} + void Button::drawBackground(Batch2D* batch, Assets* assets) { vec2 coord = calcCoord(); batch->texture(nullptr); diff --git a/src/frontend/gui/controls.h b/src/frontend/gui/controls.h index 0ef15269..fe558271 100644 --- a/src/frontend/gui/controls.h +++ b/src/frontend/gui/controls.h @@ -45,6 +45,7 @@ namespace gui { glm::vec4 hoverColor {0.05f, 0.1f, 0.15f, 0.75f}; glm::vec4 pressedColor {0.0f, 0.0f, 0.0f, 0.95f}; std::vector actions; + std::shared_ptr label = nullptr; public: Button(std::shared_ptr content, glm::vec4 padding=glm::vec4(2.0f)); Button(std::wstring text, glm::vec4 padding=glm::vec4(2.0f)); @@ -55,6 +56,9 @@ namespace gui { virtual void mouseRelease(GUI*, int x, int y) override; virtual Button* listenAction(onaction action); + + virtual void text(std::wstring text); + virtual std::wstring text() const; }; class TextBox : public Panel { diff --git a/src/frontend/world_render.cpp b/src/frontend/world_render.cpp index 3764cebc..f4596c22 100644 --- a/src/frontend/world_render.cpp +++ b/src/frontend/world_render.cpp @@ -182,16 +182,38 @@ void WorldRenderer::draw(const GfxContext& pctx, Camera* camera, bool occlusion) if (coord.z < 0) coord.z--; int cx = floordiv((int)coord.x, CHUNK_W); int cz = floordiv((int)coord.z, CHUNK_D); - for (int i = 0; i < CHUNK_W; i++) { - lineBatch->line(cx * CHUNK_W + i, 0, cz * CHUNK_D, - cx * CHUNK_W + i, CHUNK_H, cz * CHUNK_D, 0,0,1,0.5f); - lineBatch->line(cx * CHUNK_W + i, 0, (cz+1) * CHUNK_D, - cx * CHUNK_W + i, CHUNK_H, (cz+1) * CHUNK_D, 0,0,1,0.5f); + /*corner*/ { + lineBatch->line( cx * CHUNK_W, 0, cz * CHUNK_D, + cx * CHUNK_W, CHUNK_H, cz * CHUNK_D, 0.8f, 0, 0.8f, 1); + lineBatch->line( cx * CHUNK_W, 0, (cz+1) * CHUNK_D, + cx * CHUNK_W, CHUNK_H, (cz+1) * CHUNK_D, 0.8f, 0, 0.8f, 1); + lineBatch->line((cx+1) * CHUNK_W, 0, cz * CHUNK_D, + (cx+1) * CHUNK_W, CHUNK_H, cz * CHUNK_D, 0.8f, 0, 0.8f, 1); + lineBatch->line((cx+1) * CHUNK_W, 0, (cz+1) * CHUNK_D, + (cx+1) * CHUNK_W, CHUNK_H, (cz+1) * CHUNK_D, 0.8f, 0, 0.8f, 1); + } + for (int i = 2; i < CHUNK_W; i+=2) { + lineBatch->line( cx * CHUNK_W + i, 0, cz * CHUNK_D, + cx * CHUNK_W + i, CHUNK_H, cz * CHUNK_D, 0, 0, 0.8f, 1); + lineBatch->line( cx * CHUNK_W + i, 0, (cz+1) * CHUNK_D, + cx * CHUNK_W + i, CHUNK_H, (cz+1) * CHUNK_D, 0, 0, 0.8f, 1); + } + for (int i = 2; i < CHUNK_D; i+=2) { + lineBatch->line( cx * CHUNK_W, 0, cz * CHUNK_D + i, + cx * CHUNK_W, CHUNK_H, cz * CHUNK_D + i, 0.8f, 0, 0, 1); + lineBatch->line((cx+1) * CHUNK_W, 0, cz * CHUNK_D + i, + (cx+1) * CHUNK_W, CHUNK_H, cz * CHUNK_D + i, 0.8f, 0, 0, 1); + } + for (int i=0; i < CHUNK_H; i+=2){ + lineBatch->line( cx * CHUNK_W, i, cz * CHUNK_D, + cx * CHUNK_W, i, (cz+1) * CHUNK_D, 0, 0.8f, 0, 1); + lineBatch->line( cx * CHUNK_W, i, (cz+1) * CHUNK_D, + (cx+1) * CHUNK_W, i, (cz+1) * CHUNK_D, 0, 0.8f, 0, 1); + lineBatch->line((cx+1) * CHUNK_W, i, (cz+1) * CHUNK_D, + (cx+1) * CHUNK_W, i, cz * CHUNK_D, 0, 0.8f, 0, 1); + lineBatch->line((cx+1) * CHUNK_W, i, cz * CHUNK_D, + cx * CHUNK_W, i, cz * CHUNK_D, 0, 0.8f, 0, 1); - lineBatch->line(cx * CHUNK_W, 0, cz * CHUNK_D+i, - cx * CHUNK_W, CHUNK_H, cz * CHUNK_D+i, 1,0,0,0.5f); - lineBatch->line((cx+1) * CHUNK_W, 0, cz * CHUNK_D+i, - (cx+1) * CHUNK_W, CHUNK_H, cz * CHUNK_D+i, 1,0,0,0.5f); } lineBatch->render(); } diff --git a/src/graphics/Framebuffer.cpp b/src/graphics/Framebuffer.cpp index f08a55f4..ab980b1b 100644 --- a/src/graphics/Framebuffer.cpp +++ b/src/graphics/Framebuffer.cpp @@ -3,46 +3,24 @@ #include #include "Texture.h" -Framebuffer::Framebuffer(int width, int height) : width(width), height(height) { - // glGenFramebuffers(1, &fbo); - // bind(); - // GLuint tex; - // glGenTextures(1, &tex); - // // glBindTexture(GL_TEXTURE_2D, tex); - // glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, tex); - // // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); - // glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGB, width, height, GL_TRUE); - // glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - // glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - // glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - // glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - // glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, tex, 0); - // texture = new Texture(tex, width, height); - // glGenRenderbuffers(1, &depth); - // glBindRenderbuffer(GL_RENDERBUFFER, depth); - // glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT24, width, height); - // // glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height); - // glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth); - // unbind(); - - - // bind(); - // glGenFramebuffers(1, &fbo); - // // create a multisampled color attachment texture - // unsigned int textureColorBufferMultiSampled; - // glGenTextures(1, &textureColorBufferMultiSampled); - // glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, textureColorBufferMultiSampled); - // glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGB, width, height, GL_TRUE); - // glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); - // glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, textureColorBufferMultiSampled, 0); - // // create a (also multisampled) renderbuffer object for depth and stencil attachments - // unsigned int rbo; - // glGenRenderbuffers(1, &rbo); - // glBindRenderbuffer(GL_RENDERBUFFER, rbo); - // glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8, width, height); - // glBindRenderbuffer(GL_RENDERBUFFER, 0); - // glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo); - // unbind(); +Framebuffer::Framebuffer(uint width, uint height) : width(width), height(height) { + glGenFramebuffers(1, &fbo); + bind(); + GLuint tex; + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D, tex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0); + texture = new Texture(tex, width, height); + glGenRenderbuffers(1, &depth); + glBindRenderbuffer(GL_RENDERBUFFER, depth); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth); + unbind(); } Framebuffer::~Framebuffer() { @@ -56,4 +34,4 @@ void Framebuffer::bind() { void Framebuffer::unbind() { glBindFramebuffer(GL_FRAMEBUFFER, 0); -} +} \ No newline at end of file diff --git a/src/graphics/Framebuffer.h b/src/graphics/Framebuffer.h index 3fd889f2..0214d0c2 100644 --- a/src/graphics/Framebuffer.h +++ b/src/graphics/Framebuffer.h @@ -1,16 +1,18 @@ #ifndef SRC_GRAPHICS_FRAMEBUFFER_H_ #define SRC_GRAPHICS_FRAMEBUFFER_H_ +#include "../typedefs.h" + class Texture; class Framebuffer { - unsigned int fbo; - unsigned int depth; + uint fbo; + uint depth; public: - int width; - int height; + uint width; + uint height; Texture* texture; - Framebuffer(int width, int height); + Framebuffer(uint width, uint height); ~Framebuffer(); void bind(); diff --git a/src/settings.h b/src/settings.h index b4c39ba8..9208f36e 100644 --- a/src/settings.h +++ b/src/settings.h @@ -3,6 +3,7 @@ #include +#include "constants.h" #include "typedefs.h" struct DisplaySettings { @@ -17,7 +18,7 @@ struct DisplaySettings { /* GLFW swap interval value, 0 - unlimited fps, 1 - vsync*/ int swapInterval = 1; /* Window title */ - const char* title = "VoxelEngine-Cpp v0.14"; + const char* title = "VoxelEngine-Cpp v" ENGINE_VERSION; }; struct ChunksSettings { diff --git a/src/window/Window.cpp b/src/window/Window.cpp index 8efb4d6e..75047d40 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -14,6 +14,8 @@ std::stack Window::scissorStack; vec4 Window::scissorArea; uint Window::width = 0; uint Window::height = 0; +int Window::posX = 0; +int Window::posY = 0; void cursor_position_callback(GLFWwindow*, double xpos, double ypos) { if (Events::_cursor_started) { @@ -58,11 +60,15 @@ void scroll_callback(GLFWwindow*, double xoffset, double yoffset) { Events::scroll += yoffset; } +bool Window::isMaximized() { + return glfwGetWindowAttrib(window, GLFW_MAXIMIZED); +} + void window_size_callback(GLFWwindow*, int width, int height) { glViewport(0, 0, width, height); Window::width = width; Window::height = height; - if (!Window::isFullscreen()) { + if (!Window::isFullscreen() && !Window::isMaximized()) { Window::getSettings()->width = width; Window::getSettings()->height = height; } @@ -115,16 +121,11 @@ int Window::initialize(DisplaySettings& settings){ glfwSetWindowSizeCallback(window, window_size_callback); glfwSetCharCallback(window, character_callback); glfwSetScrollCallback(window, scroll_callback); - - GLFWmonitor* monitor = glfwGetPrimaryMonitor(); - const GLFWvidmode* mode = glfwGetVideoMode(monitor); if (settings.fullscreen) { + GLFWmonitor* monitor = glfwGetPrimaryMonitor(); + const GLFWvidmode* mode = glfwGetVideoMode(monitor); glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, GLFW_DONT_CARE); } - else { - tryToMaximize(window, monitor); - } - glfwSwapInterval(settings.swapInterval); return 0; } @@ -218,11 +219,12 @@ void Window::toggleFullscreen(){ if (Events::_cursor_locked) Events::toggleCursor(); if (settings->fullscreen) { + glfwGetWindowPos(window, &posX, &posY); glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, GLFW_DONT_CARE); } else { - glfwSetWindowMonitor(window, nullptr, 0, 0, settings->width, settings->height, GLFW_DONT_CARE); - tryToMaximize(window, monitor); + glfwSetWindowMonitor(window, nullptr, posX, posY, settings->width, settings->height, GLFW_DONT_CARE); + glfwSetWindowAttrib(window, GLFW_MAXIMIZED, GLFW_FALSE); } double xPos, yPos; @@ -259,10 +261,10 @@ bool Window::tryToMaximize(GLFWwindow* window, GLFWmonitor* monitor) { glm::ivec4 workArea(0); glfwGetWindowFrameSize(window, &windowFrame.x, &windowFrame.y, &windowFrame.z, &windowFrame.w); glfwGetMonitorWorkarea(monitor, &workArea.x, &workArea.y, &workArea.z, &workArea.w); - if (Window::width > workArea.z) Window::width = workArea.z; - if (Window::height > workArea.w) Window::height = workArea.w; - if (Window::width >= workArea.z - (windowFrame.x + windowFrame.z) && - Window::height >= workArea.w - (windowFrame.y + windowFrame.w)) { + if (Window::width > (uint)workArea.z) Window::width = (uint)workArea.z; + if (Window::height > (uint)workArea.w) Window::height = (uint)workArea.w; + if (Window::width >= (uint)(workArea.z - (windowFrame.x + windowFrame.z)) && + Window::height >= (uint)(workArea.w - (windowFrame.y + windowFrame.w))) { glfwMaximizeWindow(window); return true; } diff --git a/src/window/Window.h b/src/window/Window.h index 4531c77e..cfc0a9ae 100644 --- a/src/window/Window.h +++ b/src/window/Window.h @@ -22,6 +22,8 @@ class Window { static bool tryToMaximize(GLFWwindow* window, GLFWmonitor* monitor); public: + static int posX; + static int posY; static uint width; static uint height; static int initialize(DisplaySettings& settings); @@ -35,6 +37,7 @@ public: static void swapInterval(int interval); static void toggleFullscreen(); static bool isFullscreen(); + static bool isMaximized(); static void pushScissor(glm::vec4 area); static void popScissor();