Added IMGUI for debugging
This commit is contained in:
@@ -1,10 +1,19 @@
|
||||
#include "DarkRP2D.h"
|
||||
|
||||
#include <GL/gl.h>
|
||||
#ifndef NDEBUG
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_sdl_gl3.h"
|
||||
#endif
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <iostream>
|
||||
|
||||
DarkRP2D::~DarkRP2D() {
|
||||
std::cout << "Game got destroyed!" << std::endl;
|
||||
#ifndef NDEBUG
|
||||
ImGui_ImplSdlGL3_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
#endif
|
||||
delete assets;
|
||||
delete obj;
|
||||
delete inputHandler;
|
||||
@@ -37,6 +46,12 @@ void DarkRP2D::create () {
|
||||
font = new BitmapFont("arial.ttf");
|
||||
|
||||
camera = new OrtographicCamera();
|
||||
#ifndef NDEBUG
|
||||
//Setup IMGUI debugging
|
||||
ImGui::CreateContext();
|
||||
ImGui_ImplSdlGL3_Init(this->gWindow);
|
||||
ImGui::StyleColorsDark();
|
||||
#endif
|
||||
}
|
||||
|
||||
void DarkRP2D::loop(unsigned int delta) {
|
||||
@@ -72,8 +87,17 @@ void DarkRP2D::update(unsigned int delta) {
|
||||
//camera update
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
bool show_demo_window = true;
|
||||
bool show_another_window = false;
|
||||
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||
#endif
|
||||
|
||||
void DarkRP2D::render(unsigned int delta) {
|
||||
renderer->clear();
|
||||
#ifndef NDEBUG
|
||||
ImGui_ImplSdlGL3_NewFrame(gWindow);
|
||||
#endif
|
||||
|
||||
//Drawing
|
||||
Shader defaultShader = assets->getShader("defaultShader");
|
||||
@@ -85,6 +109,32 @@ void DarkRP2D::render(unsigned int delta) {
|
||||
Shader bitmapShader = assets->getShader("bitmapShader");
|
||||
font->drawText(bitmapShader, "Hallo du noob", 25.0f, 25.0f, 1.f, glm::vec3(0.5f,0.8f,0.2f));
|
||||
|
||||
|
||||
#ifndef NDEBUG
|
||||
// 1. Show a simple window.
|
||||
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug".
|
||||
{
|
||||
static float f = 0.0f;
|
||||
static int counter = 0;
|
||||
ImGui::Text("Hello, world!"); // Display some text (you can use a format string too)
|
||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
|
||||
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
|
||||
|
||||
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our windows open/close state
|
||||
ImGui::Checkbox("Another Window", &show_another_window);
|
||||
|
||||
if (ImGui::Button("Button")) // Buttons return true when clicked (NB: most widgets return true when edited/activated)
|
||||
counter++;
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("counter = %d", counter);
|
||||
|
||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
||||
}
|
||||
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplSdlGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
#endif
|
||||
SDL_GL_SwapWindow(gWindow);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user