Graphics Example Stable
This commit is contained in:
parent
e331fc1a34
commit
84046e89be
10 changed files with 28 additions and 12 deletions
|
|
@ -10,7 +10,7 @@ file(GLOB HEADERS "./public/*.hpp")
|
||||||
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
|
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC ./public/)
|
target_include_directories(${PROJECT_NAME} PUBLIC ./public/)
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE ${BINDINGS_INCLUDE})
|
target_include_directories(${PROJECT_NAME} PRIVATE ${BINDINGS_INCLUDE})
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC Strings Math Allocators)
|
target_link_libraries(${PROJECT_NAME} PUBLIC Math Allocators)
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE ${BINDINGS_LIBS})
|
target_link_libraries(${PROJECT_NAME} PRIVATE ${BINDINGS_LIBS})
|
||||||
|
|
||||||
### -------------------------- Examples -------------------------- ###
|
### -------------------------- Examples -------------------------- ###
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
|
|
||||||
#include "Window.hpp"
|
#include "Window.hpp"
|
||||||
|
#include "Graphics.hpp"
|
||||||
|
|
||||||
#include "Timing.hpp"
|
#include "Timing.hpp"
|
||||||
|
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
|
|
@ -16,15 +18,19 @@ int main() {
|
||||||
int fps = 0;
|
int fps = 0;
|
||||||
tp::Timer timer(1000);
|
tp::Timer timer(1000);
|
||||||
|
|
||||||
|
auto window = tp::Window::createWindow();
|
||||||
|
|
||||||
{
|
{
|
||||||
auto window = tp::Window::createWindow(800, 600, "Window 1");
|
tp::Graphics graphics(window);
|
||||||
|
|
||||||
if (window) {
|
if (window) {
|
||||||
while (!window->shouldClose()) {
|
while (!window->shouldClose()) {
|
||||||
window->processEvents();
|
window->processEvents();
|
||||||
|
graphics.proc();
|
||||||
|
|
||||||
ImGui::Text("fps: %i", fps);
|
ImGui::Text("fps: %i", fps);
|
||||||
|
|
||||||
|
graphics.draw();
|
||||||
window->draw();
|
window->draw();
|
||||||
|
|
||||||
if (timer.isTimeout()) {
|
if (timer.isTimeout()) {
|
||||||
|
|
@ -37,8 +43,9 @@ int main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tp::Window::destroyWindow(window);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tp::Window::destroyWindow(window);
|
||||||
|
|
||||||
testModule.deinitialize();
|
testModule.deinitialize();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#define GLEW_STATIC
|
#define GLEW_STATIC
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
#include "WindowContext.hpp"
|
#include "Graphics.hpp"
|
||||||
|
|
||||||
// -------- Canvas -------- //
|
// -------- Canvas -------- //
|
||||||
#define NANOVG_GL3_IMPLEMENTATION
|
#define NANOVG_GL3_IMPLEMENTATION
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
#include "Window.hpp"
|
#include "Window.hpp"
|
||||||
#include "WindowContext.hpp"
|
#include "WindowContext.hpp"
|
||||||
|
|
||||||
|
#include "Allocators.hpp"
|
||||||
|
|
||||||
#include "Graphics.hpp"
|
#include "Graphics.hpp"
|
||||||
|
|
||||||
// -------- Debug UI -------- //
|
// -------- Debug UI -------- //
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,7 @@
|
||||||
|
|
||||||
#include "EventHandler.hpp"
|
#include "EventHandler.hpp"
|
||||||
|
|
||||||
|
using namespace tp;
|
||||||
|
|
||||||
|
EventHandler::EventHandler() = default;
|
||||||
|
EventHandler::~EventHandler() = default;
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include "Window.hpp"
|
#include "Window.hpp"
|
||||||
#include "WindowContext.hpp"
|
#include "WindowContext.hpp"
|
||||||
|
#include "Allocators.hpp"
|
||||||
|
|
||||||
// -------- OpenGL -------- //
|
// -------- OpenGL -------- //
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
@ -31,13 +32,13 @@ static void keyCallback(GLFWwindow* window, int key, int scancode, int action, i
|
||||||
static void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
|
static void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
|
||||||
static void scrollCallback(GLFWwindow* window, double xOffset, double yOffset);
|
static void scrollCallback(GLFWwindow* window, double xOffset, double yOffset);
|
||||||
|
|
||||||
Window::Window(Vec2F size, const String& title) {
|
Window::Window(Vec2F size, const char* title) {
|
||||||
mContext = new Context();
|
mContext = new Context();
|
||||||
|
|
||||||
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, 1);
|
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, 1);
|
||||||
|
|
||||||
// Create a window and OpenGL context
|
// Create a window and OpenGL context
|
||||||
mContext->window = glfwCreateWindow((int) size.x, (int) size.y, title.read(), nullptr, nullptr);
|
mContext->window = glfwCreateWindow((int) size.x, (int) size.y, title, nullptr, nullptr);
|
||||||
if (!mContext->window) {
|
if (!mContext->window) {
|
||||||
printf("Failed to create GLFW window\n");
|
printf("Failed to create GLFW window\n");
|
||||||
return;
|
return;
|
||||||
|
|
@ -63,7 +64,7 @@ Window::~Window() {
|
||||||
delete mContext;
|
delete mContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window* Window::createWindow(Vec2F size, const String& title) {
|
Window* Window::createWindow(Vec2F size, const char* title) {
|
||||||
HeapAllocGlobal::startIgnore();
|
HeapAllocGlobal::startIgnore();
|
||||||
|
|
||||||
static int count = 1;
|
static int count = 1;
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ namespace tp {
|
||||||
// Event posters has no access to any custom state and only report any changes in any way
|
// Event posters has no access to any custom state and only report any changes in any way
|
||||||
class EventHandler {
|
class EventHandler {
|
||||||
public:
|
public:
|
||||||
EventHandler() = default;
|
EventHandler();
|
||||||
~EventHandler();
|
~EventHandler();
|
||||||
|
|
||||||
public: // Event Poster Interface
|
public: // Event Poster Interface
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ namespace tp {
|
||||||
};
|
};
|
||||||
|
|
||||||
class Graphics {
|
class Graphics {
|
||||||
private:
|
public:
|
||||||
explicit Graphics(Window* window) : mGui(window), mCanvas(window) {}
|
explicit Graphics(Window* window) : mGui(window), mCanvas(window) {}
|
||||||
|
|
||||||
void proc() {
|
void proc() {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Environment.hpp"
|
||||||
|
|
||||||
namespace tp {
|
namespace tp {
|
||||||
enum class InputID : ualni {
|
enum class InputID : ualni {
|
||||||
/* Printable keys */
|
/* Printable keys */
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include "Buffer.hpp"
|
#include "Buffer.hpp"
|
||||||
#include "EventHandler.hpp"
|
#include "EventHandler.hpp"
|
||||||
#include "Strings.hpp"
|
|
||||||
|
|
||||||
namespace tp {
|
namespace tp {
|
||||||
|
|
||||||
|
|
@ -12,11 +11,11 @@ namespace tp {
|
||||||
class Context;
|
class Context;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Window(Vec2F size, const String& title);
|
Window(Vec2F size, const char* title);
|
||||||
~Window();
|
~Window();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Window* createWindow(Vec2F size = { 1000.f, 900.f }, const String& title = "Window");
|
static Window* createWindow(Vec2F size = { 1000.f, 900.f }, const char* title = "Window");
|
||||||
static void destroyWindow(Window* window);
|
static void destroyWindow(Window* window);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue