Update debugging example code to match Debugging chapter updates.

This commit is contained in:
Joey de Vries
2020-04-29 11:57:45 +02:00
parent 39cdda55e4
commit 6d1136d09a
3 changed files with 15 additions and 13 deletions

View File

@@ -170,6 +170,7 @@ int main()
glDeleteVertexArrays(1, &VAO); glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO); glDeleteBuffers(1, &VBO);
glDeleteBuffers(1, &EBO); glDeleteBuffers(1, &EBO);
glDeleteProgram(shaderProgram);
// glfw: terminate, clearing all previously allocated GLFW resources. // glfw: terminate, clearing all previously allocated GLFW resources.
// ------------------------------------------------------------------ // ------------------------------------------------------------------

View File

@@ -164,6 +164,7 @@ int main()
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
glDeleteVertexArrays(2, VAOs); glDeleteVertexArrays(2, VAOs);
glDeleteBuffers(2, VBOs); glDeleteBuffers(2, VBOs);
glDeleteProgram(shaderProgram);
// glfw: terminate, clearing all previously allocated GLFW resources. // glfw: terminate, clearing all previously allocated GLFW resources.
// ------------------------------------------------------------------ // ------------------------------------------------------------------

View File

@@ -43,10 +43,10 @@ GLenum glCheckError_(const char *file, int line)
void APIENTRY glDebugOutput(GLenum source, void APIENTRY glDebugOutput(GLenum source,
GLenum type, GLenum type,
GLuint id, unsigned int id,
GLenum severity, GLenum severity,
GLsizei length, GLsizei length,
const GLchar *message, const char *message,
const void *userParam) const void *userParam)
{ {
if(id == 131169 || id == 131185 || id == 131218 || id == 131204) return; // ignore these non-significant error codes if(id == 131169 || id == 131185 || id == 131218 || id == 131204) return; // ignore these non-significant error codes
@@ -95,7 +95,7 @@ int main()
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); // comment this line in a release build! glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true); // comment this line in a release build!
#ifdef __APPLE__ #ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
@@ -125,7 +125,7 @@ int main()
} }
// enable OpenGL debug context if context allows for debug context // enable OpenGL debug context if context allows for debug context
GLint flags; glGetIntegerv(GL_CONTEXT_FLAGS, &flags); int flags; glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
if (flags & GL_CONTEXT_FLAG_DEBUG_BIT) if (flags & GL_CONTEXT_FLAG_DEBUG_BIT)
{ {
glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT);
@@ -143,10 +143,10 @@ int main()
Shader shader("debugging.vs", "debugging.fs"); Shader shader("debugging.vs", "debugging.fs");
// configure 3D cube // configure 3D cube
GLuint cubeVAO, cubeVBO; unsigned int cubeVAO, cubeVBO;
GLfloat vertices[] = { float vertices[] = {
// back face // back face
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, // Bottom-left -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, // bottom-left
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // top-right 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // top-right
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, // bottom-right 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, // bottom-right
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // top-right 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // top-right
@@ -196,9 +196,9 @@ int main()
// link vertex attributes // link vertex attributes
glBindVertexArray(cubeVAO); glBindVertexArray(cubeVAO);
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
glEnableVertexAttribArray(1); glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat))); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0); glBindVertexArray(0);
@@ -243,8 +243,8 @@ int main()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
shader.use(); shader.use();
GLfloat rotationSpeed = 10.0f; float rotationSpeed = 10.0f;
GLfloat angle = (float)glfwGetTime() * rotationSpeed; float angle = (float)glfwGetTime() * rotationSpeed;
glm::mat4 model = glm::mat4(1.0f); glm::mat4 model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(0.0, 0.0f, -2.5)); model = glm::translate(model, glm::vec3(0.0, 0.0f, -2.5));
model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 1.0f, 1.0f)); model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 1.0f, 1.0f));
@@ -277,8 +277,8 @@ void renderQuad()
// positions // texture Coords // positions // texture Coords
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, -1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
}; };
// setup plane VAO // setup plane VAO
glGenVertexArrays(1, &quadVAO); glGenVertexArrays(1, &quadVAO);