CPixmap

Header: include/pixmap.hpp
Implementation: src/pixmap.cpp (~1,922 lines) + src/pixtables.cpp (static lookup tables)

CPixmap is the DirectDraw surface manager. It owns all image surfaces, manages the 15 render channels, handles sprite blitting, and drives the final display flip from the back buffer to the screen. All drawing in Free Eggbert goes through CPixmap.

Overview

CPixmap wraps DirectDraw (DirectX 3) surfaces and exposes a higher-level API for loading sprite sheets, drawing sprites, and compositing the scene. Via Free Direct, these DirectDraw calls are translated to SDL3.

FileRoleStatus
src/pixmap.cpp DirectDraw surface allocation, blitting, sprite drawing, display flip Done
src/pixtables.cpp Static lookup tables for pixmap operations Done

The 15 Image Channels

CPixmap manages up to 15 simultaneous DirectDraw surfaces, each identified by a channel enum defined in include/def.hpp. Each channel holds the sprite sheet for one visual category.

EnumValueLoaded from (IMAGE08/IMAGE16)
CHBACK0decor000–031.blp (selected by region)
CHOBJECT1object.blp
CHBLUPI2blupi000.blp (default player)
CHDECOR3Decorative overlay layer
CHBUTTON4button.blp
CHJAUGE5jauge.blp (always 8-bit)
CHTEXT6text.blp
CHLITTLE7littletxt.blp
CHMAP8map.blp (always 8-bit)
CHEXPLO9explo.blp
CHELEMENT10element.blp
CHBLUPI111blupi001.blp
CHBLUPI212blupi002.blp
CHBLUPI313blupi003.blp
CHTEMP / CHMAX14Temporary scratch surface

See Image Channels Reference for full details and the note on CHJAUGE and CHMAP always being 8-bit.

Key Methods

Full signatures from include/pixmap.hpp:

// Initialization
BOOL Create(HWND hwnd, POINT dim, BOOL bFullScreen,
            int mouseType, BOOL bTrueColor, BOOL bTrueColorDecor);
BOOL CacheAll(BOOL cache, HWND hWnd, BOOL bFullScreen,
              BOOL bTrueColor, BOOL bTrueColorDecor,
              int mouseType, const char* pFilename, int region);
BOOL Restore();
BOOL Flush();

// Loading channels
BOOL Cache(int channel, char* pFilename,
           POINT totalDim, POINT iconDim, BOOL bUsePalette);
BOOL BackgroundCache(int channel, const char* pFilename,
                     POINT totalDim, POINT iconDim, BOOL bUsePalette);
void Flush(int channel);

// Drawing (chDst = destination channel/surface)
BOOL DrawIcon(int chDst, int channel, int rank,
              POINT pos, int mode=0, BOOL bMask=FALSE);
BOOL DrawIconDemi(int chDst, int channel, int rank,
                  POINT pos, int mode=0, BOOL bMask=FALSE);
BOOL DrawIconPart(int chDst, int channel, int rank,
                  POINT pos, int startY, int endY,
                  int mode=0, BOOL bMask=FALSE);
BOOL DrawPart(int chDst, int channel,
              POINT dest, RECT rect, int mode=0, BOOL bMask=FALSE);
BOOL DrawImage(int chDst, int channel, RECT rect, int mode=0);
BOOL DrawMap(int channel, RECT src, RECT dest);
void HudIcon(int channel, int rank, POINT pos);
void QuickIcon(int channel, int rank, POINT pos);

// Display
BOOL Display();               // flip back buffer to screen
void Fill(RECT rect, COLORREF color);

// Mouse cursor
void SetMousePosSprite(POINT pos, int sprite, BOOL bDemoPlay);
void MouseShow(BOOL bShow);

// Color depth
void SetTrueColorBack(BOOL bTrueColor);
void SetTrueColorDecor(BOOL bTrueColorDecor);
BOOL GetTrueColorBack();
BOOL GetTrueColorDecor();

Render Pipeline

Each frame, CDecor::Build() orchestrates rendering through CPixmap:

  1. Clear the back buffer (channel CHBACK terrain drawn first)
  2. Draw background decor tiles from the current region sheet
  3. Draw foreground objects from CHOBJECT
  4. Draw player character from CHBLUPI (or CHBLUPI1–3 in multiplayer)
  5. Draw explosions from CHEXPLO
  6. Draw UI elements (buttons, gauges) from CHBUTTON / CHJAUGE
  7. Draw text overlays from CHTEXT / CHLITTLE
  8. Call Display() to present the final frame

Color Depth Modes

CPixmap supports 8-bit (palette) and 16-bit (true color) surfaces. The mode is set via config.def keys TrueColorBack and TrueColorDecor. IMAGE16 is the default for character/decor sprites; IMAGE08 is used when configured to 8-bit mode.

ℹ️
jauge.blp and map.blp do not have IMAGE16 counterparts — they are always loaded from IMAGE08 regardless of the color depth setting.

Known Decompilation Issues

🚨
Double Create() call
The decompiled startup code calls CPixmap::Create() twice: once directly in DoInit() and again inside CacheAll(). Under real DirectDraw 3 this could produce DDERR_PRIMARYSURFACEALREADYEXISTS or DDERR_EXCLUSIVEMODEALREADYSET. Free Direct currently tolerates this; the root cause is under investigation.
⚠️
Parameter swap: bTrueColorBack / bTrueColorDecor
The declaration in pixmap.hpp and the definition in pixmap.cpp have the bTrueColor and bTrueColorDecor parameters in the opposite order, causing the wrong value to be used for each setting. See Decompilation Notes.
⚠️
delete this in CacheAll(FALSE)
CacheAll(FALSE, ...) contains a delete this pattern copied directly from the decompiled binary. This is inherently unsafe in C++ and is guarded by the _LEGACY compile flag.