Windows Build!

2015-10-05

Last week I got a used, hand-me-down Dell Optiplex 780 from a very generous friend. It’s a 2009 3ghz dual core. Upgraded it with a NVidia GT730 DDR5 graphics card ($73 amazon), and Windows 8.1. Works great! (I can run NaissancE on it, also, finally, a PC for that game.)

Porting Metareal to it took a couple of days. Fortunately SDL2 and OpenGL are the foundations (as planned) so it mostly straightforward.

Some notes, about porting an SDL2 and OpenGL app from Mac OS X to Windows.

  • Be sure to add opengl32.lib to your project. Lots of web guides I read neglected this simple step!
  • The base SDK only supports OpenGL 1.1. No, seriously. On Mac you just link to gl3.h and get it all, Visual Studio’s c++ SDK just has OpenGL 1.1. Turns out on Windows you need to dynamically load up all the extensions and later version…
  • To get to higher versions of OpenGL, I used glew. If you do, don’t get caught up in their static vs dynamic libraries and 32 vs 64 bit… just add glew.c to your project. And use their OpenGL replacement header files.
  • Am I done with glew yet? No. There’s some sort of issue with glGenFrameBuffers and other framebuffer calls. Do glewExperimental = true; glewInit(); and, yeah, then it works.
  • SDL is a little finicky and fails silently. If you do something a little wrong, it will appear sometimes to work but char *s = (char *)glGetString(GL_VERSION); shows version 1.1.In my case, on Mac I did  SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32); which, on Windows, silently throws you back to the OpenGL 1.1 software renderer. Do SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); instead.
  • Another SDL2 thing… A full screen SDL2 window will steal the whole monitor’s focus even before it’s visible. Very confusing if you’re debug-stepping (and potentially forces you to reboot, if you have just one screen). Start with a non-full screen window.
  • But everything ran so slowly. Shockingly slowly, absurdly slowly. Add this preprocessor directive at the project level: _HAS_ITERATOR_DEBUGGING=0.
  • Also set the Debug Information Format to Program Database (/Zi), instead of the more elaborate Edit-and-continue enabled one.

But mainly, OMG! My Windows build works!! All scripted and automated, too.

Porting to Windows

Finally obtained a Windows computer. Microsoft now makes a fully featured edition of Visual Studio available for free! “Community Edition VS2015”, so, we’re off.

Project up and running pretty easily, a few unix/mac-isms/g++-isms removed. But… the unit tests pass (minus 11 that I temporarily disabled)… but…

On Mac:

     0.  ok       undisposed objects 0(0) == MeObjectBase::currentCount(0)
     0.  ok       undisposed mallocs 0(0) == MeObjectBase::mallocCount - MeObjectBase::freeCount(0)
test results: 11148 pass / 11148 assertions (0.603 seconds)
---------------------
 aok
---------------------

On Windows:

     0.  ok       undisposed objects 0(0) == MeObjectBase::currentCount(0)
     0.  ok       undisposed mallocs 0(0) == MeObjectBase::mallocCount - MeObjectBase::freeCount(0)
test results: 11137 pass / 11137 assertions (19.599 seconds)
---------------------
 aok
---------------------

Well, ok then. Next bit of work is clear!