Content below was automatically extracted from the notes for my Game Engine project:

Goal:

Code from scratch a game and physics/graphics engine at level of windows API!

Questions

  • How do we render graphics and take user input-with(C++) (understanding win32 API)
  • How do we understand instructions being run and optimize this?
  • How to abstract/port this to python, new language?

Concepts (to-explain)

  • Win-API
  • Windows Handles

Windows API 🪟

Here, I will be struggling through trying to implement and understand the windows API!

Supposedly, this is almost the lowest level we can get, and it provides us with control over the windows we create and the rendering.

I will attempt to organize my thoughts about the windows API and its abstractions as clearly as possible in the following notes:

Running a Program w/ Windows

First, let’s understand a little about what our program is actually doing, and why we even need to talk to the windows API (why can’t we just change the memory itself that calls up a window and draws pixels on it?).

We can basically think of our normal C++ programs as ‘gated’ applications, where most memory is protected, and we are allocated ‘virtual memory’ that can’t actually do any harm to our computer.

When working with the windows API, we can use windows as an intermediary to do the ’elevateed permission level’ functions, like calling a window and playing a sound.

Since we can’t actually modify the memory itself, the windows api is the most low-level way to actually open windows, and create applications.

WINAPI

To run a C++ program that compiles with the windows API, we first must define the header: #include <windows.h>. Headers basically define and link all of the functions from another file (some secretive powerful windows C file with a bunch of functions we’ll be using).

This inclusion basically does the #defines and calls all of the functions we’ll be using with windows. There are ALOT of windows-specific things we’ll be using in order to talk with the operating system, here is the main function we must use:

code
#include <windows.h>

int CALLBACK WinMain( 
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow
) {
    OutputDebugStringA("Hello from the debug line");
}

So, this is very different from regular C++ code and probably seems daunting.