   Color-Blurred Pixel Problem in DirectX (Solved - Windows Creation Issue)
  Hello,I am using DirectX 9 and attempting to draw pixels to the screen, but having problems with the colors blurring.I'm using code that I've gotten to work on other computers, but not my newest.  I have several methods of drawing the pixel - either writing the color directly to the locked back buffer, or by using the D3DXSprite interface to draw a 1x1 colored image to the screen at the desired coordinates.  I've noticed I have the same problem when using the D3DXLine interface as well.Here's the problem:First, I fill the screen with black at the beginning of my scene rendering. So far so good.  But then I try to draw a red pixel, and it looks blurry.  Let me elaborate:The pixel is rarely actually seen as one pixel on the screen - it's spread out across 2 or three screen pixels in actuality (I'm using an LCD screen, so I can tell).  Also, the color is blurred with the background - that is, the pure red pixel is dimmed, because it appears to be mixed with the black.  But my alpha is at full.If I draw several red pixels next to one another (say a 2x2 array of pixels), then the pixels are still spread out - it looks like a 4x4 array.  But the pixels at the center of this blob are brighter red than the pixels at the edges of the blog - no doubt because the center pixels are mixing with other red pixels, making them bright red, while the edge pixels are mixing with both red and black background pixels, making them dimmer.This problem occurs no matter what my screen resolution and no matter whether I'm in fullscreen mode or windowed mode - even when my program's dimensions are proportional to the screen's.The ONLY case where I get exactly the behavior I expect (single pixels, not blobs, with full color strength, not color blending) is when I got to fullscreen mode with dimensions as big as my screen (1680 x 1050).  If I go to fullscreen mode with any other dimensions, or if I go to windowed mode with any dimensions, I get the blurring.Perhaps I would expect such blurring if I was in fullscreen mode with other dimensions (thus the pixels are being stretched).  But in windowed mode, I want full control over every pixel in my window - I don't want the pixel to be dimmer or spread out.  I want it to be exactly where it belongs (on one pixel), with exactly the color I feed it.I suspect this is behavior from my graphics card which needs to be controlled via some call in DirectX.Can anyone help me out?Thanks[Edited by - Gauvir_Mucca on May 6, 2009 11:55:20 AM]
  Does this happen on other monitors too? If it's not working in Windowed mode, are you using AdjustWindowRect() to get the correct window size based on the client area size you want? Remember that CreateWindow takes a window size, not client area size. And in windowed mode, what is your desktop resolution?It sounds to me like you're not calling AdjustWindowRect in windowed mode, and your monitor just doesn't do non-native resolutions very well.   ;  Well the behavior when your backbuffer resolution doesn't match your monitor's native resolution in fullscreen mode should be completely expected.  An LCD monitor is only capable of displaying at its native resolution, this means that any lower-resolution input will upscaled to that native res.  Hence, the nasty blurring.For windowed mode you should be fine...as long as your backbuffer resolution exactly matches the size of your window's client area.  Are you sure this is the case?  Remember that the size you send to CreateWindow/CreateWindowEx is notthe size of the client area, it's the size of the window including the non-client areas (window frame, title bar, menu, etc.).  The AdjustWindowRectEx function can help you figure out what size window you want.Also...what is it that you're doing that you need direct pixel access?  In general D3D9 is not at all suitable for this sort of thing...in fact it will be slow and painful to use.   ;  I will be pointing to a different direction:You may be also noting the bilinear filtering.Use Point filtering everywhere.With 1x1 images and bilinear filtering, you'll get the behaviour you're describing.Cheers   ;Quote:Original post by MJPWell the behavior when your backbuffer resolution doesn't match your monitor's native resolution in fullscreen mode should be completely expected.  An LCD monitor is only capable of displaying at its native resolution, this means that any lower-resolution input will upscaled to that native res.  Hence, the nasty blurring.Ok, good.  But the problem persists in windowed mode, which bothers me.Quote:For windowed mode you should be fine...as long as your backbuffer resolution exactly matches the size of your window's client area.  Are you sure this is the case?  Remember that the size you send to CreateWindow/CreateWindowEx is notthe size of the client area, it's the size of the window including the non-client areas (window frame, title bar, menu, etc.).  The AdjustWindowRectEx function can help you figure out what size window you want.I believe I'm handling this issue already - here is my code:// save the window handle and instance for trackingmain_window_handle = hwnd;main_instance = hinstance;// resize the window so that client is really width x heightif (!full_screen){// now resize the window, so the client area is the actual size requested// since there may be borders and controls if this is going to be a windowed app// if the app is not windowed then it won't matterRECT window_rect = {0, 0, Screen_Width - 1, Screen_Height - 1};// make the call to adjust window_rectAdjustWindowRectEx(&window_rect, GetWindowstyle(main_window_handle), GetMenu(main_window_handle) != NULL, GetWindowExstyle(main_window_handle));// now resize the window with a call to MoveWindow()MoveWindow(main_window_handle,   0, // x position   0, // y position   window_rect.right - window_rect.left, // width   window_rect.bottom - window_rect.top, // height   FALSE);// show the window, so there's no garbage on first renderShowWindow(main_window_handle, SW_SHOW);} // end if windowedSo it looks like I'm calling the right functions.  Am I doing this incorrectly, or is my issue a different one?Quote:Also...what is it that you're doing that you need direct pixel access?  In general D3D9 is not at all suitable for this sort of thing...in fact it will be slow and painful to use.I'm just playing around with some small experiments, where performance isn't an issue.  So I won't be doing a lot of pixel-drawing in this manner in the long run, but the issue still bothers me - and as I said, the D3DXLine interface is having the same problems.   ;Quote:Original post by Matias GoldbergI will be pointing to a different direction:You may be also noting the bilinear filtering.Use Point filtering everywhere.With 1x1 images and bilinear filtering, you'll get the behaviour you're describing.CheersI call this function first:void CGraphicsSystem::Disable_Antialiasing(){// Disable anti-aliasingif(FAILED(pD3DDevice9->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT))){throw Exception("Could not disable anti-aliasing with the Direct3D9 Device.",__FILE__, __LINE__);}if(FAILED(pD3DDevice9->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT))){throw Exception("Could not disable anti-aliasing with the Direct3D9 Device.",__FILE__, __LINE__);}if(FAILED(pD3DDevice9->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT))){throw Exception("Could not disable anti-aliasing with the Direct3D9 Device.",__FILE__, __LINE__);}if(FAILED(pD3DXLine->SetAntialias(FALSE))){throw Exception("Could not disable anti-aliasing with the D3DXLine interface.",__FILE__, __LINE__);}}Will that not take care of the problem you've indicated?  If I call these functions first, the problem persists.   ;  I also don't know if this will help diagnose the problem, but I was playing around and found another issue.I can change the width and height I use for my window (in windowed mode).  The height seems to be well-behaved - if I make it extremely small (like 5 pixels), the window is the right size (i.e., 5 pixels).But if I change the width I want to use, there seems to be a minimum at about 100 (hard to tell exactly).  If I specify any smaller, the window appears on my screen to remain 100 pixels wide (though the pixels are stretched and blurred to make up for this, of course - so if I make the window 5 pixels wide, it remains 100 pixels wide, but a pixel drawn at x-coordinate of 0 will be about 20 pixels away from the center of a pixel drawn at x-coordinate of 1).I do not know why I can't make the window any thinner than 100, though I can make it shorter if I want.  As you can see in my code above, when I initialize, I use AdjustWindowRectEx() and MoveWindow() to resize the window to the desirable dimensions.  MoveWindow() returns TRUE, so I would expect that if I specify a width of 5, it give me a window of width 5 (plus whatever borders are needed by Windows), or else return FALSE.Any ideas?   ;  I found my problem, and am posting the solution here should anyone else have the same issue:In my window-creation code above, I use an incorrectly-size rectangle.  If I want a window with a DirectX buffer of dimensions M x N, I need to define my RECT that I pass to AdjustWindowRectEx() as having values (0, 0, M, N),  NOT (0, 0, M-1, N-1).Apparently the RECT that Windows is looking at considers the values as being (left, top, width, height), as opposed to (left, top, right, bottom) pixel coordinates.The corrected code is as follows:// save the window handle and instance for trackingmain_window_handle = hwnd;main_instance = hinstance;// resize the window so that client is really width x heightif (!full_screen){// now resize the window, so the client area is the actual size requested// since there may be borders and controls if this is going to be a windowed app// if the app is not windowed then it won't matter// OLD INCORRECT CODE//RECT window_rect = {0, 0, Screen_Width - 1, Screen_Height - 1};// NEW, CORRECTED CODERECT window_rect = {0, 0, Screen_Width, Screen_Height};// make the call to adjust window_rectAdjustWindowRectEx(&window_rect, GetWindowstyle(main_window_handle),GetMenu(main_window_handle) != NULL, GetWindowExstyle(main_window_handle));// now resize the window with a call to MoveWindow()MoveWindow(main_window_handle,   0, // x position   0, // y position   window_rect.right - window_rect.left, // width   window_rect.bottom - window_rect.top, // height   FALSE);// show the window, so there's no garbage on first renderShowWindow(main_window_handle, SW_SHOW);} // end if windowedI will alter the thread title to reflect that the problem has been solved.Thanks for all your recommendations.   