INT GAME_INIT (Void * PARMS = NULL, INT NUM_PARMS = 0) {// Create IID_IDIRECTDRAW7 interface IF (Failed (DirectDrawCreateex (Null, (Void **) & LPDD, IID_IDirectDraw7, null)) Return (0);
// Set collaborative level if (failed (LPDD-> SetCoopeRarative (Main_Window_Handle, DDSCL_ALLSCREEN | DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)) Return (0);
/ / Set the display module IF (Failed (LPDD-> setDisplaymode (Screen_Width, Screen_HEIGHT, Screen_bpp, 0, 0)) Return (0);
// Clear DDSD AND SET SIZE DDRAW_INIT_STRUCT (DDSD);
// enable valid fields ddsd.dwflags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
// Set the backup buffer number DDSD.DWBACKBUFFERCOUNT = 1;
// Request a complex, flippable ddsd.ddscaps.dwcaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
// Create The Primary Surface IF (Failed (LPDD, & LPDDSPRIMARY, NULL)) RETURN (0);
// Now query for attach Surface from the primary surface
// this line is needed by the call ddsd.ddscaps.dwcaps = DDSCAPS_BACKBUFFER
// Get backup buffer IF (Failed (LPDDSPRIMARY-> GetAttachedSurface (& DDSD.DDSCAPS, & LPDDSBACK)) RETURN (0);
// BUILD UP THE PALETTE DATA ARRAY FOR (INT Color = 1; Color ) {// Fill with Random RGB VALUES PALETTE [Color] .pered = rand ()% 256; Palette [color] .pegreen = rand ()% 256; Palette [color] .peblue = rand ()% 256;
// set flags field to pc_nocollapse palette [color] .peflags = pc_nocollapse;} // end for color
// Now Fill in Entry 0 and 255 with black and white paste [0] .pled = 0; Palette [0] .pegreen = 0; Palette [0] .peblue = 0; Palette [0] .peflags = pc_nocollapse;
Palette [255] .pette [255] .pegreen = 255; Palette [255] .peblue = 255; Palette [255] .peflags = pc_nocollapse; // Create The Palette Object IF (failed (LPDD-> CreatePalette (DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE, PALETTE, & LPDDPAL, NULL)) RETURN (0);
// Finally Attach The Palette to The Primary Surface IF (Failed (LPDDSPRIMARY-> SetPalette (LPDDPAL))) Return (0);
// Return Success or failure or Your OWN Return Code Here Return (1);
} // end game_initint game_main (Void * PARMS = NULL, INT NUM_PARMS = 0) {if (Window_Closed) Return (0);
IF (keydown) {postmessage (main_window_handle, wm_close, 0, 0); window_closed = 1;} // endiff
// Lock The Back Buffer DDRAW_INIT_STRUCT (DDSD); LPDDSBACK-> LOCK (NULL, & DDSD, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
Uchar * back_buffer = (uchar *) DDSD.LPSURFACE;
IF (DDSD.LPITCH == Screen_Width) Memset (back_buffer, 0, screen_width * screen_height); Else {// Non-linear Memory // Make Copy of Video Pointer Uchar * DEST_PTR = BACK_BUFFER Download Adobe Reader
// Clear Out Memory One line at a time for (int y = 0; y } // END ELSE // You Would Perform Game Logic ... // Draw the next frame Into the back buffer, Notice That We // Must Use the lpitch since it's a surface and may not be linear // plot 5000 Random Pixels for (int index = 0; index <5000; index ) {int x = rand ()% screen_width; int y = rand ()% screen_Height; Uchar col = rand ()% 256; back_buffer [x Y * DDSD.LPITCH] = col;} // end for index // unlock the back buffer if (LPDDSBACK-> UNLOCK (NULL)) RETURN (0); // Perform the flip while (failed (LPDDSPRIMARY-> Flip (null, ddflip_wait))); // Wait A Sec Sleep (500); // Return Success or failure or Your OWN Return Code Here Return (1); } // End Game_main