D2 log 020 – SDL port

I upgraded my home machine to macOS Catalina. Big mistake.

  • Zero interesting new features
  • Devastro 2 OpenGL renderer broken
  • Left 4 Dead unplayable (oh no!)

My OpenGL window went black. Was I using OpenGL wrong? How? On my quest for the answer, I ended up rewriting significant parts of the rendering core, updated all my shaders and created a new SDL port. It took several nights to get things working again.

The good thing is that switching to SDL was one of my mid-term goals anyway. I’m going to need it on Windows. To complete the port, I added SDL event handling and audio backend.

Event inspector for testing the SDL port. Blatantly copied from Sokol.

It was nice to get rid of the Cocoa boilerplate. One thing I missed in the SDL API was a function to set a fixed aspect ratio for my window. I had to do it like this:

cocoa.m:

#import <Cocoa/Cocoa.h>

void SetWindowRatio(void *window) {
    NSWindow *win = (__bridge NSWindow*) window;
    win.aspectRatio = NSMakeSize( 1280, 720 );
}

main.cpp:

#include <SDL.h>
#include <SDL_syswm.h>

extern "C" void SetWindowRatio(void *window);

// and later..

SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(sdl.window, &wmInfo);
SetWindowRatio(wmInfo.info.cocoa.window);

Fixing Left 4 Dead was easy. Add a new APFS volume, install Mojave, install Steam, move data files over, tell Steam to use them → no need to re-download everything. The nice thing about APFS volumes is that they share space, so I don’t have to think about how big each partition should be.