Advertisement
Guest User

Some OpenGL notes

a guest
Sep 7th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. some libraries:
  2. GLFW - window and GL context creation
  3. GLEW - GL extension loading
  4. SOIL - image loading
  5. GLM - vector and matrix math
  6.  
  7.  
  8. Window and context creation:
  9. Initialize GLFW (glfwInit)
  10. Set window hints to enable 3.3 core profile context (glfwWindowHint)
  11. Create window with glfwCreateWindow
  12. Make window context current with glfwMakeContextCurrent
  13. Set glewExperimental to true
  14. Initialize GLEW with glewInit
  15.  
  16.  
  17. Vertex Buffer Objects (VBO's):
  18. VBO's store vertex data
  19. First load or define the vertex data in your main program
  20. Generate a buffer on the GPU with glGenBuffers
  21. Bind it with glBindBuffer
  22. Upload the data with glBufferData
  23. A buffer on the GPU must be binded as the active buffer before it can be used,
  24. for example, to GL_ARRAY_BUFFER for VBO's
  25.  
  26. Shaders:
  27. Load vertex and fragment shaders with glCreateShader, glShaderSource, and glCompileShader
  28. Check for compile errors with glGetShaderiv and glGetShaderInfoLog
  29. Create a GL program with glCreateProgram
  30. Attach the vertex and fragment shaders to the program with glAttachShader
  31. Set the output buffer number for the color output of the fragment shader with glBindFragDataLocation
  32. Link the program with glLinkProgram
  33. Bind the program with glUseProgram
  34. Generate a VAO using glGenVertexArrays
  35. Bind it using glBindVertexArray
  36. Binding a VAO will allow opengl to store shader attributes and the binded VBO so that you don't have to
  37. reset the attributes each time you use the shader. Note that this step is required.
  38. Set attributes with glGetAttribLocation, glVertexAttribPointer, and glEnableVertexAttribArray
  39.  
  40. Uniforms:
  41. Uniforms are kind of like global variables that always have the same value
  42. Get location of uniform variable with glGetUniformLocation
  43. Set it's value with glUniform**
  44.  
  45. Alpha blending:
  46. Enable with glEnable(GL_BLEND)
  47. set blending function with glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
  48.  
  49. Element Buffer Objects (EBO's):
  50. Element buffers specify indexes into the VBO when rendering vertices
  51. This allows you to combine identical vertices
  52. Generate one with glGenBuffers
  53. Bind it to GL_ELEMENT_ARRAY_BUFFER
  54. Upload the data
  55.  
  56. Drawing:
  57. Draw triangles in currently bounded VBO with glDrawArrays
  58. Or if using an EBO, use glDrawElements
  59.  
  60. Textures:
  61. Load or define the pixel data in the main program
  62. Generate a texture buffer with glGenTextures
  63. Make a texture unit active with glActiveTexture (0 is active by default)
  64. Bind it with glBindTexture to GL_TEXTURE_2D
  65. Upload pixel data with glTexImage2D
  66. Set texture parameters with glTexParameteri/f
  67. Generate mipmaps with glGenerateMipmap
  68. Remember to supply the texture coordinates in the VBO
  69. In the fragment shader, sample the texture with a uniform of type sampler2D using the texture function
  70. Update the uniform sampler2D with the correct texture unit.
  71.  
  72. Uniform Buffer Objects (UBO's)
  73. Used for uploading data in bulk to the GPU
  74. Get the index of an interface block in GLSL with glGetUniformBlockIndex (optional, unless you have more than 1 blocks)
  75. Bind the block to a bind point with glUniformBlockBinding (binded to 0 by default. optional)
  76. Bind a buffer object to GL_UNIFORM_BUFFER and an index with glBindBufferBase
  77. Upload your data to the buffer object
  78. (watch out for padding and make sure to specify the right layout in your interface block in GLSL)
  79. In order to use variable length arrays, you must specify a static upper bound in the interface block,
  80. and indicate the actual length using a uniform
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement