Hand Made Hero
Project Setup Use the command subst to create an alias to the working directory:
subst w: C:\Users\lv\work
Our project is actually created inside the work directory like this: \work\handmadehero.
Inside handmadehero, create two folders misc and code.
Inside code, create file win32_handmade.cpp.
Windows Entry Point All windows program has a entry point as follows, just put it in our code.
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { return 0; } How to Build We build our project from command line.
In HandMadeHero Day6, Casey showed a neat way to load a Windows function by yourself. The senario is as follows:
In order to get game pad input working, we need the function XInputGetState, but it is in different dll files on different Windows versions, if we link directly to Xinput.lib, then we have the risk of the program won’t start if somehow the dll is not found in the system. We don’t want that to happen considering that the user may not even use a game pad.
I started to follow Hand Made Hero again, here is the source code from Day 5. I also formatted it with clang.
win32_handmade.cpp
#include <stdint.h>#include <windows.h> #define internal static #define local_persist static #define global_variable static typedef int8_t int8; typedef int16_t int16; typedef int32_t int32; typedef int64_t int64; typedef uint8_t uint8; // 1 byte typedef uint16_t uint16; // 2 bytes typedef uint32_t uint32; // 3 bytes typedef uint64_t uint64; // 4 bytes struct win32_offscreen_buffer { // Pixels are alwasy 32-bits wide, Memory Order BB GG RR XX BITMAPINFO Info; void *Memory; int Width; int Height; int Pitch; }; struct win32_window_dimension { int Width; int Height; }; global_variable bool GlobalRunning; global_variable win32_offscreen_buffer GlobalBackbuffer; win32_window_dimension Win32GetWindowDimension(HWND Window) { win32_window_dimension Result; RECT ClientRect; GetClientRect(Window, &ClientRect); Result.
If you are a Linux person and you want to follow the awesome Hand Made Hero, here are how I am doing it(on Arch Linux).
Install VirtualBox. Create a Windows virtual machine(at least Win7 + SP1, you can download a ISO image from here), pay attention to the hard drive size, 25G is too small, increase it to like 50G at least. In order to make the full scren mode work, we have to install something called Guest Addition.
I purchased the pre-order Hand Made Hero game. I think it’s great value for learning, there is this super awesome guy who has tons of experience talking to you at least 1 hour per day for over a year. And it cost only $15. I must have lost my mind if I missed this.
Two interesting observations:
This guy is against OOP This guy prefers C to C++ This kind of “against C++ and OOP and all kind of complex nonsense shit” thing (this and this) hit me several times and I really like to know about their argument.