Archived

This topic is now archived and is closed to further replies.

damario

SetCooperativeLevel trouble for 2d game

Recommended Posts

I''m a semi-beginner making a 2d game. I have worked with DirectDraw before but I have never had this much trouble with directdraw. I use one of the basic methods to initiate directdraw but i still get DDERR_EXCLUSIVEMODEALREADYSET as an error from my Log system using a switch statement. Here''s the code: // all variables with "g_" infront of them are global variables BOOL InitDirectDraw(void) { HRESULT hRet; LPDIRECTDRAW pDD; DDSURFACEDESC2 ddsd; DDSCAPS2 ddscaps; CoInitialize(NULL); // First of all, create the DirectX object hRet = DirectDrawCreate( NULL, &pDD, NULL ); if(hRet != DD_OK) { // if failed, quit the app LogText("DirectDrawCreate() failed. couldn''t create directx object"); return FALSE; } // Fetch DirectDraw7 interface hRet = pDD->QueryInterface(IID_IDirectDraw7, (LPVOID*)&g_pDD); if(hRet != DD_OK) { // if failed, quit the app LogText("Couldn''t query a DD7 interface"); return FALSE; } // Since we don´t need this DirectDraw interface anymore, release it pDD->Release(); // Set cooperative level to fullscreenn // we have to put in a global hwnd in here hRet = g_pDD->SetCooperativeLevel(g_hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); if(hRet != DD_OK) { // if failed, quit the app LogText("SetCooperativeLevel() failed."); switch(hRet){ case DDERR_EXCLUSIVEMODEALREADYSET: LogText("Exclusive mode has already been set"); break; case DDERR_HWNDALREADYSET: LogText("an hwnd has already been set"); break; case DDERR_HWNDSUBCLASSED: LogText("DDrw can''t restore the state b/c DDrw"); LogText("cooperative level window handle has been subclassed"); break; case DDERR_INVALIDOBJECT: LogText("We gave it an invalid object: g_pDD"); break; case DDERR_INVALIDPARAMS: LogText("invalid params: exlusive and fullscreen or even hwnd"); break; case DDERR_OUTOFMEMORY: LogText("out of memory"); break; default: LogText("None of the MSDN errors are occuring here"); } return FALSE; } // Set Display mode hRet = g_pDD->SetDisplayMode(g_ScreenWidth, g_ScreenHeight, g_ColorDepth, 0, 0 ); if(hRet != DD_OK) { // if failed, quit the app LogText("SetDisplayMode() failed."); return FALSE; } // Create Main Surfaces ZeroMemory( &ddsd, sizeof( ddsd ) ); ddsd.dwSize = sizeof( ddsd ); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; // CreatSurface() is a Directx function hRet = g_pDD->CreateSurface(&ddsd, &g_pFrontBuffer, NULL ); if(hRet != DD_OK) { // if failed, quit the app LogText("Couldn''t Create main front buffer surface"); return FALSE; } // get a pointer to the back buffer ZeroMemory(&ddscaps, sizeof(ddscaps)); ddscaps.dwCaps = DDSCAPS_BACKBUFFER; hRet = g_pFrontBuffer->GetAttachedSurface( &ddscaps, &g_pBackBuffer); if(hRet != DD_OK) { // if failed, quit the app LogText("Couldn''t create back buffer surface"); return FALSE; } LogText("InitDDraw worked fine"); // All OK ! return TRUE; } If anybody can help me out, I will really appreciate it. Thanks

Share this post


Link to post
Share on other sites
Try changing the order of some of your ''cases'' in your switch statement. It could be an error with how you''re handling hRet so that it chooses the first case. Also, make sure you have all the required ''break'' statements so that it''s not going through a couple of cases.


[JESUS SAVES|Planet Half-Life]

Share this post


Link to post
Share on other sites