Added proper libraries and started draw
This commit is contained in:
parent
cb1c1fed0b
commit
c7dd8e6b49
@ -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)
|
||||
|
||||
103
dep/NBEngine/Events.h
Normal file
103
dep/NBEngine/Events.h
Normal file
@ -0,0 +1,103 @@
|
||||
#pragma once
|
||||
#ifndef _NB_EVENTS
|
||||
#define _NB_EVENTS
|
||||
|
||||
#include <atomic>
|
||||
#include <stdexcept>
|
||||
#include <queue>
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
using state_register = std::atomic<uint64_t>;
|
||||
|
||||
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<size_t SIZE>
|
||||
NBEventListener(std::array<NBEvents*, SIZE> 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<NBStateChange> stateBuffer;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
#endif
|
||||
39
dep/NBEngine/Window.h
Normal file
39
dep/NBEngine/Window.h
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
#ifndef _NB_WINDOW
|
||||
#define _NB_WINDOW
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <atomic>
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
namespace NB {
|
||||
|
||||
class NBWindow {
|
||||
public:
|
||||
NBWindow(const std::array<uint16_t, 2>, 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<uint16_t, 2> getSize() const;
|
||||
std::string getName() const;
|
||||
void resize(const std::array<uint16_t, 2>);
|
||||
void resize(const uint16_t x, const uint16_t y);
|
||||
|
||||
protected:
|
||||
static std::atomic<uint8_t> windowCount;
|
||||
|
||||
std::array<uint16_t, 2> windowSize;
|
||||
std::string windowName;
|
||||
bool ready=false, running=false;
|
||||
GLFWwindow* window;
|
||||
GLFWmonitor* monitor;
|
||||
GLFWwindow* shareWindow;
|
||||
};
|
||||
|
||||
};
|
||||
#endif
|
||||
12
include/Draw.h
Normal file
12
include/Draw.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#ifndef _NB_DRAW
|
||||
#define _NB_DRAW
|
||||
|
||||
namespace NB{
|
||||
class NBDrawObject {
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
29
main.cpp
29
main.cpp
@ -5,6 +5,7 @@
|
||||
#include <stb_image.h>
|
||||
#include <funcs.h>
|
||||
#include <shader.h>
|
||||
#include <NBEngine/Window.h>
|
||||
#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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user