diff --git a/.gitignore b/.gitignore index 6013f5a905d5f985f97d9fd4f73d133d4b43e34d..e2a14a608ced625ac1a1bcd11c3e85b904f63ba7 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,4 @@ build/* include/* library/* vcpkg_installed/* -old/* - -assets/textures/* \ No newline at end of file +old/* \ No newline at end of file diff --git a/CMakelists.txt b/CMakelists.txt index 4ed6f26854f3a98e2dde36014ec43ca2c8e08846..ed662f71a8362be1f10ef677eb3c8ad91233b921 100644 --- a/CMakelists.txt +++ b/CMakelists.txt @@ -24,7 +24,7 @@ set(CMAKE_CXX_EXTENSIONS OFF) if(WIN32) option(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake") elseif(UNIX) - option(CMAKE_TOOLCHAIN_FILE "/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake") + #option(CMAKE_TOOLCHAIN_FILE "/amuhome/b20017738/Bureau/vcpkg/scripts/buildsystems/vcpkg.cmake") endif() #============================================================== @@ -35,8 +35,8 @@ set(SOURCES ${CMAKE_SOURCE_DIR}/source/) set(LIBRARY ${CMAKE_SOURCE_DIR}/library/) set(INCLUDE ${CMAKE_SOURCE_DIR}/include/) -set(VCPK_INCLUDE ${CMAKE_SOURCE_DIR}/vcpkg_installed/*/include) -set(VCPK_INCLUDE ${CMAKE_SOURCE_DIR}/vcpkg_installed/*/lib) +set(VCPKG_INCLUDE ${CMAKE_SOURCE_DIR}/vcpkg_installed/*/include) +set(VCPKG_LIB ${CMAKE_SOURCE_DIR}/vcpkg_installed/*/lib) #============================================================== # Build @@ -59,6 +59,10 @@ set_property(TARGET ${CURRENT_TARGET} PROPERTY RUNTIME_OUTPUT_DIRECTORY $<1:${CM target_include_directories(${CURRENT_TARGET} PRIVATE ${INCLUDE}) +#list(APPEND CMAKE_PREFIX_PATH "/amuhome/b20017738/Bureau/vcpkg/packages/glew_x64-linux") +#list(APPEND CMAKE_PREFIX_PATH "/amuhome/b20017738/Bureau/vcpkg/packages/glm_x64-linux") +#list(APPEND CMAKE_PREFIX_PATH "/amuhome/b20017738/Bureau/vcpkg/packages/imgui_x64-linux") + find_package(glfw3 REQUIRED) find_package(GLEW REQUIRED) find_package(glm CONFIG REQUIRED) diff --git a/assets/textures/Cube_Amber.png b/assets/textures/Cube_Amber.png new file mode 100644 index 0000000000000000000000000000000000000000..2818dc1c2e2ce58ac8d1c13f1ea554e000ea450c Binary files /dev/null and b/assets/textures/Cube_Amber.png differ diff --git a/assets/textures/Cube_Blue.png b/assets/textures/Cube_Blue.png new file mode 100644 index 0000000000000000000000000000000000000000..660ea2bcf6a491b02d8245636432892a96cac429 Binary files /dev/null and b/assets/textures/Cube_Blue.png differ diff --git a/assets/textures/Cube_Brown.png b/assets/textures/Cube_Brown.png new file mode 100644 index 0000000000000000000000000000000000000000..6625a70ebf229d0bd2531ebd3723c97dcac377d0 Binary files /dev/null and b/assets/textures/Cube_Brown.png differ diff --git a/assets/textures/Cube_Cyan.png b/assets/textures/Cube_Cyan.png new file mode 100644 index 0000000000000000000000000000000000000000..e154c1b9291be5f26b3735e77279271177ba376a Binary files /dev/null and b/assets/textures/Cube_Cyan.png differ diff --git a/assets/textures/Cube_Dark_Green.png b/assets/textures/Cube_Dark_Green.png new file mode 100644 index 0000000000000000000000000000000000000000..e2e446677e0be7233a32d5f4436d2b1b7df8d14d Binary files /dev/null and b/assets/textures/Cube_Dark_Green.png differ diff --git a/assets/textures/Cube_Grass.png b/assets/textures/Cube_Grass.png new file mode 100644 index 0000000000000000000000000000000000000000..bf967e698b61604ff8428348c9ad2d9d3b0e8538 Binary files /dev/null and b/assets/textures/Cube_Grass.png differ diff --git a/assets/textures/Cube_Gray.png b/assets/textures/Cube_Gray.png new file mode 100644 index 0000000000000000000000000000000000000000..a2057bc9e04b33cb9e494f72a35d2693da1e0047 Binary files /dev/null and b/assets/textures/Cube_Gray.png differ diff --git a/assets/textures/Cube_Grayy.png b/assets/textures/Cube_Grayy.png new file mode 100644 index 0000000000000000000000000000000000000000..405cb6f9309a3775a9d9cfc8137688ac33152514 Binary files /dev/null and b/assets/textures/Cube_Grayy.png differ diff --git a/assets/textures/Cube_Green.png b/assets/textures/Cube_Green.png new file mode 100644 index 0000000000000000000000000000000000000000..e863145c801b80978785b3f2a1949f24fc31f2e4 Binary files /dev/null and b/assets/textures/Cube_Green.png differ diff --git a/assets/textures/Cube_Greeny.png b/assets/textures/Cube_Greeny.png new file mode 100644 index 0000000000000000000000000000000000000000..7adbb641868ecf1fe99512d0dda3302e63b14abd Binary files /dev/null and b/assets/textures/Cube_Greeny.png differ diff --git a/assets/textures/Cube_Inverted.png b/assets/textures/Cube_Inverted.png new file mode 100644 index 0000000000000000000000000000000000000000..c88966e2a81981d7e9ad95375909d70e89289569 Binary files /dev/null and b/assets/textures/Cube_Inverted.png differ diff --git a/assets/textures/Cube_Inverted_2.png b/assets/textures/Cube_Inverted_2.png new file mode 100644 index 0000000000000000000000000000000000000000..8da98f7caf655f6813524717d75e8f8ca23d257c Binary files /dev/null and b/assets/textures/Cube_Inverted_2.png differ diff --git a/assets/textures/Cube_Magenta.png b/assets/textures/Cube_Magenta.png new file mode 100644 index 0000000000000000000000000000000000000000..d6c445d966448805ceb5301a6b7701676c0e31e9 Binary files /dev/null and b/assets/textures/Cube_Magenta.png differ diff --git a/assets/textures/Cube_Orange.png b/assets/textures/Cube_Orange.png new file mode 100644 index 0000000000000000000000000000000000000000..af4c2ecb3a372c602cd3a570464906733dbd230a Binary files /dev/null and b/assets/textures/Cube_Orange.png differ diff --git a/assets/textures/Cube_Pink.png b/assets/textures/Cube_Pink.png new file mode 100644 index 0000000000000000000000000000000000000000..5a7ea7ef1b519bb8751293c66699de4ec76c6155 Binary files /dev/null and b/assets/textures/Cube_Pink.png differ diff --git a/assets/textures/Cube_Purple.png b/assets/textures/Cube_Purple.png new file mode 100644 index 0000000000000000000000000000000000000000..10e017c1f432c1d9eab0a939a311bba880ee7b30 Binary files /dev/null and b/assets/textures/Cube_Purple.png differ diff --git a/assets/textures/Cube_Red.png b/assets/textures/Cube_Red.png new file mode 100644 index 0000000000000000000000000000000000000000..fa5264076cdce558b91dc109cc21cc587bbc3495 Binary files /dev/null and b/assets/textures/Cube_Red.png differ diff --git a/assets/textures/Cube_Redy.png b/assets/textures/Cube_Redy.png new file mode 100644 index 0000000000000000000000000000000000000000..a2e2022e42869b30ec3a07e20a981daac7ada6a2 Binary files /dev/null and b/assets/textures/Cube_Redy.png differ diff --git a/assets/textures/Cube_Saumon.png b/assets/textures/Cube_Saumon.png new file mode 100644 index 0000000000000000000000000000000000000000..e370b7ab8ddd84fbdf284149415e35ea06cdf66b Binary files /dev/null and b/assets/textures/Cube_Saumon.png differ diff --git a/assets/textures/Cube_Yellow.png b/assets/textures/Cube_Yellow.png new file mode 100644 index 0000000000000000000000000000000000000000..0f055da0c20cc1b2f3da0d12ef895ab2402b308e Binary files /dev/null and b/assets/textures/Cube_Yellow.png differ diff --git a/assets/textures/Cube_Yellowy.png b/assets/textures/Cube_Yellowy.png new file mode 100644 index 0000000000000000000000000000000000000000..0b29e005f793fc7f11c13b4b1c35904720274cac Binary files /dev/null and b/assets/textures/Cube_Yellowy.png differ diff --git a/source/engine/graphics/back/textures/TextureBuffer.cpp b/source/engine/graphics/back/textures/TextureBuffer.cpp index 1d020b3acb297474efe3a7ae0f70c712ef89e686..67013aa8b08ab818a5d8fdb8079a8eca7aa00ec2 100644 --- a/source/engine/graphics/back/textures/TextureBuffer.cpp +++ b/source/engine/graphics/back/textures/TextureBuffer.cpp @@ -21,12 +21,12 @@ namespace megu { this->_height = src._height; return *this; - } - - GLuint TextureBuffer::get(GLuint x, GLuint y) const { - return this->_data.at((this->_width * y) + x); } + void TextureBuffer::flipVerticaly() { + stbi__vertical_flip(this->_data.data(), this->_width, this->_height, TextureBuffer::BytePerPixel(this->_format)); + } + void TextureBuffer::load(const GLubyte * data, size_t size) { this->_data = std::vector<GLubyte>(data, data + size); } @@ -75,7 +75,28 @@ namespace megu { this->_data.clear(); } - void TextureBuffer::set(GLuint x, GLuint y, GLubyte v) { - this->_data[(y * this->_width) + x] = v; + int TextureBuffer::BytePerPixel(GLenum format) { + switch (format) { + case GL_ZERO: + return 0; + + case GL_RED: + return 1; + + case GL_ONE: + return 1; + + case GL_RG: + return 2; + + case GL_RGB: + return 3; + + case GL_RGBA: + return 4; + + default: + throw std::runtime_error("Unkwon byter per pixel for " + format); + } } } \ No newline at end of file diff --git a/source/engine/graphics/back/textures/TextureBuffer.hpp b/source/engine/graphics/back/textures/TextureBuffer.hpp index cb7f87fa4d17be2ec6ff3d3082cdc0927c78fb5f..584ed8c28e467091c69ff141755f953dc625c91e 100644 --- a/source/engine/graphics/back/textures/TextureBuffer.hpp +++ b/source/engine/graphics/back/textures/TextureBuffer.hpp @@ -21,13 +21,13 @@ namespace megu { inline const GLubyte * data_ptr() const {return this->_data.data();} inline bool empty() const {return this->_data.empty();} - GLuint get(GLuint, GLuint) const; + void flipVerticaly(); void load(const GLubyte *, size_t); void load(const std::filesystem::path &, bool = true); void free(); - void set(GLuint, GLuint, GLubyte); + static int BytePerPixel(GLenum); private: GLuint _width, _height; diff --git a/source/engine/graphics/front/object/Image.cpp b/source/engine/graphics/front/object/Image.cpp index d719bfba3917729233dae4fa2fe6f300b83ad744..42ac510d4d50153fea150b9c9d797e30260d7f1d 100644 --- a/source/engine/graphics/front/object/Image.cpp +++ b/source/engine/graphics/front/object/Image.cpp @@ -13,7 +13,7 @@ namespace megu { } void Image::load(const TextureBuffer & buffer) { - this->setSize(buffer.width(), buffer.height()); + this->setSize(static_cast<float>(buffer.width()), static_cast<float>(buffer.height())); this->_texture.store(buffer); } } \ No newline at end of file diff --git a/source/engine/io/Window.cpp b/source/engine/io/Window.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fdc462a7bb2e986c42518b7948065180f25e6675 --- /dev/null +++ b/source/engine/io/Window.cpp @@ -0,0 +1,74 @@ +#include "Window.hpp" + +#include <stdexcept> + +namespace megu { + Window::Window() + : _pointer(nullptr) { + if(glfwInit() == GLFW_FALSE) { + throw std::runtime_error("Cannot initialize GLFW."); + } + } + + uint16_t Window::width() const { + if(this->_pointer != nullptr) { + int width; + glfwGetWindowSize(this->_pointer, &width, NULL); + return width; + } + return 0; + } + + uint16_t Window::height() const { + if(this->_pointer != nullptr) { + int height; + glfwGetWindowSize(this->_pointer, NULL, &height); + return height; + } + return 0; + } + + bool Window::isOpen() const { + return this->_pointer != nullptr ? !glfwWindowShouldClose(this->_pointer) : false; + } + + void Window::resize(uint16_t width, uint16_t height) { + if(this->_pointer != nullptr) { + glfwSetWindowSize(this->_pointer, width, height); + } + } + + void Window::open(const std::string & title, uint16_t width, uint16_t height) { + if(this->_pointer == nullptr) { + this->_pointer = glfwCreateWindow(width, height, title.c_str(), NULL, NULL); + if(this->_pointer== NULL) { + throw std::runtime_error("Cannot open Window."); + } + + glfwMakeContextCurrent(this->_pointer); + glfwSwapInterval(0); + + if(glewInit()) { + throw std::runtime_error("Cannot initialize GLEW."); + } + + glViewport(0, 0, width, height); + } + } + + void Window::close() { + if(this->_pointer != nullptr) { + glfwSetWindowShouldClose(this->_pointer, true); + } + } + + void Window::pollEvents() { + glfwPollEvents(); + } + + void Window::swapBuffers() { + if(this->_pointer != nullptr) { + glfwSwapBuffers(this->_pointer); + } + } +} \ No newline at end of file diff --git a/source/engine/io/Window.hpp b/source/engine/io/Window.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b541bf866d0ad45074692b8701231cf5e0345deb --- /dev/null +++ b/source/engine/io/Window.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include <string> +#include <GL/glew.h> +#include <GLFW/glfw3.h> + +namespace megu { + class Window { + public: + Window(); + Window(const Window &) = delete; + ~Window() = default; + + uint16_t width() const; + uint16_t height() const; + + bool isOpen() const; + + void resize(uint16_t, uint16_t); + void open(const std::string &, uint16_t, uint16_t); + void close(); + + void pollEvents(); + void swapBuffers(); + + inline static double Time() {return glfwGetTime();} + + private: + GLFWwindow * _pointer; + }; +} \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index ba376e78122fea9e4d928a16b3817a595f004c3f..7b6a23deed8bb2680d0b18276470c08012337f54 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -6,6 +6,7 @@ #define WINDOW_WIDTH 1200 #define WINDOW_HEIGHT 720 +#include <engine/io/Window.hpp> #include <engine/graphics/back/cameras/View.hpp> #include <engine/graphics/front/object/Image.hpp> #include <engine/graphics/front/group/ImageGroup.hpp> @@ -13,7 +14,7 @@ int main(int argc, const char * argv[]) { try { - //? GLFW + /*//? GLFW if(glfwInit() == GLFW_FALSE) { std::cerr << "GLFW : GLFW Init Error" << std::endl; return EXIT_FAILURE; @@ -43,47 +44,45 @@ int main(int argc, const char * argv[]) { std::cout << "GLFW Inited" << std::endl; //? Glew - if (glewInit()) { + if(glewInit()) { std::cerr << "Failed to initialize GLAD" << std::endl; return EXIT_FAILURE; - } - - std::cout << "Glew Inited" << std::endl; - - //? Viewport - glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); - + }*/ + //? Window + megu::Window window; + window.open("Window", WINDOW_WIDTH, WINDOW_HEIGHT); megu::error::opengl_error::check(); + std::cout << "Window Inited" << std::endl; + //? Camera megu::View view(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); + std::cout << "View Initied" << std::endl; //? Image megu::Image image; - image.load("assets/textures/Test.png"); + image.load("assets/textures/Cube_Red.png"); - image.setSize(WINDOW_WIDTH/2, WINDOW_HEIGHT/2); - - std::cout << "Texture" << std::endl; + std::cout << "Image Inited" << std::endl; //? Group megu::ImageGroup group; group.temp_set(image); + std::cout << "Group Inited" << std::endl; + //? Render Loop glClearColor(0.0f, 0.0f, 0.0f, 0.f); std::cout << "Render Loop Begin !" << std::endl; - while(!glfwWindowShouldClose(window)) { + while(window.isOpen()) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glfwPollEvents(); - + window.pollEvents(); group.draw(view); - image.setPosition(sin(glfwGetTime()) * WINDOW_WIDTH/2, cos(glfwGetTime()) * WINDOW_HEIGHT/2); + image.setPosition(static_cast<float>(sin(glfwGetTime()) * WINDOW_WIDTH/2), static_cast<float>(cos(glfwGetTime()) * WINDOW_HEIGHT/2)); - - glfwSwapBuffers(window); + window.swapBuffers(); } std::cout << "Render Loop End !" << std::endl; }