15#ifndef DDSCAPS_3DDEVICE
16#define DDSCAPS_3DDEVICE 0x00002000l
67 DWORD dwRGBBitCount = 8;
71 if (!DirectDrawCreate(
NULL, &pDDraw,
NULL)) {
72 memset(&ddsd, 0,
sizeof(ddsd));
73 ddsd.
dwSize =
sizeof(ddsd);
75 pDDraw->GetDisplayMode(&ddsd);
89 BOOL surface_fullscreen,
90 BOOL onlySystemMemory,
94 const PALETTEENTRY* pPaletteEntries,
120 if (!
DDInit(fullscreen)) {
148 ReleaseDC(
NULL, hdc);
163 ReleaseDC(
NULL, hdc);
166 for (i = 0; i < 10; i++) {
170 for (; i < 142; i++) {
174 for (; i < 246; i++) {
178 for (; i < 256; i++) {
182 if (paletteEntryCount != 0) {
185 for (i = 10; (i < paletteEntryCount) && (i < 246); i++) {
196 if (result !=
DD_OK) {
197 Error(
"SetEntries failed", result);
275 if (result !=
DD_OK) {
276 Error(
"SetCooperativeLevel failed", result);
306 static DWORD g_dwStyle;
309 g_dwStyle = GetWindowLong(p_hwnd, GWL_STYLE);
310 if (g_dwStyle & WS_THICKFRAME) {
311 SetWindowLong(p_hwnd, GWL_STYLE, GetWindowLong(p_hwnd, GWL_STYLE) ^ WS_THICKFRAME);
315 SetWindowLong(p_hwnd, GWL_STYLE, g_dwStyle);
331 result = DirectDrawCreate(0, &lpDD, 0);
332 if (result ==
DD_OK) {
334 if (result ==
DD_OK) {
335 lpDD->SetDisplayMode(width, height, 8);
350 if (result !=
DD_OK) {
351 Error(
"SetDisplayMode failed", result);
361 "Attempt made enter a windowed mode on a DirectDraw device that is not the primary display",
368 dwStyle = GetWindowLong(
m_hWndMain, GWL_STYLE);
369 dwStyle &= ~WS_POPUP;
370 dwStyle |= WS_OVERLAPPED | WS_CAPTION | WS_THICKFRAME;
371 SetWindowLong(
m_hWndMain, GWL_STYLE, dwStyle);
372 SetRect(&rc, 0, 0, width - 1, height - 1);
384 rc.right - rc.left + 1,
385 rc.bottom - rc.top + 1,
386 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE
388 SetWindowPos(
m_hWndMain, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
422 if (result !=
DD_OK) {
423 Error(
"CreatePalette failed", result);
428 if (result !=
DD_OK) {
429 Error(
"SetPalette failed", result);
464 result = lpDDSurf->GetSurfaceDesc(lpDDSurfDesc);
465 if (result !=
DD_OK) {
466 Error(
"Error getting a surface description", result);
469 return (result ==
DD_OK);
482 ddsd.
dwSize =
sizeof(ddsd);
490 if (result !=
DD_OK) {
491 Error(
"CreateSurface for front/back fullScreen buffer failed", result);
496 if (result !=
DD_OK) {
497 Error(
"GetAttachedSurface failed to get back buffer", result);
510 if (result !=
DD_OK) {
511 Error(
"CreateSurface for window front buffer failed", result);
522 if (result !=
DD_OK) {
523 Error(
"CreateSurface for window back buffer failed", result);
531 if (result !=
DD_OK) {
532 Error(
"CreateClipper failed", result);
536 if (result !=
DD_OK) {
537 Error(
"Clipper SetHWnd failed", result);
541 if (result !=
DD_OK) {
542 Error(
"SetClipper failed", result);
560 for (
int i = 0; i < count; i++) {
561 memset(&ddsd, 0,
sizeof(ddsd));
562 ddsd.
dwSize =
sizeof(ddsd);
570 if (result !=
DD_OK) {
578 memset(line, value, ddsd.
dwWidth);
603 result = pSurface->GetDC(&hdc);
604 if (result !=
DD_OK) {
605 Error(
"GetDC for text surface failed", result);
609 textLength = strlen(text);
612 SetTextColor(hdc, RGB(255, 255, 0));
613 SetBkColor(hdc, RGB(0, 0, 0));
614 SetBkMode(hdc, OPAQUE);
615 GetTextExtentPoint32(hdc, text, textLength, &textSizeOnSurface);
616 SetRect(&rc, 0, 0, textSizeOnSurface.cx, textSizeOnSurface.cy);
617 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, text, textLength,
NULL);
618 pSurface->ReleaseDC(hdc);
645 char dummyinfo[] =
"000x000x00 (RAMP) 0000";
646 char dummyfps[] =
"000.00 fps (000.00 fps (000.00 fps) 00000 tps)";
672 ReleaseDC(
NULL, hdc);
674 memset(&ddsd, 0,
sizeof(ddsd));
675 ddsd.
dwSize =
sizeof(ddsd);
684 if (result !=
DD_OK) {
685 Error(
"CreateSurface for text surface 1 failed", result);
688 memset(&ddck, 0,
sizeof(ddck));
694 memset(&ddsd, 0,
sizeof(ddsd));
695 ddsd.
dwSize =
sizeof(ddsd);
704 if (result !=
DD_OK) {
705 Error(
"CreateSurface for text surface 2 failed", result);
708 memset(&ddck, 0,
sizeof(ddck));
726 if (result !=
DD_OK) {
727 Error(
"Restore of front buffer failed", result);
736 if (result !=
DD_OK) {
737 Error(
"Restore of back buffer failed", result);
746 if (result !=
DD_OK) {
747 Error(
"Restore of Z-buffer failed", result);
756 if (result !=
DD_OK) {
757 Error(
"Restore of text surface 1 failed", result);
766 if (result !=
DD_OK) {
767 Error(
"Restore of text surface 2 failed", result);
784 memset(&ddsd, 0,
sizeof(ddsd));
785 ddsd.
dwSize =
sizeof(ddsd);
793 if (result !=
DD_OK) {
794 Error(
"CreateSurface for fullScreen Z-buffer failed", result);
799 if (result !=
DD_OK) {
800 Error(
"AddAttachedBuffer failed for Z-Buffer", result);
862 if (result !=
DD_OK) {
863 Error(
"SetEntries failed", result);
886 if (result !=
DD_OK) {
887 Error(
"SetEntries failed", result);
905 if (result !=
DD_OK) {
906 Error(
"FlipToGDISurface failed", result);
908 return (result ==
DD_OK);
922 if (g_isInsideError) {
926 g_isInsideError =
TRUE;
931 g_isInsideError =
FALSE;
942 return "This object is already initialized.";
944 return "Return if a clipper object is attached to the source surface passed into a BltFast call.";
946 return "This surface can not be attached to the requested surface.";
948 return "This surface can not be detached from the requested surface.";
950 return "Windows can not create any more DCs.";
952 return "Can't duplicate primary & 3D surfaces, or surfaces that are implicitly created.";
954 return "An attempt was made to set a cliplist for a clipper object that is already monitoring an hwnd.";
956 return "No src color key specified for this operation.";
958 return "Support is currently not available.";
960 return "A DirectDraw object representing this driver has already been created for this process.";
962 return "An exception was encountered while performing the requested operation.";
964 return "An attempt was made to set the cooperative level when it was already set to exclusive.";
966 return "Generic failure.";
968 return "Height of rectangle provided is not a multiple of reqd alignment.";
970 return "The CooperativeLevel HWND has already been set. It can not be reset while the process has surfaces or "
973 return "HWND used by DirectDraw CooperativeLevel has been subclassed, this prevents DirectDraw from restoring "
976 return "This surface can not be restored because it is an implicitly created surface.";
978 return "Unable to match primary surface creation request with existing primary surface.";
980 return "One or more of the caps bits passed to the callback are incorrect.";
982 return "DirectDraw does not support the provided cliplist.";
984 return "The GUID passed to DirectDrawCreate is not a valid DirectDraw driver identifier.";
986 return "DirectDraw does not support the requested mode.";
988 return "DirectDraw received a pointer that was an invalid DIRECTDRAW object.";
990 return "One or more of the parameters passed to the function are incorrect.";
992 return "The pixel format was invalid as specified.";
994 return "Returned when the position of the overlay on the destination is no longer legal for that "
997 return "Rectangle provided was invalid.";
999 return "Operation could not be carried out because one or more surfaces are locked.";
1001 return "There is no 3D present.";
1003 return "Operation could not be carried out because there is no alpha accleration hardware present or "
1006 return "No blitter hardware present.";
1008 return "No cliplist available.";
1010 return "No clipper object attached to surface object.";
1012 return "Operation could not be carried out because there is no color conversion hardware present or "
1015 return "Surface doesn't currently have a color key";
1017 return "Operation could not be carried out because there is no hardware support of the destination color "
1020 return "Create function called without DirectDraw object method SetCooperativeLevel being called.";
1022 return "No DC was ever created for this surface.";
1024 return "No DirectDraw ROP hardware.";
1026 return "A hardware-only DirectDraw object creation was attempted but the driver did not support any "
1029 return "Software emulation not available.";
1031 return "Operation requires the application to have exclusive mode but the application does not have exclusive "
1034 return "Flipping visible surfaces is not supported.";
1036 return "There is no GDI present.";
1038 return "Clipper notification requires an HWND or no HWND has previously been set as the CooperativeLevel "
1041 return "Operation could not be carried out because there is no hardware present or available.";
1043 return "Returned when GetOverlayPosition is called on an overlay that UpdateOverlay has never been called on "
1044 "to establish a destination.";
1046 return "Operation could not be carried out because there is no overlay hardware present or available.";
1048 return "No palette object attached to this surface.";
1050 return "No hardware support for 16 or 256 color palettes.";
1052 return "Operation could not be carried out because there is no appropriate raster op hardware present or "
1055 return "Operation could not be carried out because there is no rotation hardware present or available.";
1057 return "Operation could not be carried out because there is no hardware support for stretching.";
1059 return "DirectDrawSurface is not in 4 bit color palette and the requested operation requires 4 bit color "
1062 return "DirectDrawSurface is not in 4 bit color index palette and the requested operation requires 4 bit color "
1065 return "DirectDrawSurface is not in 8 bit color mode and the requested operation requires 8 bit color.";
1067 return "Returned when an overlay member is called for a non-overlay surface.";
1069 return "Operation could not be carried out because there is no texture mapping hardware present or "
1072 return "An attempt has been made to flip a surface that is not flippable.";
1074 return "Requested item was not found.";
1076 return "Surface was not locked. An attempt to unlock a surface that was not locked at all, or by this "
1077 "process, has been attempted.";
1079 return "The surface being used is not a palette-based surface.";
1081 return "Operation could not be carried out because there is no hardware support for vertical blank "
1082 "synchronized operations.";
1084 return "Operation could not be carried out because there is no hardware support for zbuffer blitting.";
1086 return "Overlay surfaces could not be z layered based on their BltOrder because the hardware does not support "
1087 "z layering of overlays.";
1089 return "The hardware needed for the requested operation has already been allocated.";
1091 return "DirectDraw does not have enough memory to perform the operation.";
1093 return "DirectDraw does not have enough memory to perform the operation.";
1095 return "The hardware does not support clipped overlays.";
1097 return "Can only have ony color key active at one time for overlays.";
1099 return "Returned when GetOverlayPosition is called on a hidden overlay.";
1101 return "Access to this palette is being refused because the palette is already locked by another thread.";
1103 return "This process already has created a primary surface.";
1105 return "Region passed to Clipper::GetClipList is too small.";
1107 return "This surface is already attached to the surface it is being attached to.";
1109 return "This surface is already a dependency of the surface it is being made a dependency of.";
1111 return "Access to this surface is being refused because the surface is already locked by another thread.";
1113 return "Access to surface refused because the surface is obscured.";
1115 return "Access to this surface is being refused because the surface memory is gone. The DirectDrawSurface "
1116 "object representing this surface should have Restore called on it.";
1118 return "The requested surface is not attached.";
1120 return "Height requested by DirectDraw is too large.";
1122 return "Size requested by DirectDraw is too large, but the individual height and width are OK.";
1124 return "Width requested by DirectDraw is too large.";
1126 return "Action not supported.";
1128 return "FOURCC format requested is unsupported by DirectDraw.";
1130 return "Bitmask in the pixel format requested is unsupported by DirectDraw.";
1132 return "Vertical blank is in progress.";
1134 return "Informs DirectDraw that the previous Blt which is transfering information to or from this Surface is "
1137 return "This surface can not be restored because it was created in a different mode.";
1139 return "Rectangle provided was not horizontally aligned on required boundary.";
1141 return "Unrecognized error value.";
Class responsible for interfacing with DirectDraw to manage rendering surfaces, palettes,...
void FUN_1009d920()
Internal: Restores original palette and resets display mode and cooperative level.
IDirectDrawSurface * m_pBackBuffer
Backbuffer for offscreen rendering/flipping. [AI].
BOOL IsSupportedMode(int width, int height, int bpp)
Checks if the given mode (resolution, bpp) is supported by the current device.
PALETTEENTRY m_originalPaletteEntries[256]
Backup of system/Windows palette for restoration. [AI].
BOOL m_bIgnoreWMSIZE
Internal flag to suppress window resize messages during device switching. [AI].
BOOL DDInit(BOOL fullscreen)
Initializes DirectDraw cooperative level for fullscreen or windowed mode.
PALETTEENTRY m_paletteEntries[256]
Active 8-bit palette entries for palettized modes. [AI].
BOOL SetPaletteEntries(const PALETTEENTRY *pPaletteEntries, int paletteEntryCount, BOOL fullscreen)
Sets the DirectDraw palette using the provided palette entries.
BOOL m_bOnlySoftRender
If TRUE, restricts rendering to software only; disables hardware acceleration. [AI].
HRESULT CreateDDSurface(LPDDSURFACEDESC a2, LPDIRECTDRAWSURFACE *a3, IUnknown *a4)
Creates a DirectDraw surface with the given surface description.
IDirectDrawClipper * m_pClipper
Clipper for managing windowed surface boundaries. [AI].
BOOL CacheOriginalPaletteEntries()
Caches the original Windows/system palette for restoration.
IDirectDrawSurface * m_pText2Surface
Debug overlay surface for "text2". [AI].
static int GetPrimaryBitDepth()
Returns the bit depth (color depth) of the primary display device.
BOOL m_bPrimaryPalettized
TRUE if primary/backbuffer is using 8-bit palettized mode. [AI].
virtual const char * ErrorToString(HRESULT p_error)
Converts DirectDraw error code to a human-readable string.
ErrorHandler m_pErrorHandler
Callback for non-fatal DirectDraw errors. [AI].
IDirectDrawSurface * m_pZBuffer
Attached Z-buffer for 3D rendering. [AI].
SIZE m_text2SizeOnSurface
Pixel size of rendered text2 overlay surface. [AI].
DeviceModesInfo::Mode m_currentMode
Struct with current width, height, and bits per pixel. [AI].
HFONT m_hFont
Font handle for debug text overlays. [AI].
BOOL TextToTextSurface(const char *text, IDirectDrawSurface *pSurface, SIZE &textSizeOnSurface)
Renders a string to the given surface and fills in its onscreen size.
BOOL TextToTextSurface1(const char *text)
Draws the specified text string to the debug "text1" surface.
DeviceModesInfo * m_currentDevInfo
Device info array for storing supported display modes. [AI].
int FlipToGDISurface()
Flips to the Windows GDI surface, restoring the desktop when leaving exclusive fullscreen.
BOOL DDCreateSurfaces()
Internal: Creates all necessary front/back/offscreen surfaces for rendering.
BOOL m_bOnlySystemMemory
TRUE for system RAM-only surfaces; disables video memory allocation. [AI].
ErrorHandler m_pFatalErrorHandler
Callback invoked for fatal device errors. [AI].
IDirectDrawSurface * m_pText1Surface
Debug overlay surface for "text1". [AI].
virtual void Destroy()
Shuts down DirectDraw and releases all resources, including device and surfaces.
IDirectDrawSurface * m_pFrontBuffer
Primary or front display surface. [AI].
SIZE m_text1SizeOnSurface
Pixel size of rendered text1 overlay surface. [AI].
void * m_pErrorHandlerArg
Custom argument pointer for error handler. [AI].
void * m_pFatalErrorHandlerArg
Custom argument pointer for fatal error handler. [AI].
BOOL CreateZBuffer(DWORD memorytype, DWORD depth)
Creates a z-buffer with the given memory type/capabilities and attaches it to the back buffer.
virtual void DestroyButNotDirectDraw()
Releases all DirectDraw-related resources except the DirectDraw device itself.
BOOL TextToTextSurface2(const char *lpString)
Draws the specified string to the debug "text2" surface.
IDirectDraw * m_pDirectDraw
Pointer to the DirectDraw COM device. [AI].
MxDirectDraw()
Constructs a MxDirectDraw instance and initializes its members.
HWND m_hWndMain
Main window handle on which DirectDraw is initialized. [AI].
void Error(const char *p_message, int p_error)
Invokes the error handler, optionally destroying the device, and outputs the given error message/code...
BOOL RestorePaletteEntries()
Restores the active DirectDraw palette entries from the internal palette array.
IDirectDrawPalette * m_pPalette
DirectDraw palette assigned to the primary/back surfaces. [AI].
BOOL DDSetMode(int width, int height, int bpp)
Changes DirectDraw to the specified display mode and creates relevant surfaces.
int Pause(BOOL)
Pauses or resumes DirectDraw rendering.
BOOL GetDDSurfaceDesc(LPDDSURFACEDESC lpDDSurfDesc, LPDIRECTDRAWSURFACE lpDDSurf)
Retrieves the surface description for the given DirectDraw surface.
int m_pauseCount
Count of nested pauses; ensures multiple Pause(TRUE)/Pause(FALSE) work correctly. [AI].
BOOL m_bFlipSurfaces
TRUE if using DirectDraw flipping (fullscreen buffer swap); windowed disables this....
BOOL m_bFullScreen
TRUE if device is in exclusive fullscreen mode. [AI].
virtual ~MxDirectDraw()
Virtual destructor.
BOOL RestoreOriginalPaletteEntries()
Restores the original Windows palette from backup.
void FUN_1009e020()
Internal: Clears the backbuffer(s), locking and filling with zero color, possibly flipping to front.
BOOL RecreateDirectDraw(GUID **a2)
Recreates the DirectDraw device, deleting and restoring the device object pointer.
BOOL RestoreSurfaces()
Attempts to restore all DirectDraw surfaces that may have been lost.
virtual BOOL Create(HWND hWnd, BOOL fullscreen_1, BOOL surface_fullscreen, BOOL onlySystemMemory, int width, int height, int bpp, const PALETTEENTRY *pPaletteEntries, int paletteEntryCount)
Creates and initializes the DirectDraw device and associated surfaces/windows/state.
BOOL m_bIsOnPrimaryDevice
TRUE if rendering on Windows' main display; disables windowed mode for other devices....
BOOL CreateTextSurfaces()
Creates the two offscreen text surfaces used for debug overlay.
#define DDERR_OVERLAYCOLORKEYONLYONEACTIVE
#define DDERR_NOT8BITCOLOR
#define DDERR_NOSTRETCHHW
#define DDERR_NOTAOVERLAYSURFACE
#define DDERR_INVALIDRECT
#define DDERR_NOT4BITCOLORINDEX
#define DDERR_HEIGHTALIGN
#define DDERR_NOOVERLAYDEST
struct _DDSURFACEDESC FAR * LPDDSURFACEDESC
#define DDERR_INVALIDPIXELFORMAT
#define DDERR_VERTICALBLANKINPROGRESS
#define DDERR_NOTFLIPPABLE
struct IDirectDrawSurface FAR * LPDIRECTDRAWSURFACE
#define DDERR_OVERLAYCANTCLIP
#define DDSCAPS_PRIMARYSURFACE
#define DDSD_ZBUFFERBITDEPTH
#define DDERR_UNSUPPORTEDMASK
#define DDERR_INVALIDCAPS
#define DDERR_INVALIDOBJECT
#define DDERR_INVALIDMODE
#define DDERR_CANNOTATTACHSURFACE
#define DDERR_UNSUPPORTEDFORMAT
#define DDERR_NOZOVERLAYHW
#define DDERR_SURFACELOST
#define DDERR_NOOVERLAYHW
#define DDERR_NOT4BITCOLOR
#define DDERR_SURFACEALREADYDEPENDENT
#define DDERR_SURFACEISOBSCURED
#define DDERR_INCOMPATIBLEPRIMARY
typedef DWORD(FAR PASCAL *LPCLIPPERCALLBACK)(LPDIRECTDRAWCLIPPER lpDDClipper
#define DDERR_EXCLUSIVEMODEALREADYSET
#define DDSCL_ALLOWREBOOT
#define DDERR_PALETTEBUSY
#define DDERR_NOCOLORCONVHW
struct _DDSURFACEDESC DDSURFACEDESC
#define DDERR_WASSTILLDRAWING
#define DDERR_HWNDSUBCLASSED
#define DDERR_NOEXCLUSIVEMODE
#define DDERR_OVERLAYNOTVISIBLE
#define DDERR_OUTOFMEMORY
#define DDSCAPS_OFFSCREENPLAIN
#define DDERR_NOZBUFFERHW
#define DDERR_CANTCREATEDC
#define DDERR_HWNDALREADYSET
#define DDERR_NOPALETTEATTACHED
#define DDERR_CURRENTLYNOTAVAIL
#define DDERR_OUTOFVIDEOMEMORY
#define DDERR_NOCOOPERATIVELEVELSET
#define DDERR_SURFACENOTATTACHED
#define DDERR_DIRECTDRAWALREADYCREATED
#define DDPF_PALETTEINDEXED8
#define DDSCAPS_BACKBUFFER
#define DDERR_NOCOLORKEYHW
#define DDERR_COLORKEYNOTSET
#define DDERR_UNSUPPORTED
#define DDERR_REGIONTOOSMALL
#define DDERR_TOOBIGWIDTH
#define DDERR_NOPALETTEHW
#define DDERR_INVALIDDIRECTDRAWGUID
#define DDERR_CANTDUPLICATE
#define DDERR_INVALIDCLIPLIST
#define DDERR_NOCLIPPERATTACHED
#define DDERR_IMPLICITLYCREATED
#define DDERR_NOTPALETTIZED
struct IDirectDraw FAR * LPDIRECTDRAW
#define DDERR_INVALIDPARAMS
#define DDERR_CLIPPERISUSINGHWND
#define DDERR_NOROTATIONHW
#define DDERR_NORASTEROPHW
#define DDERR_LOCKEDSURFACES
#define DDERR_SURFACEALREADYATTACHED
#define DDERR_NOEMULATION
#define DDERR_ALREADYINITIALIZED
#define DDERR_NOTEXTUREHW
#define DDERR_CANNOTDETACHSURFACE
#define DDERR_SURFACEBUSY
#define DDERR_NODIRECTDRAWHW
#define DDSCAPS_SYSTEMMEMORY
#define DDERR_INVALIDPOSITION
#define DDERR_TOOBIGHEIGHT
#define DDPCAPS_INITIALIZE
#define DDSD_BACKBUFFERCOUNT
#define DDERR_PRIMARYSURFACEALREADYEXISTS
#define DDERR_BLTFASTCANTCLIP
#define DECOMP_SIZE_ASSERT(T, S)
#define NULL
[AI] Null pointer value (C/C++ semantics).
void EnableResizing(HWND p_hwnd, BOOL p_flag)
void DeleteObject(MxDSAction &p_dsAction)
[AI] Deletes the specified action object, removing it from the global action list.
[AI] Represents a specific display mode supported by the device (width, height, bits per pixel).
int bitsPerPixel
[AI] Color depth (bits per pixel)
int width
[AI] Horizontal resolution in pixels
int height
[AI] Vertical resolution in pixels
Mode * m_modeArray
[AI] Array of supported display modes; dynamically allocated and owned.
int m_count
[AI] Number of display modes in m_modeArray.
GUID * m_guid
[AI] GUID of the video device (heap-allocated and owned by this struct).
DDPIXELFORMAT ddpfPixelFormat