• Advertisement
Sign in to follow this  

How do you change back buffer width/height in D3D9?

This topic is 1911 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

by default, the projection to the screen is from -1 to 1 on x and y axis, but i want to change it a little bit, is there a way to do that?

Share this post


Link to post
Share on other sites
Advertisement
Generally just loading (or multiplying by) an ortho matrix is sufficient, but is there something else you have in mind? You sound as though you want to do this for some specific reason, but you're not saying what that reason is - there may be a more appropriate answer that better meets your underlying need but doesn't involve changing this projection.

Share this post


Link to post
Share on other sites
i set up a sprite manager, like D3D9'S ID3DXSprite,sorta, and it creates geometry based on the resolution of the texture.

Works fine if the window width and height are the same.

When they aren't the same, upon rotating the image it gets skewed, or stretched/squished, depending on the resolution of the window

I want to fix this by setting the projection based on the aspect ratio of the window.

Share this post


Link to post
Share on other sites
Doesn't the projection matrix helper function have an aspect ratio parameter? Like [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb205350(v=vs.85).aspx"]D3DXMatrixPerspectiveFovLH[/url]? Or can't you use that?

Share this post


Link to post
Share on other sites
An ortho matrix will do it.

If you want to keep the -dimension to +dimension scale then use D3DXMatrixOrtho(LH|RH); if you want a 0 to dimension scale use D3DXMatrixOrthoOffCenter(LH|RH).

So, some examples.

D3DXMatrixOrthoLH (&matrix, 2, 2, 0, 1) will preserve to -1 to 1 range in each axis (because the first two params are the size of the view volume, and -1 to 1 is size 2).
D3DXMatrixOrthoLH (&matrix, 4, 4, 0, 1) will bring it to a -2 to 2 range.

Sometimes more usefully, D3DXMatrixOrthoOffCenterLH (&matrix, 0, windowwidth, windowheight, 0, 0, 1) will give you a range that's from 0 to the dimension of your window in each axis, meaning that you can use window co-ordinates for positioning objects. So if you need to draw an object at position (200, 300) that's size 24x24, you just draw it at position (200, 300) at size 24x24 and that's exactly what you get.

Interesting fact.

There is absolutely nothing to stop you from multiplying a perspective matrix by an ortho matrix. If you want to extend the range a little, just do that.

Share this post


Link to post
Share on other sites
and you just multiply that into the worldMatrix, just like a cam and projection matrix? if so it's still making my sprite disappear =( Edited by Muzzy A

Share this post


Link to post
Share on other sites
You're going to need to post some code and give a fuller description of what you're currently doing before I can help any further here.

Share this post


Link to post
Share on other sites
[code]
D3DXMATRIX ortho;
D3DXMatrixOrthoLH(&ortho,2,(wndWidth/wndHeight)*2,0,1);

// Render the sprite
shader->SetMatrix("gWorld",&(worldMatrix*ortho);

// Vertex shader
output.position = mul(float4(position,1),gWorld);

// Correct no? take out the "worldMatrix*ortho" and have just "worldMatrix" and the sprite shows up
// with the ortho in there, it disappears.
[/code]

EDIT: nvm, i got it. thanks Edited by Muzzy A

Share this post


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

  • Advertisement