Skip to content

Commit

Permalink
Tweak frog1 color key, add a button to display surface description
Browse files Browse the repository at this point in the history
  • Loading branch information
periwinkle9 committed Aug 7, 2023
1 parent a336462 commit 5ae0336
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 5 deletions.
17 changes: 17 additions & 0 deletions DDrawTransparencyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
if (!initDDraw(hWindow) || !loadSprites())
return FALSE;

MessageBox(hWindow, TEXT("Hi! If someone asked you to run this program, please screenshot the window "
"along with the contents of Help > Technical Info and send it to them.\nThanks in advance :D"),
TEXT("Hey!"), MB_OK);

renderLoop(hInstance, hWindow);

releaseDDraw();
Expand Down Expand Up @@ -164,6 +168,19 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case ID_HELP_INFO:
{
DDSURFACEDESC frontBufferDesc, frogSurfaceDesc;
ZeroMemory(&frontBufferDesc, sizeof frontBufferDesc);
ZeroMemory(&frogSurfaceDesc, sizeof frogSurfaceDesc);
frontBufferDesc.dwSize = frogSurfaceDesc.dwSize = sizeof(DDSURFACEDESC);
frontbuffer->GetSurfaceDesc(&frontBufferDesc);
frogSurface2->GetSurfaceDesc(&frogSurfaceDesc);
std::string messageText = "Frontbuffer description:\n" + getSurfaceDescString(frontBufferDesc)
+ "\n\nFrog surface description:\n" + getSurfaceDescString(frogSurfaceDesc);
MessageBoxA(hWnd, messageText.c_str(), "Surface descriptions", MB_OK | MB_ICONINFORMATION);
break;
}
case IDM_EXIT:
DestroyWindow(hWnd);
break;
Expand Down
Binary file modified DDrawTransparencyTest.rc
Binary file not shown.
55 changes: 55 additions & 0 deletions draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// For timeGetTime()
#include <MMSystem.h>

#include <stdio.h>

LPDIRECTDRAW lpDD;
LPDIRECTDRAWSURFACE frontbuffer;
LPDIRECTDRAWSURFACE backbuffer;
Expand Down Expand Up @@ -128,6 +130,59 @@ void restoreSurfaces()
frogSurface2->Restore();
}

std::string getSurfaceDescString(const DDSURFACEDESC& surfaceDesc)
{
std::string messageString;
auto write = [&messageString](const char* formatString, auto... args)
{
// I don't have C++20 std::format
char str[200] = {};
sprintf_s(str, sizeof str, formatString, args...);
messageString += str;
};

DWORD surfaceFlags = surfaceDesc.dwFlags;
write("flags: %X\n", surfaceFlags);

if (surfaceFlags & DDSD_WIDTH)
write("width: %u\n", surfaceDesc.dwWidth);
if (surfaceFlags & DDSD_HEIGHT)
write("height: %u\n", surfaceDesc.dwHeight);
if (surfaceFlags & DDSD_ALPHABITDEPTH)
write("alpha bit depth: %u\n", surfaceDesc.dwAlphaBitDepth);
if (surfaceFlags & DDSD_BACKBUFFERCOUNT)
write("backbuffer count: %u\n", surfaceDesc.dwBackBufferCount);
if (surfaceFlags & DDSD_CAPS)
write("capabilities: %X\n", surfaceDesc.ddsCaps.dwCaps);
if (surfaceFlags & DDSD_CKDESTBLT)
write("dest blt color key: %X %X\n", surfaceDesc.ddckCKDestBlt.dwColorSpaceLowValue, surfaceDesc.ddckCKDestBlt.dwColorSpaceHighValue);
if (surfaceFlags & DDSD_CKDESTOVERLAY)
write("dest overlay color key: %X %X\n", surfaceDesc.ddckCKDestOverlay.dwColorSpaceLowValue, surfaceDesc.ddckCKDestOverlay.dwColorSpaceHighValue);
if (surfaceFlags & DDSD_CKSRCBLT)
write("src blt color key: %X %X\n", surfaceDesc.ddckCKSrcBlt.dwColorSpaceLowValue, surfaceDesc.ddckCKSrcBlt.dwColorSpaceHighValue);
if (surfaceFlags & DDSD_CKSRCOVERLAY)
write("src overlay color key: %X %X\n", surfaceDesc.ddckCKSrcOverlay.dwColorSpaceLowValue, surfaceDesc.ddckCKSrcOverlay.dwColorSpaceHighValue);
if (surfaceFlags & DDSD_LINEARSIZE)
write("linear size: %u\n", surfaceDesc.dwLinearSize);
if (surfaceFlags & DDSD_MIPMAPCOUNT)
write("mipmap count: %u\n", surfaceDesc.dwMipMapCount);
if (surfaceFlags & DDSD_PITCH)
write("pitch: %ld\n", surfaceDesc.lPitch);
if (surfaceFlags & DDSD_REFRESHRATE)
write("refresh rate: %u\n", surfaceDesc.dwRefreshRate);
if (surfaceFlags & DDSD_ZBUFFERBITDEPTH)
write("z-buffer depth: %u\n", surfaceDesc.dwZBufferBitDepth);
if (surfaceFlags & DDSD_PIXELFORMAT)
{
const DDPIXELFORMAT& pixelFormat = surfaceDesc.ddpfPixelFormat;
write("pixel format:\n flags: %X\n RGB bit count: %u\n Bit masks: %08X %08X %08X %08X",
pixelFormat.dwFlags, pixelFormat.dwRGBBitCount, pixelFormat.dwRBitMask,
pixelFormat.dwGBitMask, pixelFormat.dwBBitMask, pixelFormat.dwRGBAlphaBitMask);
}

return messageString;
}

BOOL drawFrame(HINSTANCE hInstance, HWND hWnd)
{
// I'm just going to base this off of Flip_SystemTask()...
Expand Down
2 changes: 2 additions & 0 deletions draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "framework.h"
#include <ddraw.h>
#include <string>

constexpr int WINDOW_WIDTH = 320;
constexpr int WINDOW_HEIGHT = 240;
Expand All @@ -19,3 +20,4 @@ extern RECT windowRect;
BOOL initDDraw(HWND hWnd);
void releaseDDraw();
BOOL renderLoop(HINSTANCE hInstance, HWND hWnd);
std::string getSurfaceDescString(const DDSURFACEDESC&);
17 changes: 14 additions & 3 deletions load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ BOOL loadRoachClipRight()
DDSURFACEDESC ddsd;
memset(&ddsd, 0, sizeof ddsd);
ddsd.dwSize = sizeof ddsd;
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_CKSRCBLT; // Let's try setting DDSD_CKSRCBLT too
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth = bitmap.bmWidth * 3;
ddsd.dwHeight = bitmap.bmHeight * 3;
Expand Down Expand Up @@ -241,9 +241,20 @@ BOOL loadFrog1()
SelectObject(hdc, hgdiobj);
DeleteDC(hdc);

// Get color for color key
memset(&ddsd, 0, sizeof ddsd);
ddsd.dwSize = sizeof ddsd;
if ((result = frogSurface1->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL)) != DD_OK)
{
reportFailure("frogSurface1->Lock", __LINE__, 0);
return FALSE;
}
DWORD bgColor = *reinterpret_cast<DWORD*>(ddsd.lpSurface);
frogSurface1->Unlock(NULL);

DDCOLORKEY colorKey;
colorKey.dwColorSpaceLowValue = 0x01010101u; // Hopefully this should work regardless of color format
colorKey.dwColorSpaceHighValue = 0x01010101u;
colorKey.dwColorSpaceLowValue = bgColor;
colorKey.dwColorSpaceHighValue = bgColor;
if ((result = frogSurface1->SetColorKey(DDCKEY_SRCBLT, &colorKey)) != DD_OK)
{
reportFailure("frogSurface1->SetColorKey", __LINE__, result);
Expand Down
2 changes: 1 addition & 1 deletion load.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#include "framework.h"

BOOL loadSprites();
BOOL loadSprites();
3 changes: 2 additions & 1 deletion resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define IDB_ROACHCLIPRIGHT 133
#define IDR_ROACHCLIPLEFT 139
#define IDB_BIGCROAKER2 140
#define ID_HELP_INFO 32772
#define IDC_STATIC -1

// Next default values for new objects
Expand All @@ -24,7 +25,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 141
#define _APS_NEXT_COMMAND_VALUE 32772
#define _APS_NEXT_COMMAND_VALUE 32773
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 110
#endif
Expand Down

0 comments on commit 5ae0336

Please sign in to comment.