Jump to content

  • Log In with Google      Sign In   
  • Create Account


Interminable

Member Since 03 Dec 2011
Offline Last Active Private
-----

Posts I've Made

In Topic: DirectX sprite movement seems 'glitchy'

05 August 2012 - 04:11 AM

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:

Posted Image

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.

In Topic: DirectX sprite movement seems 'glitchy'

02 August 2012 - 03:31 AM

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.

In Topic: DirectX sprite movement seems 'glitchy'

01 August 2012 - 06:07 PM

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


They appear to be, yes.

In Topic: DirectX sprite movement seems 'glitchy'

01 August 2012 - 06:14 AM

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();
}

In Topic: DirectX sprite movement seems 'glitchy'

01 August 2012 - 05:11 AM

Certainly. Here are the D3DPRESENT_PARAMETERS:

ZeroMemory(&d3dPresentationParameters, sizeof(d3dPresentationParameters));
d3dPresentationParameters.BackBufferFormat = d3dDisplayMode.Format;
d3dPresentationParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dPresentationParameters.Windowed = TRUE;

RECT tempRect;
GetClientRect(hwndInput, &tempRect);
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;

if(d3dPresentationParameters.Windowed == FALSE)
{
  d3dPresentationParameters.FullScreen_RefreshRateInHz = d3dDisplayMode.RefreshRate;
}
d3dPresentationParameters.EnableAutoDepthStencil = TRUE; // Not sure if needed.
d3dPresentationParameters.AutoDepthStencilFormat = D3DFMT_D16;
d3dPresentationParameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;

My window creation code:

Window::Window(const wchar_t *szAppNameImport)
{
szAppName = szAppNameImport;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = NULL;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = GetModuleHandle(NULL);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = szAppName;
wc.hIconSm = LoadIcon(wc.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
created = true;
}

VOID Window::Create(LPCWSTR windowTitle,unsigned int window_width, unsigned int window_height, HWND parent)
{
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;
AdjustWindowRect(&windowRect, NULL, NULL); // So we can have the window at the correct size based on the desired client area size.
if(!RegisterClassEx(&wc))
{
  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();
}
SetWindowLongPtr(mHwnd, GWLP_USERDATA, (LONG_PTR)this);
ShowWindow(mHwnd, SW_SHOWDEFAULT);

UpdateWindow(mHwnd);
}

PARTNERS