Skip to content

Commit

Permalink
Comments and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
m-decoster committed Jun 11, 2015
1 parent 0e73a2f commit 085d289
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/examples/01-hello_triangle/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ int main(void)
{
return -1;
}
// Detach and delete the shaders, because we no longer need them
glDetachShader(program, vertex);
glDeleteShader(vertex);
glDetachShader(program, fragment);
glDeleteShader(fragment);

glUseProgram(program); // Set this as the current shader program

Expand Down Expand Up @@ -114,6 +119,10 @@ int main(void)
glfwPollEvents();
}

// Clean up
glDeleteBuffers(1, &vbo);
glDeleteVertexArrays(1, &vao);

glfwTerminate();
return 0;
}
6 changes: 6 additions & 0 deletions src/examples/common/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

GLuint createShader(const char* src, GLenum shaderType)
{
// Create a shader and load the string as source code and compile it
GLuint s = glCreateShader(shaderType);
glShaderSource(s, 1, (const GLchar**)&src, NULL);
glCompileShader(s);

// Check compilation status: this will report syntax errors
GLint status;
glGetShaderiv(s, GL_COMPILE_STATUS, &status);
if(!status)
Expand All @@ -22,6 +24,7 @@ GLuint createShader(const char* src, GLenum shaderType)

GLuint createShaderProgram(GLuint vertex, GLuint fragment)
{
// Create a shader program and attach the vertex and fragment shaders
GLuint program = glCreateProgram();
glAttachShader(program, vertex);
glAttachShader(program, fragment);
Expand All @@ -30,6 +33,7 @@ GLuint createShaderProgram(GLuint vertex, GLuint fragment)

bool linkShader(GLuint program)
{
// Link the program and check the status: this will report semantics errors
glLinkProgram(program);
int status;
glGetProgramiv(program, GL_LINK_STATUS, &status);
Expand All @@ -52,6 +56,7 @@ bool validateShader(GLuint program)
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);

// Validate the program (some tutorials don't show this but it's best practice)
glValidateProgram(program);
int status;
glGetProgramiv(program, GL_VALIDATE_STATUS, &status);
Expand All @@ -68,6 +73,7 @@ bool validateShader(GLuint program)
return false;
}

// Unbind the vao because we no longer need it
glBindVertexArray(0);
glDeleteVertexArrays(1, &vao);

Expand Down

0 comments on commit 085d289

Please sign in to comment.