1/25
02 Handout 1 - Pygame and OpenGL. 🍀 - syntax
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Window
is a graphical interface element that displays an application’s content
Startup
phases of an interactive and graphics-based windowed application:
during this stage, objects are created, values are initialized, and any required external filers are loaded
Main Loop
phases of an interactive and graphics-based windowed application:
this stage repeats continuously while the application is running
consists of three (3) substages: Process Input, Update, r
Process Input
Main Loop:
checks if the user has performed any action that sends data to the computer, such as pressing keys on a keyboard or clicking buttons on a mouse
Update
Main Loop:
changes values of variables and objects
Render
Main Loop:
creates graphics that are displayed on the screen
Shutdown
phases of an interactive and graphics-based windowed application:
this stage typically begins when the user performs an action indicating that the program should stop (for example, by clicking a button to quit the application)
this stage may involve tasks such as signaling the application to stop checking for user input and closing any windows created by the application
Pygame
is a set of Python modules designed for creating video games
it is a popular Python game development library
to set up a window using Pygame🍀
use pygame.display.set_mode() method
Example:
screen = pygame.display.set_mode((500, 500))
Point
is a location in space
it is the most basic graphical element
to render a single __ on the screen, use a vertex shader
Rendering a single point by using vertex shader
Vertex Shader will consists of the following code using the OpenGL Shading Language (GLSL)
every shader must contain a main() function
manipulate coordinates in a 3D space and are called once per vertex
the purpose of vertex shader is to set up the gl_Position variable

void
indicates that no values are returned
main()
requires no parameters
gl_Position
a special, global, and built-in GLSL variable
used to store the position of the current vertex
Vector Data Types
often used for storing values that indicate positions, colors, and texture coordinates
may have two, three, or four components indicated by vec2, vec3, and vec4 (for vectors consisting of floats)
the four float values represent the vertex’s x, y, z, and w positions
the w parameter is used to manipulate the clipping of the vertex position in the 3D space
default value is 1.0
Vertex Buffers
stores every vertex shader that you write will use arrays of data
multiple points are needed to specify the shapes of two-dimensional or three-dimensional objects
Sample code to draw a 3D triangle🍀
each of the triangle’s vertices is specified by a call to the function glVertex3f
vertices must be specified between calls to glBegin and glEnd

glBegin
tells which type of primitive is being drawn
Uniform Variables
are global variables that can be accessed by the vertex shader or the fragment shader, and whose values are constant while each shape is being drawn (can be changed between draw function calls)
Uniform
a type qualifier that provides a mechanism for directly sending data from variables in a CPU application to variables in a GPU program
glGetUniformLocation(programRef, variableName)🍀
glGetUniformLocation
returns a value used to reference a uniform variable (indicated by the type qualifier uniform)
variableName
the name indicated by the parameter variableName
programRef
declared in the program referenced by the parameter programRef
Keydown
occur the moment a key is initially pressed
Keyup
occur the moment the key is released
Discrete
an event that happens once at an isolated point in time
Continuous
an event that continues happening during an interval of time
Sample code the checks if a keydown event occurs🍀
.
