Sign in to follow this  
Perfunction

Weird behavior while windowed

Recommended Posts

I'm working on a DirectDraw side-scrolling game in my spare time and I'm having a weird issue running in a window. I have my engine setup to read the fullscreen option from a config file and then several parts of the game have a conditional statement to see what the user chose. Fullscreen works great but windowed mode is working rather oddly. Whenever the user selects windowed mode, the engine does something like this: Creates an 800x600 overlapped window Sets cooperation to normal Creates a primary surface Creates an 800x600 clipper Creates an 800x600 off screen surface After rendering to the off screen surface it blits to the primary It renders fine but the problem is that it doesn't scale down to fit in that window. It acts like the window is just a "view hole" to a fullscreen image. So to see the bottom left of the screen you have to drag the window to the bottom left of your desktop.

Share this post


Link to post
Share on other sites
Quote:
27 views and no comments?

bump
Probably no need to 'bump' it yet. Lots of people look at lots of threads without replying - but waiting a couple of days before a reply wouldn't hurt!

Anyway... I don't have an automagical solution for you, but I have seen this sort of thing happen before; albeit for DShow rather than DDraw. The solution in my case was that it didn't "attach" itself to the hWnd of my window and catch appropriate windowing events (or something along those lines).

Make sure that it's connecting properly to the window and not using some default value (i.e. the desktop sized area).

Failing that, go dig up the SDK. Compare your code to their code. I'll be betting they differ somewhere, and I'll be betting thats your solution [wink].

hth
Jack

Share this post


Link to post
Share on other sites
thanks for the post. didn't mean to seem impatient im just used to forums where the second page gets ignored. here's what i'm doing for anyone who cares:

bool Render_Init(HWND hWnd) {
DDSURFACEDESC2 surfDesc;
DWORD result;
DDSCAPS2 ddscaps;

// Create DDraw object
result = DirectDrawCreateEx(NULL, (VOID**)&ddraw, IID_IDirectDraw7, NULL);

if (result != DD_OK) {
Error("DirectDraw: Unable to create DDraw object. Error #", result);
return false;
}

// Setup fullscreen or windowed mode
if (config->Fullscreen) {
result = ddraw->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT);

if (result != DD_OK) {
Error("DirectDraw: Unable to set cooperation level. Error #", result);
return false;
}

// Setup display mode
result = ddraw->SetDisplayMode(config->ScreenWidth, config->ScreenHeight, config->ScreenBpp, 0, 0);

if (result != DD_OK) {
if (result = DDERR_INVALIDMODE)
Error("DirectDraw: Display mode not supported by video card. Error #", result);
else
Error("DirectDraw: Unable to set display mode. Error #", result);

return false;
}

// Setup surface discription for one back buffer
ZeroMemory(&surfDesc, sizeof(surfDesc));
surfDesc.dwSize = sizeof(surfDesc);
surfDesc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
surfDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
surfDesc.dwBackBufferCount = 1;

// Create primary surface
result = ddraw->CreateSurface(&surfDesc, &primarySurface, NULL);

if (result == DDERR_INVALIDCAPS ) {
Error("DirectDraw: Unable to create primary surface. DDERR_INVALIDCAPS");
return false;
}

if (result != DD_OK) {
Error("DirectDraw: Unable to create primary surface. Error #", result);
return false;
}

ZeroMemory(&ddscaps, sizeof(ddscaps));
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;

result = primarySurface->GetAttachedSurface(&ddscaps, &backBuffer);
if (result != DD_OK) {
Error("DirectDraw: Unable to create back buffer");
return false;
}
} else {
result = ddraw->SetCooperativeLevel(hWnd, DDSCL_NORMAL);

if (result != DD_OK) {
Error("DirectDraw: Unable to set cooperation level. Error #", result);
return false;
}

// Setup surface discription for one back buffer
ZeroMemory(&surfDesc, sizeof(surfDesc));
surfDesc.dwSize = sizeof(surfDesc);
surfDesc.dwFlags = DDSD_CAPS;
surfDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

// Create primary surface
result = ddraw->CreateSurface(&surfDesc, &primarySurface, NULL);

if (result == DDERR_INVALIDCAPS ) {
Error("DirectDraw: Unable to create primary surface. DDERR_INVALIDCAPS");
return false;
}

if (result != DD_OK) {
Error("DirectDraw: Unable to create primary surface. Error #", result);
return false;
}

ZeroMemory(&surfDesc, sizeof(surfDesc) );
surfDesc.dwSize = sizeof(surfDesc);
surfDesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
surfDesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
surfDesc.dwWidth = config->ScreenWidth;
surfDesc.dwHeight = config->ScreenHeight;

// create the backbuffer separately
result = ddraw->CreateSurface(&surfDesc, &backBuffer, NULL );
if (result != DD_OK) {
Error("DirectDraw: Unable to create back buffer.");
return false;
}
}

result = ddraw->CreateClipper(0, &clipper, NULL);
if (result != DD_OK) {
Error("DirectDraw: Unable to create clipper.");
return false;
}

result = clipper->SetHWnd(0, hWnd);
if (result != DD_OK) {
Error("DirectDraw: Unable to set parent window for clipper.");
return false;
}

result = primarySurface->SetClipper(clipper);
if (result != DD_OK) {
Error("DirectDraw: Unable to set primary surface clipper.");
return false;
}

return true;
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this