1 of 21

2D/3D Graphics Rendering Project

Jacob Medel, Lily Heinonen, Kendan Phan, Zachary Taylor, Paolo Halog

2 of 21

OpenGL Introduction

(GLEW)

  • OpenGL is an open-source API for rendering 2D and 3D graphics
  • GLFW (Graphics Library Framework) provides a simple way to create windows and handle user inputs
  • GLEW allows the use of modern OpenGL features without manually managing function pointers and extension checks
  • GLM is a mathematics library that allows for vector and matrix operations

3 of 21

Window Creation

  • GLFW Error Checking
  • Window Error Checking
  • GLEW Error Checking
  • Window Pointer Definition
  • Window Creation
  • Window Hints

4 of 21

Black Hole Simulation

5 of 21

Black Hole Structure

  • OpenGL draws everything using triangles
  • Constructor calculates the Schwarzschild radius using the black hole’s mass
  • glBegin draws the shape
  • Loops 100 times
  • sin(angle) and cos(angle) compute x and y points on circle

6 of 21

Schwarzschild equation

  • The event horizon is the point at which light cannot escape the pull of the black hole
  • Schwarzschild equation determines the radius of the event horizon

7 of 21

Ray Structure

  • Creating each ray as a point
  • Creates the fading trail for light rays
  • GL Line Strip connects trails
  • Includes step function that increments the light rays across the screen
  • Converts Polar coordinates back into cartesian coordinates

8 of 21

Partial Product

Multiple Light Rays (No Curving)

9 of 21

Geodesic Equations

10 of 21

Euler and RK4 Step Function

Euler’s Method:

RK4 Method:

11 of 21

Main Function

12 of 21

Final Product

Multiple Light Rays

Single Light Ray

13 of 21

Shaders/Objects in 2D and 3D

14 of 21

Vertex and Indices Array

Vertex Array

  • Defines the object being drawn.
  • The vertices array contains the 3D coordinates and color at that vertex.

Indices Array

  • Specifies the order the vertices should be processed to form triangles.

15 of 21

Fragment and Vertex Shaders

Vertex Shaders:

  • With the given vertex array, vertex shaders work to decide the final position of where our used shaders will be placed
  • (shown in the graphic; vertex shader setting final positions where shaders will be placed

Fragment Shaders:

  • Determine final colors of the shape/object
  • Works alongside vertex shader to determine the positions of the shaders

Stages of the Graphic Pipeline

16 of 21

Code for Fragment and Vertex Shaders

Vertex Shader

Fragment Shader

17 of 21

VAO, VBO, and EBO

VBO (Vertex Buffer Object)

  • It stores the data from the vertices array.
  • It transfers the vertex data from the CPU’s memory to the GPU’s memory.
    • Can be accessed by the vertex shader.

EBO (Element Buffer Object)

  • It stores the data from the indices array.
    • Tells the GPU which vertices from VBO should be used and in what order to form triangles.

VAO (Vertex Array Object)

  • Stores the setup to how the GPU should interpret the data stored in VBO and which EBO to use.

18 of 21

GLM Matrices

  • Top-Left 3x3 Submatrix: Rotation and Scaling
  • Fourth Column (Top 3 values): Translation (Position)
  • Fourth Row (First 3 values): Perspective Projection
  • Bottom-Right (single value): Homogeneous Coordinate Scaling

19 of 21

Main While Loop and Deletions

Breakdown:

  • glClearColor: set window to preset color used for clearing a new frame
  • If statement: checking is ESC key is pressed, breaking loop and closing window when it is
  • glfwSwapBuffers: display frame that just finished drawing; one drawn in back while displaying current one and simply switches them
  • glfwPollEvents: processes all pending events such as window resizing, mouse movement, etc
  • Program, EBO, VBO, and VAO Deletion: deletes shader programs, buffers, and arrays
  • Final Deletion: destroy the whole window and glfw System

20 of 21

Final Product

Gradient Rectangle

Gradient Cube

21 of 21

Thank You!