• 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

I need to display an image at its actual size on window using D3d. How

5 posts in this topic

I have tried. I used the "Textures" example in dx sdk june10, but all my tryings of displaying look so pixelated.

 

Should I set the back buffer size to the image size? How to do this?

 

Or other methods should I take?

    if( FAILED( g_pd3dDevice->CreateVertexBuffer( 6*2 * sizeof( CUSTOMVERTEX ),
                                                  0, D3DFVF_CUSTOMVERTEX,
                                                  D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
    {
        return E_FAIL;
    }

    // Fill the vertex buffer. We are setting the tu and tv texture
    // coordinates, which range from 0.0 to 1.0
    CUSTOMVERTEX* pVertices;
    if( FAILED( g_pVB->Lock( 0, 0, ( void** )&pVertices, 0 ) ) )
        return E_FAIL;
 
    pVertices[0].position = D3DXVECTOR3( -1.0f, 1.0f, 0.0f);
    pVertices[0].color = 0xffffffff;
    pVertices[1].position = D3DXVECTOR3( -1.0f, -1.0f, 0.0f);
    pVertices[1].color = 0xffffffff;
    pVertices[2].position = D3DXVECTOR3( 1.0f, -1.0f, 0.0f);
    pVertices[2].color = 0xffffffff;
 
    pVertices[3].position = D3DXVECTOR3( -1.0f, 1.0f, 0.0f);
    pVertices[3].color = 0xffffffff;
    pVertices[4].position = D3DXVECTOR3( 1.0f, 1.0f, 0.0f);
    pVertices[4].color = 0xffffffff;
    pVertices[5].position = D3DXVECTOR3( 1.0f, -1.0f, 0.0f);
    pVertices[5].color = 0xffffffff;
 
    pVertices[0].tu = 0.0f;
    pVertices[0].tv = 0.0f;
    pVertices[1].tu = 0.0f;
    pVertices[1].tv = 1.0f;
    pVertices[2].tu = 1.0f;
    pVertices[2].tv = 1.0f;  
 
    pVertices[3].tu = 0.0f;
    pVertices[3].tv = 0.0f;
    pVertices[4].tu = 1.0f;
    pVertices[4].tv = 0.0f;
    pVertices[5].tu = 1.0f;
    pVertices[5].tv = 1.0f;

    g_pVB->Unlock();
.........
cvNamedWindow("nihao");
cvResizeWindow(400, 300);
hWnd = (HWND)cvGetWindowHandle("nihao");
.........
in=cvLoadImage("24bpp_1920*1200_1.bmp", 1);
RECT rc;
rc.left = 0,
rc.top = 0;
rc.right = in->width;//1920
rc.bottom = in->height;//1200

g_pd3dDevice->Present( NULL, &rc, hWnd, NULL );

I create a small size window of 400x300px on purpose that I had tested it out that the more pixelated the displaying , the smaller the window is.

 

post-222996-0-27683700-1408437066.jpg

Edited by sainimu78
0

Share this post


Link to post
Share on other sites

The way you are rendering right now is that you have vertices that cover the entire viewport, and those vertices map to the entire texture.  That means that you will map the texture to the full size of the window, which is probably not what you want.  When you load the texture, you can query it for its dimensions, and then ensure that your window conforms to that aspect ratio.  As long as you have the same aspect ratio, then the image will not look squished in one direction or the other.  Outside of that, you should be able to make your window have the same size (taking into account the client area size) as your image, and then you will get 1-1 mapping.

0

Share this post


Link to post
Share on other sites

The way you are rendering right now is that you have vertices that cover the entire viewport, and those vertices map to the entire texture.  That means that you will map the texture to the full size of the window, which is probably not what you want.  When you load the texture, you can query it for its dimensions, and then ensure that your window conforms to that aspect ratio.  As long as you have the same aspect ratio, then the image will not look squished in one direction or the other.  Outside of that, you should be able to make your window have the same size (taking into account the client area size) as your image, and then you will get 1-1 mapping.

 

I got it, but I think having the same size window is hard. Commonly, a window can be created is limited in 1400x800px.

 

So, I want to query a back buffer whose size is as the same as my source image. Actually, I tried that, but failed, I can't find anymore tutorials or articles about how to query back buffer in specified size.

0

Share this post


Link to post
Share on other sites

Your back-buffer should always be the same size as whatever window into which you are rendering.

 

When you load a texture you can get its size.  Place the vertices based on this size.  For example, if the image is 800×600:

[0,0]------[800,0]

  |\           |

  | \          |

  |  \         |

  |   \        |

  |    \       |

  |     \      |

  |      \     |

  |       \    |

  |        \   |

  |         \  |

  |          \ |

  |           \|

[0,600]----[800,600]

You could also place the vertices at [-400,-300]…[400,300], etc.

 

Use an orthographic projection matrix for rendering.

D3DXMatrixOrthoLH() or D3DXMatrixOrthoOffCenterLH().

 

 

Never Present() with a specified rectangle.  I already told you that it causes scaling and pixelation.

Change:

g_pd3dDevice->Present( NULL, &rc, hWnd, NULL );

to:

g_pd3dDevice->Present( NULL, NULL, hWnd, NULL );

 

 

L. Spiro

Edited by L. Spiro
0

Share this post


Link to post
Share on other sites
 

Your back-buffer should always be the same size as whatever window into which you are rendering.
 
When you load a texture you can get its size.  Place the vertices based on this size.  For example, if the image is 800×600:
[font='courier new'][0,0]------[800,0][/font]
[font='courier new']  |\           |[/font]
[font='courier new']  | \          |[/font]
[font='courier new']  |  \         |[/font]
[font='courier new']  |   \        |[/font]
[font='courier new']  |    \       |[/font]
[font='courier new']  |     \      |[/font]
[font='courier new']  |      \     |[/font]
[font='courier new']  |       \    |[/font]
[font='courier new']  |        \   |[/font]
[font='courier new']  |         \  |[/font]
[font='courier new']  |          \ |[/font]
[font='courier new']  |           \|[/font]
[font='courier new'][0,600]----[800,600][/font]
You could also place the vertices at [font='courier new'][-400,-300]…[400,300][/font], etc.
 
Use an orthographic projection matrix for rendering.
D3DXMatrixOrthoLH() or D3DXMatrixOrthoOffCenterLH().
 
 
Never [font='courier new']Present()[/font] with a specified rectangle.  I already told you that it causes scaling and pixelation.
Change:
[font='courier new']g_pd3dDevice->Present( NULL, &rc, hWnd, NULL );[/font]
to:
[font='courier new']g_pd3dDevice->Present( NULL, NULL, hWnd, NULL );[/font]
 
 
L. Spiro

 

Oh, God, I'm making a GUI that will rendering images captured by an industrial camera in very high resolution.
High resolution means a general size window can't fit that image size.

If the image zoom out to fit the window, any details in the image can't be seen.
If the image display on window with intact size, the users can drag some scrolls to see whole image. This is correct solution.

My GUI shows in the attach file.
Only part area of the whole need to rendering, so I use a RECT to Present().

pVertices[0].position = D3DXVECTOR3( -in->width/2, in->height/2, 0.0f);
pVertices[0].color = 0xffffffff;
pVertices[1].position = D3DXVECTOR3( -in->width/2, -in->height/2, 0.0f);
pVertices[1].color = 0xffffffff;
pVertices[2].position = D3DXVECTOR3( in->width/2, -in->height/2, 0.0f);
pVertices[2].color = 0xffffffff;

pVertices[3].position = D3DXVECTOR3( -in->width/2, in->height/2, 0.0f);
pVertices[3].color = 0xffffffff;
pVertices[4].position = D3DXVECTOR3( in->width/2, in->height/2, 0.0f);
pVertices[4].color = 0xffffffff;
pVertices[5].position = D3DXVECTOR3( in->width/2, -in->height/2, 0.0f);
pVertices[5].color = 0xffffffff;

pVertices[0].tu = 0.0f;
pVertices[0].tv = 0.0f;
pVertices[1].tu = 0.0f;
pVertices[1].tv = in->height;
pVertices[2].tu = in->width;
pVertices[2].tv = in->height;

pVertices[3].tu = 0.0f;
pVertices[3].tv = 0.0f;
pVertices[4].tu = in->width;
pVertices[4].tv = 0.0f;
pVertices[5].tu = in->width;
pVertices[5].tv = in->height;

g_pVB->Unlock();

---------------------------------------

D3DXMATRIXA16 matProj;
D3DXMatrixOrthoLH(&matProj, 2, 2, 0, 1);
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );


how can the window show the whole image. no zooming, no filterring,
0

Share this post


Link to post
Share on other sites

Oh, God

Just “L. Spiro” is fine.

 

If the image zoom out to fit the window, any details in the image can't be seen.
If the image display on window with intact size, the users can drag some scrolls to see whole image. This is correct solution.

Then your solution is not in Direct3D, it is in Windows/Win32 API.
 

how can the window show the whole image. no zooming, no filterring,

Do everything I said before (back-buffer size must match the window’s dimensions, do not pass a RECT to Present(), etc.)
 
Except your target HWND is not the window anymore, it is a child window (see OBJECT A below).
 
 
#1: Make your window as you would make any other window for any other application.
#2: Add a custom control with the full size of the image you want to display in it.  This is “OBJECT A”.
#3: Add scroll bars to the control to contain it within the area you described as “My rendering area”.  http://www.functionx.com/win32/controls/scrollbars.htm
 
Everything in Direct3D you are currently doing on the window’s HWND you need to do instead to OBJECT A’s HWND.
That means the back buffers, presenting, creating the device, everything.  Direct3D no longer has any knowledge of your window at all.  Only OBJECT A.
 
 
L. Spiro Edited by L. Spiro
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