• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Interminable

DirectX sprite movement seems 'glitchy'

35 posts in this topic

I fixed the crashing issue by altering my code to use DirectX's extended functions and structs, ie LPDIRECT3DDEVICE9EX, etc. I also found out how to enable DirectX's special debugging outputs which I recently learned about (I actually did this before converting my code to use extended functions to fix the crashing issue). I also used the debugging output to fix a few memory leaks.

The graphical issue in windowed mode still exists however. I'm wondering though, could it not be a client-area size issue and instead be some rendering process DirectX performs in fullscreen but not in a window?
0

Share this post


Link to post
Share on other sites
Nope, It will be the client area size.

You can test this by changing your window class style to WS_EX_TOPMOST | WS_POPUP. This way your client window size will be what you specify (but with no borders).
0

Share this post


Link to post
Share on other sites
[quote name='lonewolff' timestamp='1343770879' post='4965000']
Nope, It will be the client area size.

You can test this by changing your window class style to WS_EX_TOPMOST | WS_POPUP. This way your client window size will be what you specify (but with no borders).
[/quote]

The issue still exists in windowed mode despite using those styles to remove the borders, title bar, etc. Edited by Interminable
0

Share this post


Link to post
Share on other sites
Certainly. Here are the D3DPRESENT_PARAMETERS:

[CODE]
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;
[/CODE]

My window creation code:

[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);
}
[/CODE] Edited by Interminable
0

Share this post


Link to post
Share on other sites
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'

[code]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;[/code]
0

Share this post


Link to post
Share on other sites
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:

[CODE]
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();
}
[/CODE]
0

Share this post


Link to post
Share on other sites
[quote name='lonewolff' timestamp='1343857375' post='4965314']
So, things are now displaying correctly in a borderless window?
[/quote]

They appear to be, yes.
0

Share this post


Link to post
Share on other sites
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:

[CODE]
windowRect.right - windowRect.left,
windowRect.bottom - windowRect.left,
[/CODE]

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. Edited by Interminable
0

Share this post


Link to post
Share on other sites
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:

[img]http://i8.photobucket.com/albums/a44/Species1664/problem001.png[/img]

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:

[CODE]
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
[/CODE]

Which sets the values:

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

Following AdjustWindowRect() being called with the following arguments:

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

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:

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

Then, in my rendering code I have:

[CODE]
d3dDisplayMode.Width = window_width;
d3dDisplayMode.Height = window_height;

d3dPresentationParameters.BackBufferWidth = d3dDisplayMode.Width;
d3dPresentationParameters.BackBufferHeight = d3dDisplayMode.Height;
[/CODE]

(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. Edited by Interminable
-1

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  
Followers 0