Why doesnt this work?

Started by
16 comments, last by GameDev.net 24 years, 4 months ago
I tried that exact code and it died on that first CreateSuface(FrontBuffer
it jus kills it, i had to EndTask to get out of it, thanks for helpin the new guy.
Advertisement
Doesnt any one have any ideas????????
PLESAE help,
thanx.
Could someone Please Help ME THANX
Do you get an error returned from CreateSurface, and if so which error?

DirectDraw's error codes can be helpful.

--If Train A leave San Francisco at 8:30am EST travelling 25mph and Train B leaves Chicago at 1:30pm MST travelling at 40mph, and they're 3000 miles apart when they start, what is the capital of Bulgaria?
The only way I no it was CreateSurface that killed it was because 1 time it didnt Totaly Freeze my comp. I some how got it out and it did return a long error, though I didnt write it down. Every time I run the program it freezes and I can only turn off my comp, tried everything.
If you want to debug your program you shouldn't use the FULLSCREEN flag. Just test the program in windowed mode and switch then to fullscreen. But be aware of the fact that you cant flip pages in windowed modes.
The last truth is that there is no magic(Feist)
heres the code, im a begginner so dont laugh if its obvios

LPDIRECT3D2 lpd3d;
LPDIRECT3DDEVICE2 lpd3ddevice;
LPDIRECTDRAW lpdd = NULL;
LPDIRECTDRAWSURFACE lpddsprimary = NULL;
LPDIRECTDRAWSURFACE lpddsbackbuffer = NULL;
LPDIRECTDRAWPALETTE lpddpal = NULL;
PALETTEENTRY color_palette[256];
DDSURFACEDESC ddsd;
DDSCAPS ddscaps;
HRESULT ddrval;
HWND main_window_handle=NULL;

int hardware;

int DD_Init(HWND hwnd)
{
// this function is responsible for initializing direct draw, it creates a
// primary surface

int index; // looping index
// now that the windows portion is complete, start up direct draw
if (DirectDrawCreate(NULL,&lpdd,NULL)!=DD_OK)
{
// shutdown any other dd objects and kill window
DD_Shutdown();
return(0);
} // end if

// now set the coop level to exclusive and set for full screen and mode x
if (lpdd->SetCooperativeLevel(hwnd, DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE |
DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX)!=DD_OK)
{
// shutdown any other dd objects and kill window
DD_Shutdown();
return(0);
} // end if

// now set the display mode
if (lpdd->SetDisplayMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP)!=DD_OK)
{
// shutdown any other dd objects and kill window
DD_Shutdown();
return(0);
} // end if

// Create the primary surface
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

if (lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL)!=DD_OK)
{
// shutdown any other dd objects and kill window
DD_Shutdown();
return(0);
} // end if

ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
ddsd.dwWidth = SCREEN_WIDTH;
ddsd.dwHeight = SCREEN_HEIGHT;
hardware=1; //Forse Hardware Acceleration
if (hardware)
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY;

else
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_SYSTEMMEMORY;

if (lpdd->CreateSurface(&ddsd, &lpddsbackbuffer,NULL) != DD_OK) return(0);
if (lpddsprimary->AddAttachedSurface(lpddsbackbuffer) != DD_OK) return(0);


//Query the hardware

if (lpd3d->QueryInterface(IID_IDirect3D2, (LPVOID *)&lpd3d) != S_OK)
return (0);


// Create the D3D device

if (lpd3d->CreateDevice(IID_IDirect3DHALDevice, lpddsbackbuffer, &lpd3ddevice) != D3D_OK)
return FALSE;

// return success if we got this far
return(1);

} // end DD_Init

---------------------------------
Thank yo so much
also, sorry for the length
I dont really know whats wrong but it cant get past the Query Interface, also I am forcing hardware acceleration (I THINK) jus to make it easier,
Thanks again,

when I turn off fullscreen mode and dont change the video mode the program seems to work as it does not return an error. Though onces I use full screen and hardware acceleration I found out that when I use CreateSurface(Front_Buffer), It returns DDER_INVALIDCAPS. I dont no if Im using the right caps. THANX AGAIN!

This topic is closed to new replies.

Advertisement