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

Started by
7 comments, last by Muzzy A 11 years, 6 months ago
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?
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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

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.
Doesn't the projection matrix helper function have an aspect ratio parameter? Like D3DXMatrixPerspectiveFovLH? Or can't you use that?

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

i'm not using a projection matrix, and when i do, my sprites disappear
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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

and you just multiply that into the worldMatrix, just like a cam and projection matrix? if so it's still making my sprite disappear =(
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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.


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.


EDIT: nvm, i got it. thanks

This topic is closed to new replies.

Advertisement