MSVCPygame

I wanted to build Pygame using the latest SDL and Python2.4/2.5. The simplest course seemed to be to use the Microsoft Visual C++ Toolkit 2003 compiler version 7.1 (available here from the MIDAS project - thanks Brian!) to build all the Pygame dependencies.

Here is the result of my efforts:

I used these articles to help setup my environment:

Use (a tweaked version of) this batch-file to setup the environment and put it in the root of the drive you are going to build on:

@echo off
rem vc7-Py.bat, copied to the command path for the machine
rem 
rem For multiple Python installations I use a system wide variable:
rem AA_PYTHON_PATH that points to the current one (AA_* so that it's
rem at the top of the list in the 'System Variables' list).
rem 
rem The various drive letters and paths will need tweaking for any 
rem given system.

set TOOLKIT=E:\programs\Microsoft Visual C++ Toolkit 2003
set SDK=E:\programs\Microsoft SDK
set NET=C:\Program Files\Microsoft Visual Studio .NET 2003

set PATH=%TOOLKIT%\bin;%SDK%\Bin;%SDK%\Bin\Win64;%PATH%
set INCLUDE=%TOOLKIT%\include;%SDK%\include;%AA_PYTHON_PATH%\include;
set LIB=%NET%\Vc7\lib;%TOOLKIT%\lib;%SDK%\Lib;%AA_PYTHON_PATH%\libs;
set MSDevDir=

The above is based on the one from the above article, but makes an extra effort to trash any residual MSVC6 environment.

A minimal check of the installation:

E:\dev\ms-dev>\vc7-py
E:\dev\ms-dev>cl
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

E:\dev\ms-dev>

Obtain the DirectX SDK headers and lib files from Microsoft (I had the SDK CD from years back) and make 'include' and 'lib' directories inside a 'dx7' directory in '\dev\ms-dev\'. Copy the header and lib files into the appropriate places.

SDL

Extract the source into the '\dev\ms-dev\' directory, then extract the 'VisualC.zip' in-place so that it make a 'VisualC' sub-directory off 'SDL-1.2.12\'.

Download these files:

and put them into 'SDL-1.2.12\VisualC\SDL\', then download these files:

and put them into 'SDL-1.2.12\VisualC\SDLmain\'.

Build SDL with these commands:

\vc7-py.bat
cd \dev\ms-dev\SDL-1.2.12\VisualC\SDL
nmake -fSDL.MAK CFG="SDL - Win32 Release"
cd ..\SDLmain
nmake -fSDLmain.MAK CFG="SDLmain - Win32 Release"
nmake -fSDLmain.mak CFG="SDLmain - Win32 Release_NoSTDIO"
ren Release_NOSTDIO\SDLmain.lib SDLmain_noredirect.lib

Prepare for using these files with PyGame by creating a "prebuilt" directory and populating it with the required files:

cd \dev\ms-dev
mkdir prebuilt
mkdir prebuilt\include
mkdir prebuilt\lib
copy SDL-1.2.12\VisualC\SDL\Release\SDL.dll prebuilt\lib
copy SDL-1.2.12\VisualC\SDL\Release\SDL.lib prebuilt\lib
copy SDL-1.2.12\VisualC\SDLmain\Release\SDLmain.lib prebuilt\lib
copy SDL-1.2.12\VisualC\SDLmain\Release_NOSTDIO\SDLmain_noredirect.lib prebuilt\lib
copy SDL-1.2.12\include\* prebuilt\include

To make building the test programs easier, I made these two batch-files build.bat and buildall.bat which should be put into the 'SDL-1.2.12\test' directory along with a copy of 'SDL.dll'. Then build them all by running 'buildall.bat' in the test directory:

cd \dev\ms-dev\SDL-1.2.12\test
buildall

To just build this one:

cd \dev\ms-dev\SDL-1.2.12\test
build testfile

Note: the dropped '.c' from the filename.

The back-end can be switched between GDI and DirectX using one of the following:

set SDL_VIDEODRIVER=windib
set SDL_VIDEODRIVER=directx

The 'testvidinfo.exe' program is useful (although not very exciting!) when experimenting:

E:\>set SDL_VIDEODRIVER=windib
E:\>testvidinfo
Video driver: windib
Current display: 1280x1024, 32 bits-per-pixel
        Red Mask = 0x00ff0000
        Green Mask = 0x0000ff00
        Blue Mask = 0x000000ff
Fullscreen video modes:
        1600x1200x32
        1440x900x32
        1360x1024x32
        1360x768x32
        1280x1024x32
        1280x960x32
        1280x768x32
        1280x720x32
        1152x864x32
        1024x768x32
        848x480x32
        800x600x32
        720x576x32
        720x480x32
        640x480x32
        640x400x32
        512x384x32
        400x300x32
        320x240x32
        320x200x32
A window manager is available


E:\>set SDL_VIDEODRIVER=directx
E:\>testvidinfo
Video driver: directx
Current display: 1280x1024, 32 bits-per-pixel
        Red Mask = 0x00ff0000
        Green Mask = 0x0000ff00
        Blue Mask = 0x000000ff
Fullscreen video modes:
        1600x1200x32
        1440x900x32
        1360x1024x32
        1360x768x32
        1280x1024x32
        1280x960x32
        1280x768x32
        1280x720x32
        1152x864x32
        1024x768x32
        848x480x32
        800x600x32
        720x576x32
        720x480x32
        640x480x32
        640x400x32
        512x384x32
        400x300x32
        320x240x32
        320x200x32
A window manager is available
Hardware surfaces are available (312151K video memory)
Copy blits between hardware surfaces are accelerated
Colorkey blits between hardware surfaces are accelerated
Copy blits from software surfaces to hardware surfaces are accelerated
Colorkey blits from software surfaces to hardware surfaces are accelerated
Color fills on hardware surfaces are accelerated

All the other test programs should work. Help is (usually) available by putting ' --help' on the command-line. It's worth running 'testgl' to make sure that OpenGL support was successfully built-in.

zlib

Extract the files into '\dev\ms-dev\' and build it like this:

\vc7-py.bat
cd \dev\ms-dev\zlib-1.2.3
nmake -f win32/Makefile.msc

Test it like this:

nmake -f win32/Makefile.msc test
nmake -f win32/Makefile.msc testdll

Install it like this:

cd \dev\ms-dev
copy zlib-1.2.3\zlib1.dll prebuilt\lib
copy zlib-1.2.3\zdll.lib prebuilt\lib\zlib1.lib
copy zlib-1.2.3\zlib.h prebuilt\include
copy zlib-1.2.3\zconf.h prebuilt\include

libpng

Download the following files:

and put them into the 'libpng-1.2.22\projects\visualc6\' directory.

Build it like this:

cd \dev\ms-dev\libpng-1.2.22\projects\visualc6
nmake /flibpng.mak CFG="libpng - Win32 DLL Release"

Test it like this:

nmake /fpngtest.mak CFG="pngtest - Win32 DLL Release"

Install it like this:

cd \dev\ms-dev
copy libpng-1.2.22\projects\visualc6\Win32_DLL_Release\libpng13.dll prebuilt\lib
copy libpng-1.2.22\projects\visualc6\Win32_DLL_Release\libpng13.lib prebuilt\lib
copy libpng-1.2.22\png.h prebuilt\include
copy libpng-1.2.22\pngconf.h prebuilt\include

libjpeg

Download the following files:

and put them into 'jpeg-6b\'. Make sure you delete the originals and rename the new ones.

Build it like this:

cd \dev\ms-dev\jpeg-6b
copy jconfig.vc jconfig.h
nmake /fmakefile.vc

Test it like this:

nmake /fmakefile.vc test

Install it like this:

cd \dev\ms-dev
copy jpeg-6b\libjpeg.dll prebuilt\lib
copy jpeg-6b\libjpeg.lib prebuilt\lib
copy jpeg-6b\jconfig.h prebuilt\include
copy jpeg-6b\jerror.h prebuilt\include
copy jpeg-6b\jmorecfg.h prebuilt\include
copy jpeg-6b\jpeglib.h prebuilt\include

libtiff

Download the following files:

and put 'nmake.opt' into 'tiff-3.8.2\' and 'Makefile.vc' into 'tiff-3.8.2\libtiff\'. Make sure you delete the originals and rename the new ones.

Build it like this:

cd \dev\ms-dev\tiff-3.8.2
nmake /f makefile.vc lib

Install it like this:

cd \dev\ms-dev
copy tiff-3.8.2\libtiff\libtiff.dll prebuilt\lib
copy tiff-3.8.2\libtiff\libtiff_i.lib prebuilt\lib\libtiff.lib
copy tiff-3.8.2\libtiff\tiff.h prebuilt\include
copy tiff-3.8.2\libtiff\tiffconf.h prebuilt\include
copy tiff-3.8.2\libtiff\tiffio.h prebuilt\include
copy tiff-3.8.2\libtiff\tiffvers.h prebuilt\include

SDL_image

Extract the source into the '\dev\ms-dev\' directory, then extract the 'VisualC.zip' in-place so that it makes a 'VisualC' sub-directory off 'SDL_image-1.2.6\'.

Download the following files:

and put all but the last two into 'SDL_image-1.2.6\VisualC\'. Don't forget to rename 'Version.rc.SDL_image'. Put the last two 'showimage' files into 'SDL_image-1.2.6\VisualC\showimage\'.

When Py2exe uses "bundle_files":1 (almost everything in one .exe) the dynamic loading of libpng, libjpeg and libtiff doesn't work so I build all my DLLs 'statically' as it were.

Build it like this:

cd \dev\ms-dev\SDL_image-1.2.6\VisualC\
nmake /f"SDL_image-static.mak" CFG="SDL_image - Win32 Release"
or
nmake /f"SDL_image-dynamic.mak" CFG="SDL_image - Win32 Release"

Install it like this:

cd \dev\ms-dev
copy SDL_image-1.2.6\VisualC\Release\SDL_image.dll prebuilt\lib
copy SDL_image-1.2.6\VisualC\Release\SDL_image.lib prebuilt\lib
copy SDL_image-1.2.6\SDL_image.h prebuilt\include

Test it like this:

cd \dev\ms-dev\SDL_image-1.2.6\VisualC\showimage
nmake /f"showimage.mak" CFG="showimage - Win32 Release"
cd \dev\ms-dev
copy SDL_image-1.2.6\VisualC\showimage\Release\showimage.exe prebuilt\lib

prebuilt\lib\showimage.exe jpeg-6b\testimg.bmp
prebuilt\lib\showimage.exe jpeg-6b\testimg.jpg
prebuilt\lib\showimage.exe jpeg-6b\testimg.ppm
prebuilt\lib\showimage.exe libpng-1.2.22\pngbar.png
prebuilt\lib\showimage.exe libpng-1.2.22\pngnow.png
prebuilt\lib\showimage.exe libpng-1.2.22\pngtest.png

I found some other image types like '.tga' and '.gif' lurking on my machine, but I downloaded these [WWW] test tif images and checked libtiff support like this:

prebuilt\lib\showimage libtiffpic/cramps.tif
prebuilt\lib\showimage libtiffpic/cramps-tile.tif
prebuilt\lib\showimage libtiffpic/dscf0013.tif
prebuilt\lib\showimage libtiffpic/fax2d.tif
prebuilt\lib\showimage libtiffpic/g3test.tif
prebuilt\lib\showimage libtiffpic/jello.tif
prebuilt\lib\showimage libtiffpic/jim___ah.tif
prebuilt\lib\showimage libtiffpic/jim___cg.tif
prebuilt\lib\showimage libtiffpic/jim___dg.tif
prebuilt\lib\showimage libtiffpic/jim___gg.tif
prebuilt\lib\showimage libtiffpic/off_l16.tif
prebuilt\lib\showimage libtiffpic/off_luv24.tif
prebuilt\lib\showimage libtiffpic/off_luv32.tif
prebuilt\lib\showimage libtiffpic/oxford.tif
prebuilt\lib\showimage libtiffpic/pc260001.tif
prebuilt\lib\showimage libtiffpic/quad-jpeg.tif
prebuilt\lib\showimage libtiffpic/quad-lzw.tif
prebuilt\lib\showimage libtiffpic/quad-tile.tif
prebuilt\lib\showimage libtiffpic/strike.tif
prebuilt\lib\showimage libtiffpic/text.tif
prebuilt\lib\showimage libtiffpic/ycbcr-cat.tif

libogg

Download the following files:

and put them into the 'libogg-1.1.3\win32\' directory.

Build it like this:

cd \dev\ms-dev\libogg-1.1.3\win32
nmake /fogg_dynamic.mak CFG="ogg_dynamic - Win32 Release"

Install it like this:

cd \dev\ms-dev
copy libogg-1.1.3\win32\Dynamic_Release\ogg.dll prebuilt\lib
copy libogg-1.1.3\win32\Dynamic_Release\ogg.lib prebuilt\lib
mkdir prebuilt\include\ogg
copy libogg-1.1.3\include\ogg\ogg.h prebuilt\include\ogg
copy libogg-1.1.3\include\ogg\os_types.h prebuilt\include\ogg

libvorbis

Download the following files:

and put them into 'libvorbis-1.2.0\win32\'.

Build it like this:

cd \dev\ms-dev\libvorbis-1.2.0\win32
nmake /fvorbis_dynamic.mak CFG="vorbis_dynamic - Win32 Release"
nmake /fvorbisenc_dynamic.mak CFG="vorbisenc_dynamic - Win32 Release"
nmake /fvorbisfile_dynamic.mak CFG="vorbisfile_dynamic - Win32 Release"

Install it like this:

cd \dev\ms-dev
copy libvorbis-1.2.0\win32\Vorbis_Dynamic_Release\vorbis.dll prebuilt\lib
copy libvorbis-1.2.0\win32\Vorbis_Dynamic_Release\vorbis.lib prebuilt\lib
copy libvorbis-1.2.0\win32\Vorbisenc_Dynamic_Release\vorbisenc.dll prebuilt\lib
copy libvorbis-1.2.0\win32\Vorbisenc_Dynamic_Release\vorbisenc.lib prebuilt\lib
copy libvorbis-1.2.0\win32\Vorbisfile_Dynamic_Release\vorbisfile.dll prebuilt\lib
copy libvorbis-1.2.0\win32\Vorbisfile_Dynamic_Release\vorbisfile.lib prebuilt\lib
mkdir prebuilt\include\vorbis
copy libvorbis-1.2.0\include\vorbis\codec.h prebuilt\include\vorbis
copy libvorbis-1.2.0\include\vorbis\vorbisenc.h prebuilt\include\vorbis
copy libvorbis-1.2.0\include\vorbis\vorbisfile.h prebuilt\include\vorbis

smpeg

Checkout the current version from svn using the instructions on the above page. If you don't already have 'Subversion' installed try: svn-1.4.5-setup.exe.

For example, in a Windows command prompt:

D:\>cd \dev\ms-dev
D:\dev\ms-dev>svn co svn://svn.icculus.org/smpeg/trunk smpeg

Extract the 'VisualC.zip' file in-place so that it makes a 'VisualC' sub-directory off 'smpeg'.

Download the following files:

and copy the first two into 'smpeg\VisualC\', and the second two into 'smpeg\VisualC\plaympeg\'.

Build it like this:

cd \dev\ms-dev\smpeg\VisualC
nmake /f"smpeg.mak" CFG="smpeg - Win32 Release"

Install it like this:

cd \dev\ms-dev
copy smpeg\VisualC\Release\smpeg.dll prebuilt\lib
copy smpeg\VisualC\Release\smpeg.lib prebuilt\lib
mkdir prebuilt\include\smpeg
copy smpeg\MPEG*.h prebuilt\include\smpeg
copy smpeg\smpeg.h prebuilt\include\smpeg

Test it like this:

cd \dev\ms-dev\smpeg\VisualC\plaympeg
nmake /f"plaympeg.mak" CFG="plaympeg - Win32 Release"
cd \dev\ms-dev
copy smpeg\VisualC\plaympeg\Release\plaympeg.exe prebuilt\lib

prebuilt\lib\plaympeg.exe c:\home\Media\butterfly.mpg
prebuilt\lib\plaympeg.exe c:\home\Media\lake.mpg
prebuilt\lib\plaympeg.exe c:\home\Media\MIX2.2.mpg
prebuilt\lib\plaympeg.exe  --novideo c:\home\Media\piano.mp3
prebuilt\lib\plaympeg.exe  --novideo c:\home\Media\roadhouse_blues.mp3

SDL_mixer

Extract the source into the '\dev\ms-dev\' directory, then extract the 'VisualC.zip' in-place so that it makes a 'VisualC' sub-directory off 'SDL_mixer-1.2.8\'.

Download the following files:

and copy the first four into 'SDL_mixer-1.2.8\VisualC\' (don't forget to rename Version.rc.SDL_mixer), and the other four pairs of files into the appropriate sub-directory off 'SDL_mixer-1.2.8\VisualC\'.

When Py2exe uses "bundle_files":1 (almost everything in one .exe) the dynamic loading of smpeg, and vorbisfile doesn't work so I built all my DLLs 'statically' as it were.

Build it like this:

cd \dev\ms-dev\SDL_mixer-1.2.8\VisualC
nmake /fSDL_mixer-static.mak CFG="SDL_mixer - Win32 Release"
or
nmake /fSDL_mixer-dynamic.mak CFG="SDL_mixer - Win32 Release"

Install it like this:

cd \dev\ms-dev
copy SDL_mixer-1.2.8\VisualC\Release\SDL_mixer.dll prebuilt\lib
copy SDL_mixer-1.2.8\VisualC\Release\SDL_mixer.lib prebuilt\lib
copy SDL_mixer-1.2.8\SDL_mixer.h prebuilt\include

Test it like this:

cd \dev\ms-dev\SDL_mixer-1.2.8\VisualC\playmus
nmake /fplaymus.mak CFG="playmus - Win32 Release"
cd \dev\ms-dev\
copy \dev\ms-dev\SDL_mixer-1.2.8\VisualC\playmus\Release\playmus.exe prebuilt\lib

prebuilt\lib\playmus.exe c:\home\Media\wonrace1-jt.it
prebuilt\lib\playmus.exe c:\home\Media\gtrsolo2.mid
prebuilt\lib\playmus.exe c:\home\Media\Chipgene.mod
prebuilt\lib\playmus.exe c:\home\Media\track1.mp3
prebuilt\lib\playmus.exe c:\home\Media\keepgoin.ogg
prebuilt\lib\playmus.exe c:\home\Media\bizzarre-funfair.s3m
prebuilt\lib\playmus.exe c:\home\Media\wahoo.wav

freetype

Download the following files:

and put them into the 'freetype-2.3.5\builds\win32\visualc\' directory.

Build it like this:

cd \dev\ms-dev\freetype-2.3.5\builds\win32\visualc
nmake /ffreetype.mak CFG="freetype - Win32 Release"

Install it like this:

cd \dev\ms-dev
copy freetype-2.3.5\objs\freetype235.lib prebuilt\lib
xcopy /S freetype-2.3.5\include\* prebuilt\include

SDL_ttf

Extract the source into the '\dev\ms-dev\' directory, then extract the 'VisualC.zip' in-place so that it makes a 'VisualC' sub-directory off 'SDL_ttf-2.0.9\'.

Download the following files:

and put the first three files into 'SDL_ttf-2.0.9\VisualC\' (don't forget to rename 'Version.rc.SDL_ttf') and the other two pairs into the appropriate sub-directory off 'SDL_ttf-2.0.9\VisualC\'.

Build it like this:

cd \dev\ms-dev\SDL_ttf-2.0.9\VisualC
nmake /f SDL_ttf.mak CFG="SDL_ttf - Win32 Release"

Install it like this:

cd \dev\ms-dev
copy SDL_ttf-2.0.9\VisualC\Release\SDL_ttf.dll prebuilt\lib
copy SDL_ttf-2.0.9\VisualC\Release\SDL_ttf.lib prebuilt\lib
copy SDL_ttf-2.0.9\SDL_ttf.h prebuilt\include

Test it like this:

cd \dev\ms-dev\SDL_ttf-2.0.9\VisualC\showfont
nmake /f showfont.mak CFG="showfont - Win32 Release"
cd \dev\ms-dev\SDL_ttf-2.0.9\VisualC\glfont
nmake /f glfont.mak CFG="glfont - Win32 Release"
cd \dev\ms-dev
copy \dev\ms-dev\SDL_ttf-2.0.9\VisualC\showfont\Release\showfont.exe prebuilt\lib
copy \dev\ms-dev\SDL_ttf-2.0.9\VisualC\glfont\Release\glfont.exe prebuilt\lib

prebuilt\lib\showfont.exe c:\windows\fonts\arial.ttf 32 "Hello world!"
prebuilt\lib\showfont.exe -solid c:\windows\fonts\arial.ttf 32 "More than one word!"
prebuilt\lib\glfont.exe c:\windows\fonts\arial.ttf 32 "Hello world."

Note: you might need to tweak the path to the fonts depending on your OS.

Pygame

Checkout the current version from svn using the instructions on the above page. I use a Windows native version of svn in a command-prompt like this:

cd \dev\ms-dev
mkdir pygame
cd pygame
svn co svn://seul.org/svn/pygame/trunk
...
...
Checked out revision 1052.

Copy the 'prebuilt' directory generated above into the 'trunk' directory.

I tried configuring first:

cd \dev\ms-dev\pygame\trunk
python config.py
Using WINDOWS configuration...

Use the SDL libraries in "prebuilt"? [Y/n]y

There was an error creating the Setup file, check for errors
or make a copy of "Setup.in" and edit by hand.

This didn't seem to work properly so I just manually edited the 'Setup' file that the above step generates: Setup

Unfortunately, the SVN revision 1052 version of 'src/transform.c' doesn't build with the MS compiler and needs patching. If you don't have the 'patch' tool try downloading the GNU utilities for Win32. Then download this patch pygame-transform.c.diff into '\dev\ms-dev\pygame\' and apply it like this:

cd \dev\ms-dev\pygame\trunk
patch -p0 < ..\pygame-transform.c.diff

Build it like this:

cd \dev\ms-dev\pygame\trunk
python setup.py build

Install it like this:

python setup.py install

Test it like this:

cd \dev\ms-dev\pygame\trunk
python run_tests.py
loading base_test
loading blit_test
loading mask_test
loading transform_test
loading rect_test
loading pixelarray_test
loading image_test
loading display_test
loading font_test
loading sprite_test
loading surface_test
...............................................................................................
----------------------------------------------------------------------
Ran 95 tests in 1.219s

OK

and like this:

cd examples
python aliens.py
python arraydemo.py
python blend_fill.py
python blit_blends.py
python chimp.py
python cursors.py
python eventlist.py
python fastevents.py
python fonty.py
python glcube.py                                         [requires PyOpenGL  ]
python liquid.py
python mask.py data\alien1.gif
python moveit.py
python oldalien.py
python overlay.py data\yuv_1.pgm
python pixelarray.py
python scaletest.py ..\..\..\jpeg-6b\testimg.jpg         [use the cursor-keys]
python scrap_clipboard.py                                [use g, p, a, i keys]
python sound.py
python sound_array_demos.py
python stars.py
python testsprite.py
python vgrade.py

and like this:

python
>>> import pygame
>>> pygame.init()
(6, 0)
>>> ^Z







Valid HTML 4.01!