Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


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


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
5 replies to this topic

#1 sainimu78   Members   -  Reputation: 121

Like
0Likes
Like

Posted 19 August 2014 - 01:11 AM

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, 19 August 2014 - 03:24 AM.


Sponsor:

#2 Jason Z   Crossbones+   -  Reputation: 5382

Like
0Likes
Like

Posted 19 August 2014 - 08:26 AM

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.



#3 sainimu78   Members   -  Reputation: 121

Like
0Likes
Like

Posted 19 August 2014 - 07:20 PM

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.



#4 L. Spiro   Crossbones+   -  Reputation: 14354

Like
0Likes
Like

Posted 19 August 2014 - 07:37 PM

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, 19 August 2014 - 07:41 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

#5 sainimu78   Members   -  Reputation: 121

Like
0Likes
Like

Posted 19 August 2014 - 09:20 PM

 

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

 

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,

Attached Thumbnails

  • 1.jpg


#6 L. Spiro   Crossbones+   -  Reputation: 14354

Like
0Likes
Like

Posted 20 August 2014 - 04:51 PM

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, 20 August 2014 - 04:52 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




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