1 of 40

OpenGL Rendering Pipeline Code

2 of 40

Requirement

3 of 40

Requirement

  • Below are the list of the suggestion you should know about before you proceed.
    • Core language feature you wish to used.
      • Otherwise you can’t create the program, right?
    • Basic rules of resource allocation and management.
      • In this slide, we will request the hardware to do the work for us. Remember to release the hardware resource once the program finished.
    • CPU and GPU.
      • Some knowledge of the hardware helps in this slide.

4 of 40

Requirement

  • In this slide, we will use the specification:
    • OpenGL version 3.3 or above.
  • With the requirement listed below:
    • C++ – Main programming languages
    • GLFW – OpenGL utility library
    • glad – OpenGL loading library

5 of 40

Requirement

  • In addition, we will use some optional system to help build our project, you can decide to use it or not:
    • CMake – Build system

6 of 40

Before we start

7 of 40

Before we start

  • We won’t cover the installation process since each platform has different setup.
  • Consider the following additional lecture from online:

8 of 40

Before we start

  • Install CMake
    • Suggest to install version 3.3 or above
  • Build and install GLFW
    • Suggest to install version 3.3 or above
  • Set up glad
    • Remember to download the patch your computer can perform (version 3.3 in this case).

9 of 40

Window

10 of 40

Window

  • General execute step.

11 of 40

Window

12 of 40

Window

13 of 40

Window

14 of 40

Window

15 of 40

Window

16 of 40

Window

17 of 40

Render pipeline code

vertex_array_objects_ebo.png – LearnOpenGL (Joey de Vries) – CC BY 4.0

https://learnopengl.com/img/getting-started/vertex_array_objects_ebo.png

18 of 40

Render pipeline code

  • Below are the components user can modify
    • Vertex Shader
    • Tessellation
    • Geometric Shader
    • Fragment Shader

Per-Sample Processing

Fragment Shader

Rasterization

Primitive Assembly

Vertex Post-Processing

Geometry Shader

Tessellation

Vertex Shader

Vertex Specification

19 of 40

Render pipeline code

  • Setup
    • Vertex array object.
    • Vertex buffer object.
    • Element buffer object.

vertex_array_objects_ebo.png – LearnOpenGL (Joey de Vries) – CC BY 4.0

https://learnopengl.com/img/getting-started/vertex_array_objects_ebo.png

20 of 40

Render pipeline code

  • Generate the OpenGL object.

21 of 40

Render pipeline code

  • Bind the VAO.
  • Bind the buffer object to vertex array object and specify the data (copy them into OpenGL context memory).

22 of 40

Render pipeline code

  • Enable and specify the generic vertex attribute array.

vertex_attribute_pointer.png – LearnOpenGL (Joey de Vries) – CC BY 4.0

https://learnopengl.com/img/getting-started/vertex_attribute_pointer_interleaved.png

23 of 40

Render pipeline code

  • Setup
    • Texture
      • Different system from vertex array object.

24 of 40

Render pipeline code

texture_wrapping.png – LearnOpenGL (Joey de Vries) – CC BY 4.0

https://learnopengl.com/img/getting-started/texture_wrapping.png

25 of 40

Render pipeline code

filter_linear.png – LearnOpenGL (Joey de Vries) – CC BY 4.0

https://learnopengl.com/img/getting-started/filter_linear.png

filter_nearest.png – LearnOpenGL (Joey de Vries) – CC BY 4.0

https://learnopengl.com/img/getting-started/filter_nearest.png

texture_filtering.png – LearnOpenGL (Joey de Vries) – CC BY 4.0

https://learnopengl.com/img/getting-started/texture_filtering.png

26 of 40

Render pipeline code

mipmaps.png – LearnOpenGL (Joey de Vries) – CC BY 4.0

https://learnopengl.com/img/getting-started/mipmaps.png

27 of 40

Render pipeline code

  • Texture
    • Read the data from file input stream.
    • Generate the texture object.
    • Bind and setup the texture object.

28 of 40

Render pipeline code

  • Shader program
    • Build the individual shader in render pipeline.
    • Build a shader program to link the shader.

29 of 40

Render pipeline code

  • Vertex Shader
    • Must have
  • Tessellation
    • Optional
  • Geometric Shader
    • Optional
  • Fragment Shader
    • Optional, but recommended

30 of 40

Render pipeline code

  • Build the individual shader in render pipeline.
    • Vertex Shader
    • Fragment Shader

31 of 40

Render pipeline code

  • Build-in Variable
    • Vary from shader to shader.
    • We will discuss the gl_Position only.
    • Full list

32 of 40

Render pipeline code

  • gl_Position
    • The output position of the current vertex.
      • Vertex shader output
      • Geometry shader input/output

33 of 40

Render pipeline code

  • Vertex shader
    • Specify the OpenGL version.
    • Specify the generic vertex attribute array.
    • Specify the output structure for next pipeline stage.

vertex_attribute_pointer.png – LearnOpenGL (Joey de Vries) – CC BY 4.0

https://learnopengl.com/img/getting-started/vertex_attribute_pointer_interleaved.png

34 of 40

Render pipeline code

  • Vertex shader
    • [Optional] Specify a variable for shader object.
    • Operate the vertex attribute.

35 of 40

Render pipeline code

  • Fragment shader
    • Specify the OpenGL version.
    • Specify the output structure for next stage.
    • Specify the input structure from previous stage.
    • [Optional] Specify a variable for shader object.
    • Determine the color.

36 of 40

Render pipeline code

  • Build a shader program to link the shader.
    • Remember to read the code via file input stream.

37 of 40

Render pipeline code

  • Compile shader
    • Create a shader object to catch the shader.
    • Compile the shader.
    • Check the compile status.

38 of 40

Render pipeline code

  • Create shader program
    • Create a shader program object to link the shader.
    • Check the link status.

39 of 40

Render pipeline code

  • Render the mesh in render loop.
    • Render the mesh in the window repeatedly.

40 of 40

Render pipeline code

  • Render the mesh in render loop.
    • Clear the render buffer.
    • Use the proper shader program.
    • Bind the correct vertex array object and texture.
    • Set the shader variables.
    • Draw the mesh.