Skip to content

Instantly share code, notes, and snippets.

@rxantos
Forked from SimonJinaphant/glNotes.c
Created October 12, 2022 18:02
Show Gist options
  • Save rxantos/655d9d1ba3b3536fca06181875c5ca25 to your computer and use it in GitHub Desktop.
Save rxantos/655d9d1ba3b3536fca06181875c5ca25 to your computer and use it in GitHub Desktop.
OpenGL Notes
/*
CREATING THE VAO & VBO
======================
Objects must be generated via its corresponding glGen...() function
To perform any operations on any of OpenGL's objects, we must bind
the objects by invoking it corresponding glBind...() function
For @param GLenum target:
GL_ARRAY_BUFFER for Vertex attributes (Non-indexing method)
GL_ELEMENT_ARRAY_BUFFER for Vertex array indices (Indexing method)
*/
glGenVertexArrays(GLsizei n, GLuint *arrays);
glBindVertexArrays(GLuint array);
glGenBuffers(GLsizei n, GLuint *buffer);
glBindBuffers(GLenum target, GLuint buffer);
/*
Once the objects are created, we can populate data into it
by calling glBufferData() we "move" the data from Normal RAM to the GPU's RAM (Not too sure about this analogy)
If the data is custom, we must specify to OpenGL how it should interpret it
via glVertexAttribPointer()
Once we are done using something in OpenGL, we should unbind it:
Use the input argument of 0 to specify unbinding the currently binded object
*/
glBufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer);
//Unbinding the current VAO/VBO
glBindBuffers(GLenum target, 0);
glBindVertexArrays(0);
/*
USING AND DESTROYING THE VAO & VBO
==================================
To use the VAO/VBO again we must bind it, and unbind it once we're done
After binding we can enable a VAO's attribute(s), and disable it once we're done
If there are multiple attributes, make sure to activate more than one
For every attribute (VBO) and VAO you've generated, you must call its corresponding
glDelete...() to release the memory they held which properly destroys it
*/
glBindVertexArray(GLuint array);
glEnableVertexAttribArray(GLuint index);
//Attrubutes are activated, do something...like draw a shape...
glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
glDisableVertexAttribArray(GLuint index);
glBindVertexArray(0);
//Clearing up the VAO/VBO in the application's destructor
glDeleteVertexArray(vao);
glDeleteBuffers(vbo);
//-----Creating Shaders and Shader Programs-----
//For every shader (Vertex, Fragment, Geometric...)
glCreateShader();
glShaderSource();
glCompileShader();
glCreateProgram();
//For every shader relating to each other:
glAttachShader();
//For every uniform variable:
glBindAttribLocation();
glLinkProgram();
glValidateProgram();
//-----Helpful validation for Shaders-----
glGetProgrami();
glGetProgramInfoLog();
//-----Using the Shader-----
glUseProgram(programID);
//Do some rendering...
glUseProgram(0);
//-----Destroying the Shader
//Per every shader in the program:
glDetachShader(prog, shader);
glDeleteShader(shaderID);
glDeleteProgram(programID);
//-----Creating the Texture-----
glGenTexture();
glBindTexture();
//For every parameter:
glTexParameter();
glTexImage();
//-----Using the texture-----
//(In the render method, right before drawing)
glActiveTexture();
glBindTexture();
//-----Destroying the Shader-----
glDeleteTexture();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment