Added IMGUI for debugging
This commit is contained in:
@@ -40,8 +40,6 @@ Texture2D Assets::loadTextureFromFile(const GLchar *file, GLboolean alpha) {
|
||||
return texture;
|
||||
}
|
||||
texture.Generate(loadedSurface->w, loadedSurface->h, (unsigned char *) loadedSurface->pixels);
|
||||
|
||||
Utility::checkOpenGLError();
|
||||
|
||||
SDL_FreeSurface(loadedSurface);
|
||||
return texture;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ class DarkRP2D;
|
||||
#include <SDL.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
#include "Assets.h"
|
||||
#include "Renderer.h"
|
||||
#include "Mesh.h"
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "Desktoplauncher.h"
|
||||
#include "DarkRP2D.h"
|
||||
#include "Utility.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -59,6 +60,9 @@ bool initSDL() {
|
||||
}
|
||||
//Mask deprectated functions
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
#ifndef NDEBUG
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
|
||||
#endif
|
||||
//Init OpenGL Renderer
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
glcontext = SDL_GL_CreateContext(gWindow);
|
||||
@@ -73,6 +77,42 @@ bool initSDL() {
|
||||
cout << "Init of Glew failed: " << glewGetErrorString(err) << endl;
|
||||
return false;
|
||||
}
|
||||
//Init debug callback function
|
||||
#ifndef NDEBUG
|
||||
if (GLEW_ARB_debug_output) {
|
||||
Utility::printInfo(Utility::GLEW, "Supporting ARB debug output!");
|
||||
}
|
||||
if (GLEW_AMD_debug_output) {
|
||||
Utility::printInfo(Utility::GLEW, "Supporting AMD debug output!");
|
||||
}
|
||||
if (GLEW_KHR_debug) {
|
||||
Utility::printInfo(Utility::GLEW, "Supporting KHR debug output!");
|
||||
}
|
||||
//Print OpenGL version
|
||||
printf("----------------------OpenGL Info----------------------------\n");
|
||||
printf("Glew Version: %s\n", glewGetString(GLEW_VERSION));
|
||||
printf(" Version: %s\n", glGetString(GL_VERSION));
|
||||
printf(" Vendor: %s\n", glGetString(GL_VENDOR));
|
||||
printf(" Renderer: %s\n", glGetString(GL_RENDERER));
|
||||
printf(" Shading: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
printf("----------------------------------------------------------------\n");
|
||||
|
||||
if(glDebugMessageCallback) {
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
Utility::printInfo(Utility::OpenGL, "Register OpenGL debug callback");
|
||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
||||
glDebugMessageCallback(Utility::openglCallbackFunction, nullptr);
|
||||
GLuint unusedIds = 0;
|
||||
glDebugMessageControl(GL_DONT_CARE,
|
||||
GL_DONT_CARE,
|
||||
GL_DONT_CARE,
|
||||
0,
|
||||
&unusedIds,
|
||||
true);
|
||||
} else {
|
||||
Utility::printWarning(Utility::OpenGL, "glDebugMessageCallback not available");
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
62
src/Utility.cpp
Normal file
62
src/Utility.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "Utility.h"
|
||||
|
||||
|
||||
void APIENTRY Utility::openglCallbackFunction(GLenum source,
|
||||
GLenum type,
|
||||
GLuint id,
|
||||
GLenum severity,
|
||||
GLsizei length,
|
||||
const GLchar* message,
|
||||
const void* userParam){
|
||||
std::cout << "---------------------opengl-callback-start------------" << std::endl;
|
||||
std::cout << "message: "<< message << std::endl;
|
||||
std::cout << "type: ";
|
||||
switch (type) {
|
||||
case GL_DEBUG_TYPE_ERROR:
|
||||
std::cout << "ERROR";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
|
||||
std::cout << "DEPRECATED_BEHAVIOR";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
|
||||
std::cout << "UNDEFINED_BEHAVIOR";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_PORTABILITY:
|
||||
std::cout << "PORTABILITY";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_PERFORMANCE:
|
||||
std::cout << "PERFORMANCE";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_OTHER:
|
||||
std::cout << "OTHER";
|
||||
break;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "id: " << id << std::endl;
|
||||
std::cout << "severity: ";
|
||||
switch (severity){
|
||||
case GL_DEBUG_SEVERITY_LOW:
|
||||
std::cout << "LOW";
|
||||
break;
|
||||
case GL_DEBUG_SEVERITY_MEDIUM:
|
||||
std::cout << "MEDIUM";
|
||||
break;
|
||||
case GL_DEBUG_SEVERITY_HIGH:
|
||||
std::cout << "HIGH";
|
||||
break;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
std::cout << "---------------------opengl-callback-end--------------" << std::endl;
|
||||
}
|
||||
static const char* Errornames[] = { "OpenGL", "SDL","GLEW", "Other" };
|
||||
void Utility::printWarning(ERROR_TYPE type, std::string msg) {
|
||||
std::cout << "Warning[" << Errornames[type] << "]: " << msg << std::endl;
|
||||
}
|
||||
|
||||
void Utility::printError(ERROR_TYPE type, std::string msg) {
|
||||
std::cout << "Error[" << Errornames[type] << "]: " << msg << std::endl;
|
||||
}
|
||||
void Utility::printInfo(ERROR_TYPE type, std::string msg) {
|
||||
std::cout << "Info[" << Errornames[type] << "]: " << msg << std::endl;
|
||||
}
|
||||
@@ -1,13 +1,30 @@
|
||||
#ifndef UTILITY_H
|
||||
#define UTILITY_H
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <iostream>
|
||||
#include <windows.h>
|
||||
#include <string>
|
||||
|
||||
namespace Utility{
|
||||
inline void checkOpenGLError() {
|
||||
GLenum err;
|
||||
if((err = glGetError()) != GL_NO_ERROR) {
|
||||
std::cout << "OpenGL Error: " << err << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
enum ERROR_TYPE { OpenGL = 0, SDL,GLEW, Other};
|
||||
|
||||
void APIENTRY openglCallbackFunction(GLenum source,
|
||||
GLenum type,
|
||||
GLuint id,
|
||||
GLenum severity,
|
||||
GLsizei length,
|
||||
const GLchar* message,
|
||||
const void* userParam);
|
||||
|
||||
|
||||
|
||||
void printWarning(ERROR_TYPE type, std::string msg);
|
||||
|
||||
void printError(ERROR_TYPE type, std::string msg);
|
||||
|
||||
void printInfo(ERROR_TYPE type, std::string msg);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user