[go: up one dir, main page]

Skip to content

The aim of this project is to study how 3D computations and linear algebra are implemented in computer science with the OpenGL library.

Notifications You must be signed in to change notification settings

KeremTAN/Learn-OpenGL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Learn OpenGL

Aim of This Repository

  The aim of this project is to study how 3D computations and linear algebra are implemented in computer science with the OpenGL library.

  For example; How to use theory of light in OpenGL or what are the functions used in OpenGL and OpenGL auxiliary libraries and what they do, etc.

Summary Information About OpenGL and Auxiliary Libs

  OpenGL is a cross platform library that communicates for us with the graphics card. The operations needed 2D and 3D graphics requirements such as video games, simulations, visual effects can be performed thanks to this library that can work independently on different operating systems and video cards.

  GLFW is the cross platform library of the OpenGL's auxiliary libraries. The GLFW library communicates between OpenGL and the operating system, it helps us that to manage windows, control input-output operations and similar process in OpenGL.

  GLAD and GLEW are cross platform libraries of the OpenGL's auxiliary libraries.

  Programs that using OpenGL need to connect with OpenGL's dynamic library in the background while they run. OpenGL uses dynamic loading method for the programs can connect its dynamic library. The GLAD and GLEW libraries help us here. In order to connect with the OpenGL dynamic library, it is enough to use only one of the two libraries.

  The working way of GLAD, the programmer tells to GLAD the function it needs instead of directly capturing the needed function addresses in OpenGL's dynamic library, and GLAD gives the address of the function needed for the programmer.

  The working way of GLEW, giving programmers an easier-to-use interface by wrapping functions in the OpenGL dynamic library.

How to Work OpenGL - OpenGL Pipeline

  • Certain steps have to be followed when drawing a shape with OpenGL.
  • These certain steps are called the OpenGL pipeline.
  • A program object contains these steps which called OpenGL pipeline in OpenGL.
  • Thus, we can manage the OpenGL pipeline thanks to a program object and we can program some specific steps as we want.

  The steps of OpenGL pipeline which the contained in a program object for us to be able to draw a shape with OpenGL are briefly described at below.

Step 1 - Vertex Specification

  The programmer can not do any changing or interventions in Vertex Specification.

  For example, we want to draw a triangle on the monitor.
  Each corner point of the triangle to be drawn is called a vertex and each vertex has x, y and z coordinates data in the drawing area.

  Simple shapes drawn using vertices are called primitives.
  The triangle shape which wanted to draw that is a primitive in this example.

  The vertices data are set for the primitive/primitives can be rendered in Vertex Specification.

Step 2 - Vertex Processing

  Points called vertex in the previous step begin to be processed for rendering in this step.

  This step consists of several sub-steps. Technically, some other steps contain several sub-steps, but the their sub-steps will not be explained separately. The reason for explaining the sub-steps in this step is that programmers can directly change or intervene to processing with the sub-steps in here.

Step 2.1 - Vertex Shader

  The programmer can do some changings or interventions in Vertex Shader.

  The aim of Vertex Shader is to geometrically calculate the position and features of the 2D/3D model to be created by using vertices.
  Some interventions are made using with GLSL commands in this step.
  The vertex data sent from previous step to this step comes as bit data.
  The type of the bit data can be labeled when writing GLSL commands in this step.
  For example, layout(location=0) command is used to indicate that the vertex data received in the previous step is a location data.

  Moreover, the vector sent in the previous step that is transformed from a 3-element vector (x, y, z coordinates) to a 4-element vector in this step. To do this transformation, 1 is added to the end of the vertex data.
  In this way, the new vector is converted to [x, y, z, 1].

  The purpose of this vector transformation is so that the matrix multiplication can be done correctly in the next steps.

  The reason for adding 1 to end of the vertices data which is that the number 1 is an ineffective element in the multiplication process.

  In other words, the purpose is that the matrix multiplications in the next steps can be done without distorting the original data.

Step 2.2 - Tessellation

  The programmer can do some changings or interventions in Tessellation.

  The data sent from previous step can be converted into smaller primitives in this step because more detail and complexity can be added dynamically to 3D surfaces by breaking the primitives into smaller pieces.
  The model/shape which wanted to create that can be converted more realistic in this way.

Step 2.3 - Geometry Shader

  The programmer can do some changings or interventions in Geometry Shader.

  Geometry Shader is logically similar to Vertex Shader.
  More complex and new primitives are created by using the primitives sent from the previous step in the Geometry Shader, just like that geometric shapes are created by using vertices in the Vertex Shader.

  For example, a hexagon are created by using triangle shapes.

Step 3 - Vertex Post-Processing

  The programmer can not do any changing or interventions in Vertex Post-Processing.

  Values calculated in Vertex and Geometry Shader can be saved in this step if wish.

  In addition, clipping processing is done in here.
  The drawing area which contains the shape wanted to create can be larger than the monitor on which the shape will be displayed.
  Unnecessary calculations are prevented by removing primitives that cannot be displayed on the monitor from the drawing screen in this step.

Step 4 - Primitive Assembly

  The programmer can not do any changing or interventions in Primitive Assembly.

  Vertices are processed as a series and new shapes are rendered from these series in this step.
  For example, drawing 3 triangles from a 9-element vertex series.

  In addition, Face Culling is done in this step.
  Face Culling processing means that invisible or too far to be seen in perspective primitives are in our drawing area removed from the drawing area.

Step 5 - Rasterization

  The programmer can not do any changing or interventions in Rasterization.

  Geometric shapes created in the previous step are converted into pixels called fragment data in this step.

  Information such as the color and depth of each pixel of the shape/model to be wanted drawing is stored in the fragment data for the next step.

Step 6 - Fragment Shader

  The programmer can do some changings or interventions in Fragment Shader.

  Pixels named as fragment data in the previous step are processed in this step. In particular, the coloring of each pixel of the created shape/model is done at this stage.

  In addition to coloring the pixels in this step, operations such as shading and lighting of each pixel are also processed.

Step 7 - Per-Sample Operations

  The programmer can not do any changing or interventions in Per-Sample Operations.

  First of all, Depth Test is performed in this step. The Depth Test is the stage of whether the fragment data to be wanted drawing will draw or not.
  For example; If there is another fragment data in front of the fragment data to be wanted drawing, the fragment data to be drawn will fail for the depth test.

  Moreover, Color Blending is performed in this step. Using the operations described in the previous steps, the colors in the fragment data are mixed with each other and interact with overlapping fragments in this stage.

  As a result of all these steps, the rendering process of the 2D/3D scene is completed and the final shape/model is created.

About

The aim of this project is to study how 3D computations and linear algebra are implemented in computer science with the OpenGL library.

Topics

Resources

Stars

Watchers

Forks

Languages