Skip to content

Instantly share code, notes, and snippets.

Last active May 5, 2022 09:04
Show Gist options
  • Save umutseven92/70d21da86da0fdb1d0a3617063767eba to your computer and use it in GitHub Desktop.
Save umutseven92/70d21da86da0fdb1d0a3617063767eba to your computer and use it in GitHub Desktop.
Game Dev Programming



  • GLSL stands for openGL Shading Language, which is how shaders are written in the OpenGL API.
    • OpenGL is run by Khronos group.
    • OpenGL is a subset of OpenGL that is for embedded systems.
    • Other alternatives are:
      • Direct3D, part of DirectX, owned by Microsoft,
      • Vulkan, next generation OpenGL, also by Khronos group, and,
      • Metal, for Apple platforms, owned by Apple.
  • Shaders are memoryless & stateless; they cannot modify the input, nor communicate with other shaders. They are input -> output only.
  • Vertex function: 3D to 2D conversation
    • Runs for each vertex in the triange
  • Rasterization: taking an image described in vector graphics formats and transform it into a set of pixels of output on the screen.
  • Fragment function: Which color each pixel will be
    • Runs for each pixel
  • UV Mapping: Mapping the vertices of our model to locations in our texture (U and V are coordinates)
  • Interpolation: Use vertices to find out where in the texture our point lies
  • Both UV Mapping and Interpolation are done in the vertex function, then sent to the fragment function
  • Normal: Direction each vertex is facing
  • Interpolated Normals: Normal of each pixel, as an average depending on their distance to vertices
  • Fragment uses the dot product of light direction and normals to calculate lighting.
    • If the pixel faces the light, the dot product will be 1.
    • If the pixel is facing away from the light, the product will be between 1 and 0.
  • Vertex function (Position, UV, Normal) -> Interpolation System (Interpolated Normals) -> Fragment Function


  • Normal mapping: Used to fake ligting of bumps and dents to add more detail to models.
    • The normal map is colored based on where its facing the viewer.
    • They don't contain any height information, only angle information.
  • Height maps: Used to fake height in models.
    • Greyscale, black is down and white is up.
  • Mip mapping: Mipmaps are smaller, pre-filtered versions of a texture image, representing different levels of detail (LOD) of the texture.
    • They are often stored in sequences of progressively smaller textures called mipmap chains with each level half as small as the previous one.
    • They are used for situations where the distance between an object and the camera can change. As the object gets further from the camera, the object’s texture will eventually appear smaller on-screen than its actual resolution, in other words, there will be more than one texel (pixels of a texture map) per screen pixel.
  • Z-buffering: A depth buffer, also known as a z-buffer, is a type of data buffer used in computer graphics to represent depth information of objects in 3D space from a particular perspective.
    • Depth buffers are an aid to rendering a scene to ensure that the correct polygons properly occlude other polygons.



  • Entities, Components, Systems
  • Composition based rather than Inheritence based
  • ECS solves the problems that occur when applying OOP to game programming
  • Entity: Any object in game (Player, Platform, Enemy)
    • Each will have an (x, y) position
  • Component is a property that can be attached to Entities
    • Like Position, Speed, Bounding Box
    • Components are pure data
  • Systems is the Code & Logic that drives behaviour
    • Movement, Rendering, Physics



  • Vectors can be used to represent a point, a direction, velocity etc.
  • When representing a direction, the origin (0, 0) is used.
  • The distance from the origin is knows as the magnitude.
  • Magnitude is calculated using Pythagorean theorem (a^2 + b^2 = c^2)
  • For things like direction where magnitude does not matter, we normalize the vector.
  • Normalizing a vector scales its length down to 1.
  • A dot product is an operation on two vectors, which returns a number.
  • If dot product is 1, normals face the same direction.
  • If dot product is 0, normals are perpendicular.
  • If dot product is -1, normals face opposite directions.
  • A cross product is also an operation on two vectors.
  • The result is a third vector, which is perpendicular to the first two, and it's length is an average of the both lengths.


  • Delta time: is the time difference between the previous frame and the current frame.
  • Games will run at different speeds on every computer.
  • Delta time is used to make sure the game is not frame rate dependant.
  • Great for movement, not so great for rendering & physics (as they usually need a fixed time step).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment