Jump to content
  • Advertisement
Sign in to follow this  
MadButch

pixelated/grainy graphics on 2nd screen

This topic is 2445 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,

I have a weird problem with DirectX 9, related to the displayed graphics.
The problem occurs on Windows 7 when using SetRenderTarget to render to a surface, or under windows xp when I move my game window to the 2nd screen.
It only happens if the dimension of the target surface doesn't match the dimension of the source surface (for example a shrink).

What happens is that the normally nice looking graphics suddenly look deformed, as illustrated by the following image:
Nr1_Good_vs_Bad.png

I can add code to help track this down, but maybe just the image alone is recognized by a fellow developer who has seen the exact same problem.

Many thanks in advance for any help.

Kind regards,
Michaël



Some additional info:
If I use D3DXSaveSurfaceToFile() on the RenderTarget, then the image saved is still fine. So the rendering to the render target works.
The problem must happen during while presenting the packbuffer to the screen.

Here is the code that happens after the rendering is done:

// Now render to the backbuffer
hResult = m_lpD3DDevice->SetRenderTarget( 0, m_pBackBuffer );
// Clear the backbuffer
hResult = m_lpD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, m_clearColor, 1.0f, 0 );
// Begin the scene
hResult = m_lpD3DDevice->BeginScene();

// Set the sampler states
hResult = m_lpD3DDevice->SetRenderState( D3DRS_MULTISAMPLEANTIALIAS, FALSE );
m_lpD3DDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); // D3DTEXF_LINEAR D3DTEXF_ANISOTROPIC
m_lpD3DDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
m_lpD3DDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
m_lpD3DDevice->SetSamplerState( 0, D3DSAMP_MAXANISOTROPY, 0 ); // 1 for Anisotropic

// Set the render texture
hResult = m_lpD3DDevice->SetTexture( 0, m_pRenderTexture );
// Set the Stream source
hResult = m_lpD3DDevice->SetStreamSource( 0, m_pQuadVB, 0, sizeof(TextureVertex) );
hResult = m_lpD3DDevice->SetFVF( D3DFVF_TEXTURE_VERTEX );
// Draw the primitives
hResult = m_lpD3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

// End the scene
hResult = m_lpD3DDevice->EndScene();

// Present the backbuffer
hResult = m_lpD3DDevice->Present( NULL, NULL, NULL, NULL );

* All error handling has been removed to make the code more readable

Share this post


Link to post
Share on other sites
Advertisement
If the output window size doesn't match the back-buffer size your rendered image will be scaled when it is displayed, which can cause these artifacts. If the image is scaled with bilinear filtering it might not look too bad anyway, but sometimes pointsampling is used instead, for example if you move your window to another screen or if you switch between windowed and fullscreen mode.

It is usually best to always keep your back-buffer at exactly the same size as the output window/screen, so you never get any scaling.

If you actually want your graphics to be scaled, but still look nice, then it's usually better to manually render the image smaller and use mip-maps or some other type of filtering to avoid artifacts.

Share this post


Link to post
Share on other sites
It always worked fine under windows XP, but starting with Vista (and also Windows 7), it no longer looks like viable output... Aka it's better to not offer the resize option anymore.
I read once here (but can't find it anymore) that windows XP used some kind of linear filtering by default, and that the new windows don't.

I guess a workaround would be to have my render target (which has a set width/height) rendered onto a texture that has the same size as the back buffer, and then present that texture to the backbuffer.
That way the rendering to the backbuffer would not involve any scaling.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!