Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- some libraries:
- GLFW - window and GL context creation
- GLEW - GL extension loading
- SOIL - image loading
- GLM - vector and matrix math
- Window and context creation:
- Initialize GLFW (glfwInit)
- Set window hints to enable 3.3 core profile context (glfwWindowHint)
- Create window with glfwCreateWindow
- Make window context current with glfwMakeContextCurrent
- Set glewExperimental to true
- Initialize GLEW with glewInit
- Vertex Buffer Objects (VBO's):
- VBO's store vertex data
- First load or define the vertex data in your main program
- Generate a buffer on the GPU with glGenBuffers
- Bind it with glBindBuffer
- Upload the data with glBufferData
- A buffer on the GPU must be binded as the active buffer before it can be used,
- for example, to GL_ARRAY_BUFFER for VBO's
- Shaders:
- Load vertex and fragment shaders with glCreateShader, glShaderSource, and glCompileShader
- Check for compile errors with glGetShaderiv and glGetShaderInfoLog
- Create a GL program with glCreateProgram
- Attach the vertex and fragment shaders to the program with glAttachShader
- Set the output buffer number for the color output of the fragment shader with glBindFragDataLocation
- Link the program with glLinkProgram
- Bind the program with glUseProgram
- Generate a VAO using glGenVertexArrays
- Bind it using glBindVertexArray
- Binding a VAO will allow opengl to store shader attributes and the binded VBO so that you don't have to
- reset the attributes each time you use the shader. Note that this step is required.
- Set attributes with glGetAttribLocation, glVertexAttribPointer, and glEnableVertexAttribArray
- Uniforms:
- Uniforms are kind of like global variables that always have the same value
- Get location of uniform variable with glGetUniformLocation
- Set it's value with glUniform**
- Alpha blending:
- Enable with glEnable(GL_BLEND)
- set blending function with glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
- Element Buffer Objects (EBO's):
- Element buffers specify indexes into the VBO when rendering vertices
- This allows you to combine identical vertices
- Generate one with glGenBuffers
- Bind it to GL_ELEMENT_ARRAY_BUFFER
- Upload the data
- Drawing:
- Draw triangles in currently bounded VBO with glDrawArrays
- Or if using an EBO, use glDrawElements
- Textures:
- Load or define the pixel data in the main program
- Generate a texture buffer with glGenTextures
- Make a texture unit active with glActiveTexture (0 is active by default)
- Bind it with glBindTexture to GL_TEXTURE_2D
- Upload pixel data with glTexImage2D
- Set texture parameters with glTexParameteri/f
- Generate mipmaps with glGenerateMipmap
- Remember to supply the texture coordinates in the VBO
- In the fragment shader, sample the texture with a uniform of type sampler2D using the texture function
- Update the uniform sampler2D with the correct texture unit.
- Uniform Buffer Objects (UBO's)
- Used for uploading data in bulk to the GPU
- Get the index of an interface block in GLSL with glGetUniformBlockIndex (optional, unless you have more than 1 blocks)
- Bind the block to a bind point with glUniformBlockBinding (binded to 0 by default. optional)
- Bind a buffer object to GL_UNIFORM_BUFFER and an index with glBindBufferBase
- Upload your data to the buffer object
- (watch out for padding and make sure to specify the right layout in your interface block in GLSL)
- In order to use variable length arrays, you must specify a static upper bound in the interface block,
- and indicate the actual length using a uniform
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement