mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-30 20:13:22 +08:00
Update debugging example code to match Debugging chapter updates.
This commit is contained in:
@@ -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.
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|||||||
@@ -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.
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|||||||
@@ -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));
|
||||||
|
|||||||
Reference in New Issue
Block a user