diff --git a/CMakeLists.txt b/CMakeLists.txt index ed5bdc5..690b353 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,16 +4,18 @@ project(GraphicsTest VERSION 0.1.0 LANGUAGES C CXX) include(CTest) enable_testing() - set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) include(CPack) include_directories(./dep ./include) -link_directories(../libs/glfw-3.3.9/build/src) +link_directories(../libs/glfw-3.3.9/build/src ../libs/NBEngine/lib) + +add_library(NBDraw Draw.cpp) + add_executable(GraphicsTest main.cpp funcs.cpp shader.cpp ../libs/glad/src/glad.c) -target_link_libraries(GraphicsTest glfw3) +target_link_libraries(GraphicsTest glfw3 NBWindows NBEvents) set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) diff --git a/Draw.cpp b/Draw.cpp new file mode 100644 index 0000000..ffd0576 --- /dev/null +++ b/Draw.cpp @@ -0,0 +1,5 @@ +#include "Draw.h" + +namespace NB{ + +} \ No newline at end of file diff --git a/dep/NBEngine/Events.h b/dep/NBEngine/Events.h new file mode 100644 index 0000000..0b4212b --- /dev/null +++ b/dep/NBEngine/Events.h @@ -0,0 +1,103 @@ +#pragma once +#ifndef _NB_EVENTS +#define _NB_EVENTS + +#include +#include +#include +#include +#include +#include +#include + +using state_register = std::atomic; + +namespace NB { + +extern std::invalid_argument null_mask_error; + +void NULL_FUNC(); + +class NBEvents { +friend class NBEventListener; +public: + NBEvents(const uint64_t, void (*initFunc)() = NULL_FUNC, const char* initName=""); + NBEvents(const uint64_t, const char* initName=""); + NBEvents(const NBEvents&); + NBEvents& operator=(const NBEvents&); + ~NBEvents(); + + const std::string getName() const; + const uint64_t getMask() const; + void setMask(const uint64_t); + void setName(const char*); + void setFunc(void (*newFunc)()); + virtual const uint64_t check(const uint64_t) const = 0; + virtual NBEvents* clone() const = 0; + +protected: + uint64_t mask = 0x0; + void (*func)() = nullptr; + std::string name = ""; + +}; + +class NBEventBasic : public NBEvents { +friend class NBEventListener; +public: + using NBEvents::NBEvents; + + NBEventBasic* clone() const override; + const uint64_t check(const uint64_t) const override; + +}; + +class NBEventState : public NBEvents { +friend class NBEventListener; +public: + using NBEvents::NBEvents; + + NBEventState* clone() const override; + const uint64_t check(const uint64_t) const override; +}; + +enum NBStateChangeType : uint8_t { + STATE_RAISE, STATE_DROP, STATE_SET +}; + +struct NBStateChange { + uint8_t type; + uint64_t mask; +}; + +class NBEventListener { +public: + NBEventListener(NBEvents**, uint16_t, const uint64_t initState=(uint64_t)0x0, state_register* initStatePtr=nullptr); + template + NBEventListener(std::array eventArray, const uint64_t initState=(uint64_t)0x0, state_register* initStatePtr=nullptr) + : NBEventListener(eventArray.data(), eventArray.size(), initState, initStatePtr) {} + + state_register* getStatePtr() const; + const uint64_t getState() const; + void raiseFlags(const uint64_t); + void raiseFlags(const NBEvents&); + void dropFlags(const uint64_t); + void dropFlags(const NBEvents&); + const bool snoop(const uint64_t) const; + const bool snoop(const NBEvents&) const; + void listen(); + void listen(const NBEvents&); + +protected: + void _setState(const uint64_t); + + NBEvents** eventList; + uint16_t numEvents; + state_register* state; + std::mutex bufferLock; + std::queue stateBuffer; + +}; + +}; +#endif \ No newline at end of file diff --git a/dep/NBEngine/Window.h b/dep/NBEngine/Window.h new file mode 100644 index 0000000..7ac7b60 --- /dev/null +++ b/dep/NBEngine/Window.h @@ -0,0 +1,39 @@ +#pragma once +#ifndef _NB_WINDOW +#define _NB_WINDOW + +#include +#include +#include +#include +#include +#include +namespace NB { + +class NBWindow { +public: + NBWindow(const std::array, const char*, GLFWmonitor* initMonitor=NULL, GLFWwindow* initWindow=NULL); + NBWindow(const uint16_t, const uint16_t, const char*, GLFWmonitor* initMonitor=NULL, GLFWwindow* initWindow=NULL); + ~NBWindow(); + + + int init(); + GLFWwindow* getWindow() const; + std::array getSize() const; + std::string getName() const; + void resize(const std::array); + void resize(const uint16_t x, const uint16_t y); + +protected: + static std::atomic windowCount; + + std::array windowSize; + std::string windowName; + bool ready=false, running=false; + GLFWwindow* window; + GLFWmonitor* monitor; + GLFWwindow* shareWindow; +}; + +}; +#endif \ No newline at end of file diff --git a/include/Draw.h b/include/Draw.h new file mode 100644 index 0000000..32a833b --- /dev/null +++ b/include/Draw.h @@ -0,0 +1,12 @@ +#pragma once +#ifndef _NB_DRAW +#define _NB_DRAW + +namespace NB{ +class NBDrawObject { + +}; + + +} +#endif \ No newline at end of file diff --git a/main.cpp b/main.cpp index 3f5a464..ded5e30 100644 --- a/main.cpp +++ b/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "data.cpp" unsigned int gridX = 8, gridY = 8; @@ -13,32 +14,12 @@ float* tileCoords = makeGridPoints(gridX, gridY); unsigned int* tileIndices = makeGridIndex(gridX, gridY); int main() { - // Initalize GLFW - glfwInit(); - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + NB::NBWindow myWindow(800, 600, "Howdy Naif!"); + auto window = myWindow.getWindow(); - // Open Window - GLFWwindow* window = glfwCreateWindow(800, 600, "Howdy Naif!", NULL, NULL); - if (window == NULL) { - std::cout << "Could not open the window!\n"; - glfwTerminate(); - return -1; - } - glfwMakeContextCurrent(window); - - // Start GLAD loader - if (!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress)){ - std::cout << "Failed to initialize GLAD" << std::endl; - return -1; - } - - // Set viewport - glViewport(0, 0, 800, 600); + myWindow.init(); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); - // glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); - // glfwSetCursorPosCallback(window, mouse_callback); + // Create Data float* screenCoords = scaleGridPoints(gridX, gridY, (float)sizeX/(float)800, (float)sizeY/(float)600, tileCoords);