Adding objects GUI initial. Changing TODO. Some fixes along side

This commit is contained in:
IlushaShurupov 2023-08-03 22:04:42 +03:00 committed by Ilya Shurupov
parent f579a969ce
commit 17ad239692
18 changed files with 1345 additions and 56 deletions

View file

@ -1,6 +1,8 @@
#include "Window.hpp"
#include "imgui.h"
int main() {
tp::ModuleManifest* deps[] = { &tp::gModuleGraphics, nullptr };
tp::ModuleManifest testModule("Example", nullptr, nullptr, deps);
@ -10,12 +12,16 @@ int main() {
}
{
tp::HeapAllocGlobal::startIgnore();
auto window = tp::Window::createWindow(800, 600, "Window 1");
tp::HeapAllocGlobal::stopIgnore();
if (window) {
window->renderLoop();
while (!window->shouldClose()) {
window->processEvents();
ImGui::Text("Hello!");
window->draw();
}
}
tp::Window::destroyWindow(window);

View file

@ -42,10 +42,14 @@ void Graphics::GUI::deinit() {
}
void Graphics::GUI::proc() {
tp::HeapAllocGlobal::startIgnore();
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
tp::HeapAllocGlobal::stopIgnore();
// ImGui code goes here
ImGui::Begin("Window");
ImGui::End();

View file

@ -71,11 +71,13 @@ void Graphics::deinit() {
mGl.deinit();
}
void Graphics::draw() {
void Graphics::proc() {
mGl.proc();
mCanvas.proc();
mGui.proc();
}
void Graphics::draw() {
mGl.draw();
mCanvas.draw();
mGui.draw();
@ -110,6 +112,8 @@ Window::~Window() {
Window* Window::createWindow(int width, int height, const char* title) {
tp::HeapAllocGlobal::startIgnore();
static int count = 1;
if (!count) {
printf("Window class is a singleton\n");
@ -128,7 +132,10 @@ Window* Window::createWindow(int width, int height, const char* title) {
printf("GLFW Error: %i %s\n", error, description);
});
return new Window(width, height, title);
auto out = new Window(width, height, title);
tp::HeapAllocGlobal::stopIgnore();
return out;
}
void Window::destroyWindow(Window* window) {
@ -136,15 +143,18 @@ void Window::destroyWindow(Window* window) {
glfwTerminate();
}
void Window::renderLoop() {
while (!glfwWindowShouldClose(mContext->window)) {
bool Window::shouldClose() const {
return glfwWindowShouldClose(mContext->window);
}
mGraphics.draw();
void Window::processEvents() {
glfwPollEvents();
mGraphics.proc();
}
// Swap buffers and poll events
glfwSwapBuffers(mContext->window);
glfwPollEvents();
}
void Window::draw() {
mGraphics.draw();
glfwSwapBuffers(mContext->window);
}
auto Window::getContext() -> Context* { return mContext; }

View file

@ -67,6 +67,7 @@ namespace tp {
void init(Window* window);
void deinit();
void draw();
void proc();
private:
GUI mGui;

View file

@ -27,7 +27,10 @@ namespace tp {
static void destroyWindow(Window* window);
public:
void renderLoop();
void draw();
void processEvents();
[[nodiscard]] bool shouldClose() const;
auto getContext() -> Context*;
private: