Jump to content

  • Log In with Google      Sign In   
  • Create Account

Why the texture blurred ? I need it keeps the same resolution of the source image


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
16 replies to this topic

#1 sainimu78   Members   -  Reputation: 119

Like
0Likes
Like

Posted 18 August 2014 - 02:05 AM

The source image is 1920x1200 px. 

 

Here is my render funtion:

VOID Render()
{
    // Clear the backbuffer and the zbuffer
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
                         D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 );

    // Begin the scene
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
    
        g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
	g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
	g_pd3dDevice->SetSamplerState(0, D3DSAMP_BORDERCOLOR, 0x000000ff);
        g_pd3dDevice->SetTexture( 0, g_pTexture );

        // Render the vertex buffer contents
        g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );
        g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
        g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2);//2 * 50 - 2 );

        // End the scene
        g_pd3dDevice->EndScene();
    }

    // Present the backbuffer contents to the display
    // shows in two windows
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
    HWND hWnd = WindowFromDC(g_hDc);
    RECT rc; rc.bottom = 600, rc.left = 100, rc.right = 600, rc.top = 100;
    //RECT rc; rc.bottom = in->height, rc.left = 0, rc.right = in->width, rc.top = 0;
    g_pd3dDevice->Present( NULL, &rc, hWnd, NULL );
}

What will be seen shows in the attach file

 

Why does the image the program displays look so blurred? How to set the texture to look better. The source image is 1920x1200 px !

Attached Thumbnails

  • QQ图片20140818155031.jpg

Edited by sainimu78, 18 August 2014 - 02:38 AM.


Sponsor:

#2 Chris_F   Members   -  Reputation: 2386

Like
0Likes
Like

Posted 18 August 2014 - 02:58 AM

You probably need to generate mipmaps and enable trilinear filtering.



#3 kauna   Crossbones+   -  Reputation: 2519

Like
1Likes
Like

Posted 18 August 2014 - 03:05 AM

The image seems more like pixelated than blurred. How is your texture sampler set for drawing?

 

Cheers!



#4 tonemgub   Members   -  Reputation: 1139

Like
1Likes
Like

Posted 18 August 2014 - 03:13 AM

Your texture looks pixelated to me rather than blurred. If you want it to look smooth, you should use a texture filtering mode other than point-sampling.

For your simple example, try linear sampling first, just to see the difference:

 

g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);

 

You could also use mipmapping to get even better results...



#5 sainimu78   Members   -  Reputation: 119

Like
0Likes
Like

Posted 18 August 2014 - 03:59 AM

Let's make it simple

Just how should I display the source image on the dx rendering scene, ignoring the displaying size.

 

 



#6 kauna   Crossbones+   -  Reputation: 2519

Like
3Likes
Like

Posted 18 August 2014 - 04:09 AM

Well, it depends greatly on your needs ... since you can have any size of window, you can't expect the image to look the same in all the cases. Maybe you should add the sampler states as hinted earlier and tell us after it if the image looks the way you want it to look and enable mipmaps too if your haven't already.

 

Cheers!


Edited by kauna, 18 August 2014 - 04:15 AM.


#7 imoogiBG   Members   -  Reputation: 1187

Like
0Likes
Like

Posted 18 August 2014 - 04:34 AM

How do you load the texture?



#8 sainimu78   Members   -  Reputation: 119

Like
0Likes
Like

Posted 18 August 2014 - 05:24 AM

Well, it depends greatly on your needs ... since you can have any size of window, you can't expect the image to look the same in all the cases. Maybe you should add the sampler states as hinted earlier and tell us after it if the image looks the way you want it to look and enable mipmaps too if your haven't already.

 

Cheers!

 

I need a window displaying a image by using dx.

 

I added. 

these tow lines 

.........
g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
g_pd3dDevice->SetTexture( 0, g_pTexture );
..........

and they make no effects.

The image displaying on the window is blurred or, say, pixelated as before.

 

 

 

 

I don't know how to enable mipmaps, could you?



#9 sainimu78   Members   -  Reputation: 119

Like
0Likes
Like

Posted 18 August 2014 - 05:31 AM

How do you load the texture?

My program is modified from the sample code "texture" in dxsdk_june10.

 

This sample code load a texture using CreateTextureFromFile().

I substituted that function with CreateTexture() that loads a texture from memory



#10 Hodgman   Moderators   -  Reputation: 30388

Like
2Likes
Like

Posted 18 August 2014 - 05:57 AM

Are you trying to display it at actual size (one texture-pixel = one screen-pixel), or stretch it over the whole window?

If the first, you need to very carefully place your vertices at the corners of the screen pixels, which means shifting the vertices up+left by half a screen pixel.

If the second, you have to blur it, because you're resizing...

#11 kauna   Crossbones+   -  Reputation: 2519

Like
1Likes
Like

Posted 18 August 2014 - 06:21 AM

Ok, I think I got it:

 

There are 2 windows and the same image is drawn in both of them :

 

- In the first window the image seems to be correct (it is stretched over the whole window, mipmapping / filtering seems to work as intended). 

- In the second window the back buffer is streched over a 500x500 region. Probably the back buffer isn't 500x500 pixels, so the image to be presented is stretched without any filtering. I'm not sure if there is a way to stretch with some filtering operation - anyhow, if the back buffer isn't the same size as the destination rectangle the image quality won't be the same.

 

Cheers!

 

[edit] to fix the problem, you'll need another swap chain for the other window, with the correct back buffer size 

[edit 2] or fix your RECT rc to match the back buffer size


Edited by kauna, 18 August 2014 - 09:24 AM.


#12 L. Spiro   Crossbones+   -  Reputation: 13600

Like
2Likes
Like

Posted 18 August 2014 - 04:48 PM

You are Present()’ing the image to 2 different windows, so texture filters and mipmaps are unrelated.

 

Present() is what is resizing your image.  It only resizes 1 way: with a point filter.

Therefor the only possible result you can get with your current method is the one you see (which is pixelated, not blurred).

 

 

You have to render to the 2nd window separately (and using a linear filter), ensuring that its back buffer stays the correct width and height for Present() not to resize.

This means maintaining 2 back buffers, performing 2 renders, and performing 2 Present()’s.

 

 

L. Spiro


Edited by L. Spiro, 18 August 2014 - 08:53 PM.

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#13 sainimu78   Members   -  Reputation: 119

Like
0Likes
Like

Posted 18 August 2014 - 09:04 PM

Ok, I think I got it:

 

There are 2 windows and the same image is drawn in both of them :

 

- In the first window the image seems to be correct (it is stretched over the whole window, mipmapping / filtering seems to work as intended). 

- In the second window the back buffer is streched over a 500x500 region. Probably the back buffer isn't 500x500 pixels, so the image to be presented is stretched without any filtering. I'm not sure if there is a way to stretch with some filtering operation - anyhow, if the back buffer isn't the same size as the destination rectangle the image quality won't be the same.

 

Cheers!

 

[edit] to fix the problem, you'll need another swap chain for the other window, with the correct back buffer size 

[edit 2] or fix your RECT rc to match the back buffer size

 

I test it out

The buffer size is equal to the window size. 

But a window size is limited, commonly, in 1400x800

 

I tried pDevice->SetScissorRect(), It doesn't work.

 

How to set the buffer size?



#14 sainimu78   Members   -  Reputation: 119

Like
0Likes
Like

Posted 18 August 2014 - 11:05 PM

You are Present()’ing the image to 2 different windows, so texture filters and mipmaps are unrelated.

 

Present() is what is resizing your image.  It only resizes 1 way: with a point filter.

Therefor the only possible result you can get with your current method is the one you see (which is pixelated, not blurred).

 

 

You have to render to the 2nd window separately (and using a linear filter), ensuring that its back buffer stays the correct width and height for Present() not to resize.

This means maintaining 2 back buffers, performing 2 renders, and performing 2 Present()’s.

 

 

L. Spiro

 

 

How to ensure that?

 

I have tried :

    in = cvLoadImage("24bpp_1920x1200_1.bmp", 1);
    rc.left = 0; rc.top =0; rc.bottom = in->height; rc.right = in->width;
    cvReleaseImage(&in);
    g_pd3dDevice->SetScissorRect(&rc);
    g_pd3dDevice->GetScissorRect(&rc);
    IDirect3DSurface9* pSurf = NULL;
    IDirect3DSurface9* pBB = NULL;
    IDirect3DSwapChain9* pSwapChain = NULL;
    g_pd3dDevice->GetSwapChain(0, &pSwapChain);
    pSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pSurf);
    g_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBB);
 
    hr = g_pd3dDevice->StretchRect(pSurf, NULL, pBB, &rc, D3DTEXF_LINEAR);

Both methods totally make no effects.

There are still pixelated 



#15 sainimu78   Members   -  Reputation: 119

Like
0Likes
Like

Posted 19 August 2014 - 02:31 AM

somewhat conclusion

Attached Thumbnails

  • QQ20140819162352.jpg


#16 kauna   Crossbones+   -  Reputation: 2519

Like
0Likes
Like

Posted 19 August 2014 - 02:02 PM

When you draw to your 400x300 window, is your back buffer size 400x300?

 

- if you use Present to scale (RECT of a different size than the backbuffer) the backbuffer when flipping it will get pixelated (regardless of the resolution of the image)

 

Cheers!



#17 sainimu78   Members   -  Reputation: 119

Like
0Likes
Like

Posted 19 August 2014 - 07:28 PM

When you draw to your 400x300 window, is your back buffer size 400x300?

 

- if you use Present to scale (RECT of a different size than the backbuffer) the backbuffer when flipping it will get pixelated (regardless of the resolution of the image)

 

Cheers!

 

 

That it is.

 

How to allocate a back buffer in specified size matters now.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS