Sign in to follow this  
lodoss118

2d game fullscreen and window

Recommended Posts

lodoss118    102
Hi i am having problems when running my game in fullscreen my scaling and bounding boxes are in different positions i.e. i have a bounding box class which draws a square depending on the width and height specified in window it draws the square fine but fullscreen it overlaps the line.

Share this post


Link to post
Share on other sites
Evil Steve    2017
What language? What OS? What graphics API? Can we get a screenshot (You can upload one to imageshack or a similar site, and then use HTML to link it here).

Assuming C++/Win32, when you create the window, do you call AdjustWindowRectEx to get the correct window size for the client area?

Share this post


Link to post
Share on other sites
CodaKiller    108
Quote:
Original post by lodoss118
Hi i am having problems when running my game in fullscreen my scaling and bounding boxes are in different positions i.e. i have a bounding box class which draws a square depending on the width and height specified in window it draws the square fine but fullscreen it overlaps the line.


Need more information, what APIs are you using?

Share this post


Link to post
Share on other sites
lodoss118    102
I am using a direct 8 wrapper for example the createwindow is set to 1024/768
i have also two variables that sotre lastModeX = 1024 and lastModey = 768

in my scaling i am multiplying the scale i.e spriteScaleX * (GetMAxX()/lastModeX)

c++, oh yeah i suck at maths wippeeeeeeeee

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by lodoss118
I am using a direct 8 wrapper for example the createwindow is set to 1024/768
i have also two variables that sotre lastModeX = 1024 and lastModey = 768

in my scaling i am multiplying the scale i.e spriteScaleX * (GetMAxX()/lastModeX)

c++, oh yeah i suck at maths wippeeeeeeeee


Quote:
Original post by Evil Steve
Assuming C++/Win32, when you create the window, do you call AdjustWindowRectEx to get the correct window size for the client area?


CreateWindow takes a window size, not a client area size. Direct3D renders to the backbuffer, which is then copied to the client area. If the client area size doesn't match the backbuffer size, you'll get stretching and odd artifacts.
The correct way to handle this is to call AdjustWindowRectEx to find out the window size for the client area size you want (1024x768 in your case).

Share this post


Link to post
Share on other sites
lodoss118    102
hmm looking at my code i have this


//Create a WIN32 window: add +6 and + 26 to account for window borders
if(!DXUCreateWindow(hinstance, 0, 0, 1024+6, 760+26))
{
DXUUnloadDirectXGraphics();
DXUDisplayLastError();
return -1;
}

//Initialise Windowed Graphics:
//Note: Default Full Screen Mode is ( 1152x864x16 )
if(!DXUInitGraphics())
{
DXUUnloadDirectXGraphics();
DXUDisplayLastError();
return -1;
}





i am not sure how DXUCreateWindow works but how would i use AdjustWindowRectEx in this scenario on when creating the window or do i have update all my sprite rects :( sorry for being a noob

Share this post


Link to post
Share on other sites
Evil Steve    2017
Where are these DXU* functions defined? I can't find anything in the SDK about them, which makes me think you're using some code from a book or some other source.
If you go into DXUCreateWindow(), does it call AdjustWindowRect? In any case, adding random values to the width and height of the window to account for the window borders is very wrong; they can be different across OSs, and even across PCs (If the user uses different fonts for the UI for instance).

Share this post


Link to post
Share on other sites
lodoss118    102
Its a wrapper class



DXUAPI BOOL DXUCreateWindow(HINSTANCE hInst,int x,int y,int screenW,int screenH)
{
HWND hwnd;
WNDCLASS wc;

if (!dxuSystemInfo.isInitialised)
DXUSetWindowInfo("DXU-API","DXU-API",LoadIcon((HINSTANCE)dllInstance,(LPCTSTR)IDI_DXUICON));
else if (!dxuSystemInfo.hIcon)
dxuSystemInfo.hIcon = LoadIcon((HINSTANCE)dllInstance,(LPCTSTR)IDI_DXUICON);

wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = DXUDefaultWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = dxuSystemInfo.hIcon;
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = dxuSystemInfo.menuName;
wc.lpszClassName = dxuSystemInfo.wndClassName;
RegisterClass( &wc );

hwnd = CreateWindowEx(0,
dxuSystemInfo.wndClassName,
dxuSystemInfo.wndName,
dxuSystemInfo.windowStyle,
x, y,
screenW,
screenH,
NULL,
NULL,
hInst,
NULL);

if ( !hwnd )
{
DXUSetLastError(DXUERR_NOHWND);
return FALSE;
}

dxuSystemInfo.hWnd = dxuSystemInfo.hWndFocus = hwnd;
dxuSystemInfo.hInst = hInst;
dxuSystemInfo.isActive = TRUE;
dxuSystemInfo.isCursor = TRUE;
dxuSystemInfo.isWindowed = TRUE;
dxuSystemInfo.windowW = screenW;
dxuSystemInfo.windowH = screenH;
// Save window properties
//dxuSystemInfo.windowStyle = GetWindowLong( hwnd, GWL_STYLE );
GetWindowRect( hwnd, &dxuSystemInfo.rcBounds );
GetClientRect( hwnd, &dxuSystemInfo.rcClient );

return TRUE;
}


Share this post


Link to post
Share on other sites
Evil Steve    2017
Well, you can see it doesn't call AdjustWindowRectEx, so you'll have to:

// Setup a RECT to describe the requested client area size
RECT rcClient;
rcClient.top = 0;
rcClient.left = 0;
rcClient.right = 1024; // Your client area width
rcClient.bottom = 768; // YOour client area height

// Adjust rcClient for the window borders, given the window style
AdjustWindowRectEx(&rcClient, CS_HREDRAW | CS_VREDRAW, FALSE, 0);

//Create a WIN32 window, using the size adjusted to include window borders
if(!DXUCreateWindow(hinstance, 0, 0, rcClient.right-rcClient.left, rcClient.bottom-rcClient.top))
/// Etc...

I'd also be a little wary of the code, given that the author doesn't seem to know what window styles he wants - The two given are useless for Direct3D, and he doesn't specify WS_OVERLAPPEDWINDOW or WS_POPUP, which is unusual (Although not incorrect).

Share this post


Link to post
Share on other sites
lodoss118    102
hmm seems like stuff is still offset

i think this method is the culprit i use this to make the screen fullscreen



DXUAPI BOOL DXUToggleFullscreen()
{
// Get access to current adapter, device, and mode
DXUADAPTERINFO* pAdapterInfo = &dxuSystemInfo.pAdapters[dxuSystemInfo.curAdapter];
DXUDEVICEINFO* pDeviceInfo = &pAdapterInfo->devices[pAdapterInfo->curDevice];
DXUMODEINFO* pModeInfo = &pDeviceInfo->modes[pDeviceInfo->curMode];

// Need device change if going windowed and the current device
// can only be fullscreen
if( !dxuSystemInfo.isWindowed && !pDeviceInfo->canDoWindowed )
{
BOOL retVal = DXUForceWindowed();
// reload the graphics if set by user:
//if(dxuSystemInfo.currentState)dxuSystemInfo.currentState->LoadState();
return retVal;
}

// Toggle the windowed state
dxuSystemInfo.isWindowed = !dxuSystemInfo.isWindowed;
pDeviceInfo->isWindowed = dxuSystemInfo.isWindowed;

// Prepare window for windowed/fullscreen change
DXUPrepareWindowForChange();

// Set up the presentation parameters
dxuSystemInfo.d3dpp.Windowed = pDeviceInfo->isWindowed;
dxuSystemInfo.d3dpp.MultiSampleType = pDeviceInfo->multiSampleType;
dxuSystemInfo.d3dpp.AutoDepthStencilFormat = pModeInfo->DepthStencilFormat;
dxuSystemInfo.d3dpp.hDeviceWindow = dxuSystemInfo.hWnd;

if( dxuSystemInfo.isWindowed )
{
dxuSystemInfo.d3dpp.BackBufferWidth = dxuSystemInfo.viewport.right - dxuSystemInfo.viewport.left;
dxuSystemInfo.d3dpp.BackBufferHeight = dxuSystemInfo.viewport.bottom - dxuSystemInfo.viewport.top;
dxuSystemInfo.d3dpp.BackBufferFormat = pAdapterInfo->d3ddmDesktop.Format;
}
else
{
dxuSystemInfo.d3dpp.BackBufferWidth = pModeInfo->Width;
dxuSystemInfo.d3dpp.BackBufferHeight = pModeInfo->Height;
dxuSystemInfo.d3dpp.BackBufferFormat = pModeInfo->Format;
}

// Resize the 3D device
if( FAILED( DXUResize3DEnvironment() ) )
{
if( dxuSystemInfo.isWindowed )
return DXUForceWindowed();
else
return FALSE;
}

// When moving from fullscreen to windowed mode, it is important to
// adjust the window size after resetting the device rather than
// beforehand to ensure that you get the window size you want. For
// example, when switching from 640x480 fullscreen to windowed with
// a 1000x600 window on a 1024x768 desktop, it is impossible to set
// the window size to 1000x600 until after the display mode has
// changed to 1024x768, because windows cannot be larger than the
// desktop.
if( dxuSystemInfo.isWindowed )
{
SetWindowPos( dxuSystemInfo.hWnd, HWND_NOTOPMOST,
dxuSystemInfo.rcBounds.left, dxuSystemInfo.rcBounds.top,
( dxuSystemInfo.rcBounds.right - dxuSystemInfo.rcBounds.left ),
( dxuSystemInfo.rcBounds.bottom - dxuSystemInfo.rcBounds.top ),
SWP_SHOWWINDOW );

AdjustWindowRectEx(&dxuSystemInfo.rcClient, 0, false, dxuSystemInfo.windowStyle);
}

// reload the graphics if set by user:
// if ( dxuSystemInfo.currentState != NULL )
//dxuSystemInfo.currentState->LoadState();


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