• 13
• 18
• 19
• 27
• 9

# 2D rendering in D3D10 problem

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

## Recommended Posts

When doing 2D stuff in D3D 9 I do the following, so that (0,0) was the top left and (bufferWidth,bufferHeight) was bottom right. How can I get the same effect in D3D10? D3D9 code:
void Graphics::setHUDTransforms()
{
D3DXMATRIXA16 mat;
//world - this is set by every draw method anyway
//view
D3DXMatrixIdentity(&mat);
device->SetTransform(D3DTS_VIEW, &mat);
//projection
D3DXMatrixOrthoOffCenterLH(&mat,
0,(float)size.w,
(float)size.h, 0, 0, 1);
device->SetTransform(D3DTS_PROJECTION, &mat);
}


I tried the following but it doesnt seem to render anything to the screen (no errors or anything)... D3D10 code:
//creation code
...create device, swapchain, load effect etc...
basic2DProjection = basic2DEffect->GetVariableByName("Projection")->AsMatrix();
D3DXMATRIXA16 projMat;
D3DXMatrixOrthoOffCenterLH(&projMat,
0,(float)(size.w),
(float)(size.h), 0, 0, 1);
basic2DProjection->SetMatrix((float*)projMat);
//test vertices
vertices[0].Col = D3DXVECTOR4(1.0, 0.0, 0.0, 1.0);
vertices[1].Col = D3DXVECTOR4(0.0, 1.0, 0.0, 1.0);
vertices[2].Col = D3DXVECTOR4(0.0, 0.0, 1.0, 1.0);
vertices[0].Pos = D3DXVECTOR3(100,100, 1);
vertices[1].Pos = D3DXVECTOR3(400,100, 1);
vertices[2].Pos = D3DXVECTOR3(400,400, 1);
...create buffer from vertices...

//render code
//test draw
void Test2DDraw()
{
device->IASetInputLayout(basic2DInputLayout);
UINT stride = sizeof(Basic2DVertex);
UINT offset = 0;
device->IASetVertexBuffers(0, 1, &basic2DBuffer, &stride, &offset);
device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
D3D10_TECHNIQUE_DESC techDesc;
basic2DTechnique->GetDesc(&techDesc);
for(UINT i=0; p<techDesc.Passes; ++i)
{
basic2DTechnique->GetPassByIndex(i)->Apply(0);
device->Draw(3, 0);
}
}


matrix Projection;

struct VS_INPUT
{
float4 Pos : POSITION;
float4 Col : COLOR;
};
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float4 Col : COLOR;
};

PS_INPUT VS(VS_INPUT input)
{
PS_INPUT output = (PS_INPUT)0;
output.Col = input.Col;
output.Pos = mul(input.Pos, Projection);
return output;
}

float4 PS(PS_INPUT input):SV_Target
{
return input.Col;
}

technique10 Render
{
pass P0
{
}
}


I expected this to render a triangle in the top left area of the screen, as it would in with those cords with my d3d9 code (asumming I set the world tranform to an identity matrix), however instead it appears to render nothing to the screen :(

##### Share on other sites
So does that mean its not possible to set d3d10 up todo 2D rendering in this manner?

##### Share on other sites
It's certainly possible, but the limited amount of code you're provided make it difficult to say for certain if your setup is incorrect -- anything that occurs in code you did not show could drastically alter the behavior.

If you've created the device with the debug flag and it's still not printing anything to the VS Output window, then you're doing everything "correctly" and just not seeing the results you expect (versus telling the API to do something wrong).

A simple, but tedious and entirely uneducated approach to finding out what's wrong, then, is that you start working backwards from where you are now towards first principles (i.e., back towards rendering a single point at 0,0,0). Start by setting your primitive topology to points, so that you eliminate the possibility of any kind of culling having an impact, then make your shader just pass the position through direction without transforming it -- et cetera.

Do note as well that the parameters to D3DXMatrixOrthoOffCenterLH are left, right, bottom, top. That's a common thing to not be accounting for correctly elsewhere. Your vertices also appear to be exactly on you far plane.