Original Post
I''ve been using directdraw for a couple of weeks now but i have this problem that ALWAYS seems to come back no matter what.
Whats happens is my app goes into fullscreen mode (like its supposed to) but then it exits immediatly. I come accross this problem very often and its starting to annoy me how I cannot find the solution.
I''ve been writing a simple ddraw app at the moment and it has come up again! I''ve checked over for long enought now, so please help me find what the heck is closing my program.
I even took out all the error code exits and it still does it!
Ok here is my Game_Init and Game_Main.
(all im trying to do is create a black screen with moving pixels)
Remember my problem is that the program exits straight away,
but i haven''t a single error check in my whole code!
Thanks for your precious time
//Main game initialisation
void Game_Init()
{
//Main ddraw object
DirectDrawCreateEx(NULL,(void**)&lpdd,IID_IDirectDraw7,NULL);
//Cooperation with windows
lpdd->SetCooperativeLevel(gHwnd,DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT);
//Display mode
lpdd->SetDisplayMode(640,480,8,0,0);
//Set surface description for primary surface
//First clear memory then set size
memset(&ddsd,0,sizeof(DDSURFACEDESC2));
ddsd.dwSize = sizeof(DDSURFACEDESC2);
//Set to primary surface with one back buffer
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.dwBackBufferCount = 1;
//Set to complex, flippable for page-flipping
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
//Create both surfaces
lpdd->CreateSurface(&ddsd,&lpddsPrimary,NULL);
//Attach backbuffer to primary surface
ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
lpddsPrimary->GetAttachedSurface(&ddsd.ddsCaps,&lpddsBack);
//Init star positions at random
for (int i=0; i<NUM_STARS; i++)
{
stars[i].x = rand()%SCREEN_WIDTH;
stars[i].y = rand()%SCREEN_HEIGHT;
}
} //End Game_Init
//Main game loop
void Game_Main()
{
DDBLTFX ddbltfx;
DD_INIT_STRUCT(ddbltfx);
ddbltfx.dwFillColor = 0; //Set color to black
//Check for escape key
if (KEYDOWN(VK_ESCAPE))
SendMessage(gHwnd,WM_DESTROY,0,0);
//Clear back buffer
lpddsBack->Blt(NULL,NULL,NULL,DDBLT_WAIT | DDBLT_COLORFILL,&ddbltfx);
//Move stars
for (int i=0; i<NUM_STARS; i++)
stars[i].x += 2;
//Lock backbuffer
lpddsBack->Lock(NULL,NULL,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL);
//Create alias to back buffer
UCHAR *back_buffer = (UCHAR*)ddsd.lpSurface;
//Plot stars
for (int i=0; i<NUM_STARS; i++)
{
int color = 255;
back_buffer[stars[i].x + stars[i].y*ddsd.lPitch] = color;
}
//Unlock backbuffer
lpddsBack->Unlock(NULL);
//Flip surfaces -remember that this in only
//Possible when all surfaces are UNLOCKED
while (FAILED(lpddsPrimary->Flip(NULL,DDFLIP_WAIT)));
Sleep(100);
} //End Game_Main