Does my code look alright?
LPDIRECTDRAW7 lpdd = NULL; //DirectDraw 7 Object
LPDIRECTDRAWPALETTE lpddpal = NULL; //DirectDraw Palette
LPDIRECTDRAWSURFACE7 lpddsprimary = NULL; //DirectDraw 7 Surface
PALETTEENTRY Palette[256] ; //Palette::8-Bit
DDSURFACEDESC2 ddsd ; //Primary Surface Structure
void GameInit(void) {
//Create DDraw7 Interface
if(FAILED(DirectDrawCreateEx(NULL, (void**)&lpdd, IID_IDirectDraw7, NULL))) {
throw Exception(MainWindow, "DirectDrawCreateEx() Failed");
return; }
//Set the cooperative level
if(FAILED(lpdd->SetCooperativeLevel(MainWindow, DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT))) {
throw Exception(MainWindow, "SetCooperativeLevel() Failed");
return; }
//Set display mode
if(FAILED(lpdd->SetDisplayMode(ScreenX, ScreenY, 8, 0, 0))) {
throw Exception(MainWindow, "SetDisplayMode() Failed");
return; }
//--Set-Palette----------
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
srand((unsigned)time(NULL));
for(i = 1; i < 255; i++) {
Palette[i].peRed = rand()%256;
Palette[i].peGreen = rand()%256;
Palette[i].peBlue = rand()%256;
Palette[i].peFlags = PC_NOCOLLAPSE; }
Palette[0].peRed = 0;
Palette[0].peGreen = 0;
Palette[0].peBlue = 0;
Palette[0].peFlags = PC_NOCOLLAPSE;
Palette[255].peRed = 255;
Palette[255].peGreen = 255;
Palette[255].peBlue = 255;
Palette[255].peFlags = PC_NOCOLLAPSE;
//--------------
//Create Palette Object
if(FAILED(lpdd->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE, Palette, &lpddpal, NULL))) {
throw Exception(MainWindow, "CreatePalette() Failed");
return; }
//--Set-Surface----------
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
//--------------
//Create Surface Object
if(FAILED(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL))) {
throw Exception(MainWindow, "CreateSurface() Failed");
return; }
//Attach palette to surface
if(FAILED(lpddsprimary->SetPalette(lpddpal))) {
throw Exception(MainWindow, "SetPalette() Failed");
return; } }
this too, a couple of macros and functions...
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
inline void DrawPixel(const int& X, const int& Y, const UCHAR& Color,
UCHAR* Surface, const int& Pitch)
{ Surface[X + Y * Pitch] = Color; }
DrawPixel(rand()%6 + (X - 3), ScreenY - i, RandColor, (UCHAR*)ddsd.lpSurface, (int)ddsd.lPitch);
void GameTerminate(void) {
if(lpddpal) {
lpddpal->Release();
lpddpal = NULL; }
if(lpddsprimary) {
lpddsprimary->Release();
lpddsprimary = NULL; }
if(lpdd) {
lpdd->Release();
lpdd = NULL; } }

