Upgrade to Pro — share decks privately, control downloads, hide ads and more …

OpenGL Introduction

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →
Bruce Tsai
February 02, 2015

OpenGL Introduction

A introduction to OpenGL for beginners

Bruce Tsai

February 02, 2015

Transcript

34 slides
  1. Port Crane Crates inside each container are our instances! Containers

    are OpenGL ’s objects ! textures, shaders, meshes! Port crane is OpenGL API 4 State Machine
  2. Rendering Settings void glPolygonMode(GLenum face, GLenum mode);! ! void glFrontFace(GLenum

    mode);! ! void glCullFace(GLenum mode); GL_FRONT_AND_BACK GL_POINT GL_LINE GL_FILL GL_CW GL_CCW GL_FRONT GL_BACK GL_FRONT_AND_BACK 8
  3. Render Buffer Color! Store final colored (RGB) image! Depth! Store

    final Z depth information! Stencil! Store visible part of object 10
  4. Structures vs. Indices {v1, v2, v3}, {v1, v3, v4}, …!

    ! {v1, v2, v3, v4, …}
 (0, 1, 2, 0, 2, 3, …) 13
  5. Create Buffer void glGenBuffers(GLsizei n, GLuint *buffers);! ! void glBindBuffers(GLenum

    target, GLuint buffer); GL_ARRAY_BUFFER GL_ELEMENT_ARRAY_BUFFER 15
  6. Set Buffer Data void glBufferData(GLenum target, GLsizeiptr size, const GLvoid

    *data, GLenum usage);! ! ! void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); _STATIC_ _DYNAMIC_ _STREAM_ _DRAW _READ _COPY GL_STATIC_DRAW 16
  7. Access Content Buffer void* glMapBuffer(GLenum target, GLenum access);! ! GLboolean

    glUnmapBuffer(GLenum target) GL_READ_ONLY GL_WRITE_ONLY GL_READ_WRITE 19
  8. Create Shader GLuint glCreateShader(GLenum type);! ! void glShaderSource(GLuint shader, GLsizei

    count, const GLchar **string, const GLint *length);! void glCompileShader(GLuint shader); 21 GL_VERTEX_SHADER GL_FRAGMENT_SHADER
  9. Create Program GLuint glCreateProgram(void);! void glAttachShader(GLuint program, GLuint shader);! void

    glLinkProgram(GLuint program);! void glUseProgram(GLuint program); 22
  10. Attribute Location 1. Defined fixed location in shader! 2. Bind

    attribute location before linking shader code! void glBindAttribLocation(GLuint program, GLuint index, const GLchar *name);! 3. Get attribute location after linking shader code! GLint glGetAttribLocation(GLuint program, const GLchar *name); 24
  11. Uniform Location Get uniform location after linking shader code! GLint

    glGetUniformLocation(GLuint program, const GLchar *name); 25
  12. Attribute Pointer void glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean

    normalized, GLsizei stride, const GLvoid *ptr);! ! void glGenVertexArrays(GLsizei n, GLuint *arrays);! void glBindVertexArrays(GLuint array); 27 Required while using glVertexAttribPointer
  13. Define Uniform Values void glUniform{1234}{if}(GLint index, T value[N]);! void glUniform{1234}{if}v(GLint

    index, GLsizei count, const T *value);! void glUniformMatrix{234}fv(GLint index, GLsizei count, GLboolean transpose, const GLfloat *value); 29
  14. Clear void glClearColor(GLflozt red, GLfloat green, GLfloat blue, GLfloat alpha);!

    void glClear(GLbitfield mask); 30 GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT GL_STENCIL_BUFFER_BIT
  15. Drawing void glDrawArrays(GLenum mode, GLint first, GLsizei count);! ! !

    void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); 31 GL_POINTS GL_LINES GL_LINE_STRIP GL_LINE_LOOP GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_UNSIGNED_BYTE GL_UNSIGNED_SHORT GL_UNSIGNED_INT

More Decks by Bruce Tsai

Other Decks in Programming