• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
sainimu78

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

16 posts in this topic

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 !

Edited by sainimu78
0

Share this post


Link to post
Share on other sites

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

 

Cheers!

1

Share this post


Link to post
Share on other sites

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

1

Share this post


Link to post
Share on other sites

Let's make it simple

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

 

 

0

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites
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...
2

Share this post


Link to post
Share on other sites

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
1

Share this post


Link to post
Share on other sites

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
2

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites

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 

0

Share this post


Link to post
Share on other sites

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!

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0