DirectX sprite movement seems 'glitchy'

Started by
34 comments, last by Interminable 11 years, 8 months ago
You haven't specified a window style in AdjustWindowRect() and you are also only assuming that the call succeeded as there is no error checking there.

And these don't match the calculated window size because it should be 'Windowed==TRUE'

if(d3dPresentationParameters.Windowed == FALSE)
{
d3dDisplayMode.Width = window_width;
d3dDisplayMode.Height = window_height;
}
d3dPresentationParameters.BackBufferWidth = d3dDisplayMode.Width;///*tempRect.right;*/window_width;
d3dPresentationParameters.BackBufferHeight = d3dDisplayMode.Height;///*tempRect.bottom;*/window_height;
Advertisement
That 'd3dPresentationParameters.Windowed == FALSE' was an unfortunate typo, sorry about that. Changing it to what it was supposed to be, TRUE, means that sprites now properly move across the screen in windowed mode without the borders.

As for AdjustClientRect()...if memory serves it used to work fine for what I was using it for without any styles being specified, however I'm not sure I was using it with DirectX. I have a feeling it may just be left over. It doesn't appear to actually do anything, I can comment it out entirely or specify the styles I'm using and it makes no difference to the issue with borders displayed.

The altered code for window creation:


if(!AdjustWindowRect(&windowRect, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN/*WS_EX_TOPMOST | WS_POPUP*/, NULL)) // So we can have the window at the correct size based on the desired client area size.
{
logWindow.AddLogEntry(3, TEXT("AdjustWindowRect() FAILED"), GetLastError());
MessageBox(mHwnd, TEXT("AdjustWindowRect() failed! This program will now close."), TEXT("CRITICAL FAILURE"), MB_OK | MB_ICONERROR | MB_TOPMOST);
GlobalFunctions::CheckCriticalExit();
}

if(!RegisterClassEx(&wc)) // Has a pointer to wc, above.
{
throw std::exception();
}

if((mHwnd = CreateWindowEx
(
0,
szAppName,
windowTitle,
/*WS_EX_TOPMOST | WS_POPUP,*/WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
windowRect.left,windowRect.top,
windowRect.right,windowRect.bottom,
GetDesktopWindow(),
NULL,
wc.hInstance,
NULL))==NULL)
{
throw std::exception();
}
So, things are now displaying correctly in a borderless window?

So, things are now displaying correctly in a borderless window?


They appear to be, yes.
I worked out I was not making proper use of the values AdjustWindowRect() was setting. So now my sprites can move horizontally across the screen in bordered mode and look fine, but there's a problem: Everything looks squashed and sprites moving vertically still have the issue, because it's adjusting the top by -30 pixels and the left by -8 (because of the title bar). Ideally I'd like to have the window sized so that stuff within it is not squashed, unfortunately if I do it:


windowRect.right - windowRect.left,
windowRect.bottom - windowRect.left,


It looks fine and sprites move perfectly when moving horizontally, but the issue still exists when they move up or down.

I think this may be about solved now though, I just want to try and get the window sized correctly so sprites are not stretched and at the same time have their movement appear glitch free.
So I didn't touch my code for a couple of days, but I'm SURE it was working. However I've come back to it to try and fix the sizing issue once and for all but when I ran it (without changing anything today), it looks like this:

problem001.png

To clarify, the purple sprite should have the red and white dotted line on the top only, not the bottom, and part of it seems to have been spliced part way across the screen. Does anyone have any ideas what I may have changed to cause this? I've not touched the vertices aspects of the code, etc for a while as I've been working on the client width thing. So far I can't think what I've done wrong.

EDIT: I've found what was causing it, it's because I'd force-enabled anti-aliasing with the Catalyst Control Center (for something else). It seems my application didn't like that. :S

Setting it back to Application Preference fixed it.


EDIT2: I'm still struggling with trying to get the damned client size correct though.

I first have a RECT with the following:


windowRect.left = GetSystemMetrics(SM_CXSCREEN)/2-window_width/2
windowRect.top = GetSystemMetrics(SM_CYSCREEN)/2-window_height/2;
windowRect.right = window_width;
windowRect.bottom = window_height


Which sets the values:

left = 328
top = 141
right = 1024
bottom = 768

Following AdjustWindowRect() being called with the following arguments:


AdjustWindowRect(&windowRect, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN/*WS_EX_TOPMOST | WS_POPUP*/, NULL)


Which adjusts the original values to the following:

left = 320
top = 111
right = 1032
bottom = 776

The window is then created using those values like this:


CreateWindowEx
(
0,
szAppName,
windowTitle,
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
windowRect.left,
windowRect.top,
windowRect.right,
windowRect.bottom,
GetDesktopWindow(),
NULL,
wc.hInstance,
NULL))==NULL)


Then, in my rendering code I have:


d3dDisplayMode.Width = window_width;
d3dDisplayMode.Height = window_height;

d3dPresentationParameters.BackBufferWidth = d3dDisplayMode.Width;
d3dPresentationParameters.BackBufferHeight = d3dDisplayMode.Height;


(window_width is still 1024 and window_height is still 768).

The issue still exists with what I'm doing here, but I'm not sure what I'm doing wrong. The client area SHOULD be 1024x768, which is what I should be setting d3dDisplayMode.Width and d3dDisplayMode.Height with, and d3dPresentationParameters.BackBufferWidth and d3dPresentationParameters.BackBufferHeight with, right?

I cannot see where I'm going wrong.

This topic is closed to new replies.

Advertisement