Interminable

Members
  • Content count

    30
  • Joined

  • Last visited

Community Reputation

127 Neutral

About Interminable

  • Rank
    Member
  1. DirectX sprite movement seems 'glitchy'

    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.
  2. DirectX sprite movement seems 'glitchy'

    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.
  3. DirectX sprite movement seems 'glitchy'

    [quote name='lonewolff' timestamp='1343857375' post='4965314'] So, things are now displaying correctly in a borderless window? [/quote] They appear to be, yes.
  4. DirectX sprite movement seems 'glitchy'

    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]
  5. DirectX sprite movement seems 'glitchy'

    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]
  6. DirectX sprite movement seems 'glitchy'

    [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.
  7. DirectX sprite movement seems 'glitchy'

    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?
  8. DirectX sprite movement seems 'glitchy'

    [quote name='JWBaker' timestamp='1343660204' post='4964508'] [quote name='Interminable' timestamp='1343652839' post='4964473'] [quote name='lonewolff' timestamp='1343649700' post='4964463'] I believe that this is your answer. If you have a Window of 800x600 for example. The client area is less (eg 792x594 or something like that). If you have set your D3DPRESENTPARAMETERS to 800 x 600 the DX screen will differ from your actual client area. So, your sprites will be getting resized to fit and you will definately get the phenomenon that you are having. If you run full screen, do you have the same problem (I am guessing not). [/quote] You're right, in fullscreen the issue does not appear to be present! However, when trying to set the present parameters to the client area size, it didn't fix the issue when running it in a window. This is what I was doing: [CODE] RECT tempRect; GetClientRect(hwndInput, &tempRect); d3dPresentationParameters.BackBufferWidth = tempRect.right; d3dPresentationParameters.BackBufferHeight = tempRect.bottom; [/CODE] [/quote] How are you building your window? You have to do some math in order to get the client size correct by taking into accound the size of the windows border, its been a while since i have programmed that kind of thing, but lets see your window creation. [/quote] This is what GetClientRect() does, or at least that's my understanding of it. GetWindowRect() would get the size including the border, etc. EDIT: Interestingly, if I run it fullscreen at a resolution other than my native one (or the one I'm currently on I'm assuming), IDirect3DDevice9::Present() fails, but checking the HRESULT says the operation completed successfully. I have no idea what's wrong there.
  9. DirectX sprite movement seems 'glitchy'

    [quote name='lonewolff' timestamp='1343649700' post='4964463'] I believe that this is your answer. If you have a Window of 800x600 for example. The client area is less (eg 792x594 or something like that). If you have set your D3DPRESENTPARAMETERS to 800 x 600 the DX screen will differ from your actual client area. So, your sprites will be getting resized to fit and you will definately get the phenomenon that you are having. If you run full screen, do you have the same problem (I am guessing not). [/quote] You're right, in fullscreen the issue does not appear to be present! However, when trying to set the present parameters to the client area size, it didn't fix the issue when running it in a window. This is what I was doing: [CODE] RECT tempRect; GetClientRect(hwndInput, &tempRect); d3dPresentationParameters.BackBufferWidth = tempRect.right; d3dPresentationParameters.BackBufferHeight = tempRect.bottom; [/CODE]
  10. DirectX sprite movement seems 'glitchy'

    [quote name='lonewolff' timestamp='1343647159' post='4964451'] Out of interest, is this a windowed application? [/quote] It is indeed a windowed application.
  11. DirectX sprite movement seems 'glitchy'

    JWBaker, based on your original post I have eventually managed to put together this which I 'think' is the equivalent of what you put, however this may not be the case as it does not fix the issue unfortunately. [CODE] void Renderer::SetProjectionMatrix(float fieldOfView, float aspectRatio, float closestZLimit, float furthestZLimit) { D3DXMATRIXA16 projectionMatrix; //D3DXMatrixPerspectiveFovLH(&projectionMatrix, fieldOfView, aspectRatio, closestZLimit, furthestZLimit); D3DXMatrixTranslation(&projectionMatrix, -0.5f, 0.5f, 0.0f); D3DXMatrixOrthoLH(&projectionMatrix, window_width, window_height, 0, 1); md3dDevice->SetTransform(D3DTS_PROJECTION, &projectionMatrix); } [/CODE]
  12. DirectX sprite movement seems 'glitchy'

    [quote name='Icebone1000' timestamp='1343338380' post='4963437'] [quote name='Khatharr' timestamp='1343286202' post='4963209'] What kind of filtering are you using? I'm not sure if filtering applies to the edges of sprite renders but it may be worth looking at, since it's just changing a flag. [/quote] This. If Im understanding the issue right, thats definitely the problem. In the texture sampler filter, set everything to POINT instead of LINEAR. I remember finding the same "issue" the first time I did my pixel perfect sprite class. Linear is good if you will rotate the sprite, but for translation it leaves a ghost when the sprite moves/lies across/on coords that arent pixel perfect ( i.e. 1.06 pixels to righ) [/quote] I just tried doing as you describe with no discernible effect on the issue I am experiencing. Unless I'm doing something wrong. To write the lines below I used this page for help which I found from Googling what you stated: [url="http://www.toymaker.info/Games/html/sampler_states.html"]http://www.toymaker....ler_states.html[/url] If I have misinterpreted your instructions or not carried them out appropriately please let me know. [CODE] md3dDevice->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); md3dDevice->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); md3dDevice->SetSamplerState( 1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR ); md3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT ); md3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT ); md3dDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT ); [/CODE] [quote name='Madhed' timestamp='1343340877' post='4963448'] If you want pixel perfect sprites you have to make sure that coordinates get mapped exactly to pixels. I think that is the problem you seem to experience. [/quote] I understand this to most likely be the case, but my last post here was about how it wasn't fixing the issue (or indeed making any noticeable change). EDIT: [quote name='JWBaker' timestamp='1342233507' post='4958984'] [quote name='Interminable' timestamp='1342209934' post='4958898'] [quote name='JWBaker' timestamp='1342195376' post='4958828'] This might help the issue. [url="http://msdn.microsof...0(v=vs.85"]http://msdn.microsof...0(v=vs.85[/url]).aspx [/quote] What the article describes sounds like it could be related to the issue I'm having. The problem is, I'm not drawing a 2D texture to a surface. It's a standalone sprite. I'm unsure how I can deal with this. [/quote] Do you mean you are using the Sprite class? What you need to do is shift your Projection Matrix to account for the issue. This is how i setup mine and it seems to work. I'm not a DX master by any means but give it a shot and see if it helps. My Coordinate system has 0,0 at the center of the screen and +Y is up. Device.SetTransform(TransformState.Projection, Matrix.Translation(-0.5f, 0.5f, 0.0f) * Matrix.OrthoLH(_form.ClientSize.Width, _form.ClientSize.Height, 0, 1)); [/quote] I've finally worked out that the reason I can't find these DirectX functions is because they don't exist, they're part of .NET but I'm not using it, I'm using the pure Win32 API. Do you know how I can replicate what you're doing here using normal DirectX functions? Having since altered my code so I set the View Matrix and Projection Matrix, I'm currently setting my Projection Matrix in this manner: [CODE] D3DXMATRIXA16 projectionMatrix; D3DXMatrixPerspectiveFovLH(&projectionMatrix, fieldOfView, aspectRatio, closestZLimit, furthestZLimit); md3dDevice->SetTransform(D3DTS_PROJECTION, &projectionMatrix); [/CODE]
  13. DirectX sprite movement seems 'glitchy'

    Sorry to bump this but I am still experiencing this issue. I completely rewrote how I was drawing sprites to use textured quads instead of ID3DXSPRITE but I'm still getting the issue. I did read that I should adjust the coordinates of my quad by -0.5, but this hasn't helped. This is exactly what happens: * My sprite moves across the screen from left to right at a steady rate (calculated using the time it took to render each frame). * As a sprite moves along, at some point it will appear to shrink by what appears to be one pixel on the right side. * After it has moved along a bit more it will appear to expand by one pixel on the left side, thus returning to its original size. * It will repeat this process whilst it moves along. I'm not using any custom defined Projection Matrices or anything like that. This is the code I'm using for configuring my vertices, it's based on some other code I found online a while back. [CODE] void Sprite::ConfigureVertices() { if(vertexBuffer) { vertexBuffer->Release(); } if(FAILED(hResult = (*mTexturePointer->rendererPointer()->d3dDevicePointer())->CreateVertexBuffer (sizeof(TLVERTEX)*4, D3DUSAGE_WRITEONLY, mTexturePointer->rendererPointer()->GetD3DFVF_CUSTOMVERTEXFORMAT(), D3DPOOL_MANAGED, &vertexBuffer, NULL))) { logWindow.AddLogEntry(3, TEXT("IDirect3DDevice9::CreateVertexBuffer() FAILED"), hResult, GetLastError()); MessageBox(*mTexturePointer->rendererPointer()->hwndPointer(), TEXT("IDirect3DDevice9::CreateVertexBuffer() failed! This program will now close."), TEXT("CRITICAL FAILURE"), MB_OK | MB_ICONERROR | MB_TOPMOST); CheckCriticalExit(); } else logWindow.AddLogEntry(6, TEXT("IDirect3DDevice9::CreateVertexBuffer() succeeded"), hResult); vertices.resize(4); vertices[0].colour = 0xFFFF00FF; vertices[0].x = (float) objectPointer->coordinatesPointer()->x - 0.5f; // Left vertices[0].y = (float) objectPointer->coordinatesPointer()->y - 0.5f; // Top vertices[0].z = 0.0f; vertices[0].rhw = 1.0f; vertices[0].u = 0.0f; vertices[0].v = 0.0f; vertices[1].colour = 0xFFFF00FF; vertices[1].x = vertices[0].x+mTexturePointer->textureDescPointer()->Width;// - 0.5f; // Right vertices[1].y = objectPointer->coordinatesPointer()->y - 0.5f; // Top vertices[1].z = 0.0f; vertices[1].rhw = 1.0f; vertices[1].u = 1.0f; vertices[1].v = 0.0f; vertices[2].colour = 0xFFFF00FF; vertices[2].x = (float) vertices[0].x+mTexturePointer->textureDescPointer()->Width;// - 0.5f; // Right vertices[2].y = (float) vertices[0].y+mTexturePointer->textureDescPointer()->Height;// - 0.5f; // Bottom vertices[2].z = 0.0f; vertices[2].rhw = 1.0f; vertices[2].u = 1.0f; vertices[2].v = 1.0f; vertices[3].colour = 0xFFFF00FF; vertices[3].x = (float) objectPointer->coordinatesPointer()->x - 0.5f; // Left vertices[3].y = (float) vertices[0].y+mTexturePointer->textureDescPointer()->Height;// - 0.5f; // Bottom vertices[3].z = 0.0f; vertices[3].rhw = 1.0f; vertices[3].u = 0.0f; vertices[3].v = 1.0f; if(FAILED(hResult = vertexBuffer->Lock(0,0, (void**)&vertexVoidPointer, 0))) { logWindow.AddLogEntry(3, TEXT("IDirect3DVertexBuffer9::Lock() FAILED"), hResult, GetLastError()); MessageBox(*mTexturePointer->rendererPointer()->hwndPointer(), TEXT("IDirect3DVertexBuffer9::Lock() failed! This program will now close."), TEXT("CRITICAL FAILURE"), MB_OK | MB_ICONERROR | MB_TOPMOST); CheckCriticalExit(); } else logWindow.AddLogEntry(6, TEXT("IDirect3DVertexBuffer9::Lock() succeeded"), hResult); memcpy(vertexVoidPointer, vertices.data(), (sizeof(TLVERTEX)*vertices.capacity())); vertexBuffer->Unlock(); } [/CODE] I would greatly appreciate any assistance with this issue, I've searched online and found stuff relating to texel-pixel inconsistencies and whatnot. This SOUNDS like my issue, but what I tried to do to compensate for it (based on stuff I read online) does not appear to be doing anything to help.
  14. DirectX sprite movement seems 'glitchy'

    Personally I do not believe this is a timing issue. I think JWBaker was on the right track with regard to texture distortion. I just have no idea how to properly move it (by that I mean without the distortion) with SetTransform(), trouble is I'm unsure what step I need to do for Projection Matrices (as per my question a few posts back [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img] ). EDIT: I could have sworn when I edited my previous post that your post was not originally there. My edits explain what happened.
  15. DirectX sprite movement seems 'glitchy'

    [quote name='lonewolff' timestamp='1342256055' post='4959028'] I still think it is to do with your timer. GetSystemTime() seems to be only accurate to the millisecond. If you have a basic scene you might be rendering faster than 1000 fps, so your scene will be choppy as the timer wont be acurate enough. On my 3 year old video card my application (that also uses sprites) is rendering at 8000 FPS. This is why I had the same problems that your are experiencing. I had to re-think my timer. Give my timer a try [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] [code] #pragma once class Timer { public: Timer() { liCurrent.QuadPart=0; liPrevious.QuadPart=0; } ~Timer() { } long double TimeSinceLastFrame() { QueryPerformanceFrequency(&liPerfFreq); QueryPerformanceCounter(&liCurrent); ddFrameTime=(liCurrent.QuadPart-liPrevious.QuadPart)/long double(liPerfFreq.QuadPart)*1000; liPrevious.QuadPart=liCurrent.QuadPart; return ddFrameTime; } private: LARGE_INTEGER liCurrent; LARGE_INTEGER liPrevious; LARGE_INTEGER liPerfFreq; LARGE_INTEGER liStart; long double ddFrameTime; }; [/code]TimeSinceLastFrame() will return exactly that (but using the performance counters) I would love to know how you go [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] [/quote] I'll give it a try...but I'm also updating how far they should move using the time it takes to render the last frame. They appear to move smoothly already, just with minute changes in size as they go. Anyway, I'll EDIT this post with how I get on (or reply in a new post if there have been further responses). EDIT: TimeSinceLastFrame()'s first return value is insanely high (eg 9029811) and screws up anything that relies on it for moving etc at the very beginning of the program. It eventually settles down to values of hundreds. EDIT2: It appears to do this regardless of when the first call to it was, so I call it a few times needlessly at the beginning of my program to make it settle down a little before I start actually needing to use it. Unfortunately the issue I am experiencing with the minute changes in size remains.