Jump to content
  • Advertisement
Sign in to follow this  
BigFreak

"Relative" vertex positions...?

This topic is 4765 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Yeah, so I'm new to all this Direct3D malarky. Essentially I'm trying to get the very basics down, and get a square rendered. I've got it all sorted, so the VertexBuffer carries a four sided shape, with each side having equal length, but when it comes to render it's longer than it is tall. I found out this is because of the dimensions of the window; when I set it to a square window, the shape is displayed square. I'm just trying to get some simple 2D stuff under my belt so I can make a simple Tetris/whatever clone. I've been reading various tutorials, such as Drunken Hyena's page, but I couldn't find specific information on how to get a square to display square. If anyone can forward me to details behind the theory, and/or code that'd be much appreciated. Thanks a lot.

Share this post


Link to post
Share on other sites
Advertisement
You have to make the aspect ratio of your projection (viewing frustrum) correspond to the aspect ratio of the window. You want to do 2D, so I suppose you use this projection matrix:

link to msdn

If your window has dimensions window_width and window_height, you have to make sure that the w and h parameters of the D3DXMatrixOrthoLH function are created using the following formula:

w/h = window_width / window_height

Obviously, you still have to choose either w or h yourself. The other one can then be computed.

edit:
window_width and window_height, should actually be the dimensions of the client area (the part of the window without borders and title bar). Look at the AdjustWindowRectEx function to create a window with the correct client area size.

Share this post


Link to post
Share on other sites
Yeah, the msdn link didn't work, I'm assuming cos of their silly frames thing.

But anyway, I tried this:

Quote:

D3DXMATRIX ortho2D;
D3DXMATRIX identity;

D3DXMatrixOrthoLH(&ortho2D, width, height, 0.0f, 1.0f);
g_D3DDevice->SetTransform(D3DTS_PROJECTION, &ortho2D);
g_D3DDevice->SetTransform(D3DTS_WORLD, &identity);
g_D3DDevice->SetTransform(D3DTS_VIEW, &identity);


...where width and height are the adjusted dimensions of the window, and yeah, basically nothing got drawn :

Share this post


Link to post
Share on other sites
Quote:
Original post by BigFreak
Yeah, the msdn link didn't work, I'm assuming cos of their silly frames thing.

But anyway, I tried this:

Quote:

D3DXMATRIX ortho2D;
D3DXMATRIX identity;

D3DXMatrixOrthoLH(&ortho2D, width, height, 0.0f, 1.0f);
g_D3DDevice->SetTransform(D3DTS_PROJECTION, &ortho2D);
g_D3DDevice->SetTransform(D3DTS_WORLD, &identity);
g_D3DDevice->SetTransform(D3DTS_VIEW, &identity);


...where width and height are the adjusted dimensions of the window, and yeah, basically nothing got drawn :


You need to initialize the identity matrices also, with D3DXMatrixIdentity - an identity matrix does not equal an empty matrix (array of 0:s).

Share this post


Link to post
Share on other sites
Quote:
Original post by BigFreak
Yeah, the msdn link didn't work, I'm assuming cos of their silly frames thing.

My bad:
Quote:

Syntax

D3DXMATRIX *WINAPI D3DXMatrixOrthoLH( D3DXMATRIX *pOut,
FLOAT w,
FLOAT h,
FLOAT zn,
FLOAT zf
);
Parameters

pOut
[in, out] Pointer to the D3DXMATRIX structure that contains the resulting matrix.
w
[in] Width of the view volume.
h
[in] Height of the view volume.
zn
[in] Minimum z-value of the view volume which is referred to as z-near.
zf
[in] Maximum z-value of the view volume which is referred to as z-far.

Return Value
Pointer to a D3DXMATRIX structure that is a left-handed orthogonal projection matrix.


Quote:

...where width and height are the adjusted dimensions of the window, and yeah, basically nothing got drawn :

Do you do everything exactly as before, except for computing the h-parameter from your window size and the w-parameter?

Share this post


Link to post
Share on other sites
Yeah, I did everything else the same, but I don't really understand what you meant by this:
Quote:

If your window has dimensions window_width and window_height, you have to make sure that the w and h parameters of the D3DXMatrixOrthoLH function are created using the following formula:

w/h = window_width / window_height

Obviously, you still have to choose either w or h yourself. The other one can then be computed.

edit:
window_width and window_height, should actually be the dimensions of the client area (the part of the window without borders and title bar). Look at the AdjustWindowRectEx function to create a window with the correct client area size.


Surely if:

w/h = window_width / window_height

it's implied that w can be equal to window_width, and h can be equal to window_height? This is currently how I have then, equal to the dimensions of the window.

Share this post


Link to post
Share on other sites
Quote:
Original post by BigFreakSurely if:

w/h = window_width / window_height

it's implied that w can be equal to window_width, and h can be equal to window_height? This is currently how I have then, equal to the dimensions of the window.

True. You can make them equal. But you shouldn't :) Think about it. w and h are the size of "the screen" expressed in the same units as the world coordinates (more or less). If you make this really, really big (eg. 640 x 480, compared to the 1 or 10 of z_near, and the dimensions of the quad you try to draw) the object you try to draw wil appear smaller. Maybe it gets so small, that you can't see it anymore. I don't know if this is actually the case, but try using something in the range of z_near, or simply use the value for w you used before, and only compute the value of h from there.
If you insist on making w and h equal to the window size, you should also adjust your other dimensions accordingly.
I hope this solves your problem...

Share this post


Link to post
Share on other sites
OK, so I have this:
Quote:

D3DXMATRIX ortho2D;
D3DXMATRIX identity;

D3DXMatrixOrthoLH(&ortho2D, (float)1, (float)0.75, 0.0f, 1.0f);
D3DXMatrixIdentity(&identity);
g_D3DDevice->SetTransform(D3DTS_PROJECTION, &ortho2D);
g_D3DDevice->SetTransform(D3DTS_WORLD, &identity);
g_D3DDevice->SetTransform(D3DTS_VIEW, &identity);

And I'm trying to draw this:
Quote:

CustomVertex Triangle_Data[] = {
{-1.0f, -1.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0)},
{1.0f, -1.0, 0.0f, D3DCOLOR_XRGB(255, 0, 0)},
{-1.0f, 1.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0)},
{1.0f, 1.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0)}
};

...as a triangle strip, and I'm still seeing nothing :/

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!