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

Started by
15 comments, last by sainimu78 9 years, 7 months ago

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 !

Advertisement

You probably need to generate mipmaps and enable trilinear filtering.

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

Cheers!

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...

Let's make it simple

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

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!

How do you load the texture?

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?

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

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...

This topic is closed to new replies.

Advertisement