From 454ea72a8556992e0c279ba4cb5584ee327ac2e3 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Tue, 27 Feb 2018 23:31:13 +0100 Subject: [PATCH] Added OpenGL error logging, trying to draw colored lines... --- data/shaders/vs_simple.glsl | 4 ++-- src/main.cc | 18 ++++++++++++++++++ src/modules/RenderModule.cc | 15 +++++++++------ src/modules/RenderUtils.cc | 3 +-- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/data/shaders/vs_simple.glsl b/data/shaders/vs_simple.glsl index 5051b16..573f5f8 100644 --- a/data/shaders/vs_simple.glsl +++ b/data/shaders/vs_simple.glsl @@ -1,8 +1,8 @@ #version 150 core #extension GL_ARB_explicit_attrib_location : require -layout(location = 0) in vec3 inCoord; -layout(location = 1) in vec3 inColor; +in vec3 inCoord; +in vec3 inColor; uniform mat4 uModelViewProj; diff --git a/src/main.cc b/src/main.cc index c41ee95..6302877 100644 --- a/src/main.cc +++ b/src/main.cc @@ -43,6 +43,20 @@ static void error_callback(int error, const char* description) fprintf(stderr, "Error (%d): %s\n", error, description); } +static void opengl_error_callback( + GLenum source, + GLenum type, + GLuint id, + GLenum severity, + GLsizei length, + const GLchar* message, + const void* userParam ) +{ + gLog ("OpenGL Error: %s type %0x%x, severity = 0x%x, message = %s", + ( type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "" ), + type, severity, message ); +} + static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) @@ -117,6 +131,10 @@ int main(void) std::cout << "OpenGL Version: " << glGetString(GL_VERSION) << endl; std::cout << "GLSL Version : " << glGetString(GL_SHADING_LANGUAGE_VERSION) << endl; + // During init, enable debug output + glEnable ( GL_DEBUG_OUTPUT ); + glDebugMessageCallback( (GLDEBUGPROC) opengl_error_callback, 0 ); + // imgui initialization. ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; diff --git a/src/modules/RenderModule.cc b/src/modules/RenderModule.cc index cbecd92..6235d96 100644 --- a/src/modules/RenderModule.cc +++ b/src/modules/RenderModule.cc @@ -42,10 +42,10 @@ static const GLfloat g_textured_quad_vertex_buffer_data[] = { }; static const GLfloat g_coordinate_system_vertex_buffer_data[] = { - 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, - 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 255.0f, 0.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 255.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, 255.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, 255.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f }; @@ -180,7 +180,7 @@ void Camera::DrawGui() { // void Renderer::Initialize(int width, int height) { mDefaultTexture.MakeGrid(128, Vector3f (0.8, 0.8f, 0.8f), Vector3f (0.2f, 0.2f, 0.2f)); - + // Mesh glGenVertexArrays(1, &mMesh.mVertexArrayId); glBindVertexArray(mMesh.mVertexArrayId); @@ -296,10 +296,13 @@ void Renderer::RenderGl() { // glDrawArrays(GL_TRIANGLES, 0, 3); // starting from vertex 0; 3 vertices total glDisableVertexAttribArray(0); + glBindAttribLocation(mDefaultProgram.mProgramId, 0, "inCoord"); + glBindAttribLocation(mDefaultProgram.mProgramId, 1, "inColor"); + // Coordinate system glBindVertexArray(mCoordinateSystem.mVertexArrayId); glEnableVertexAttribArray(0); - glUniform4fv(muDefaultColor, 1, Vector4f(1.0f, 0.0f, 1.0f, 1.0f).data()); + glUniform4fv(muDefaultColor, 1, Vector4f(1.0f, 0.0f, 0.0f, 1.0f).data()); glBindBuffer(GL_ARRAY_BUFFER, mCoordinateSystem.mVertexBuffer); glVertexAttribPointer( 0, diff --git a/src/modules/RenderUtils.cc b/src/modules/RenderUtils.cc index aa9005a..0862c84 100644 --- a/src/modules/RenderUtils.cc +++ b/src/modules/RenderUtils.cc @@ -19,7 +19,7 @@ using namespace SimpleMath; // RenderProgram::~RenderProgram() { - if (mProgramId > 0) + if (mProgramId != -1) glDeleteProgram(mProgramId); } @@ -298,7 +298,6 @@ void Texture::MakeGrid(const int& size, const Vector3f &c1, const Vector3f &c2) } } - glGenTextures(1, &mTextureId); glBindTexture(GL_TEXTURE_2D, mTextureId);