Jump to content
  • Advertisement
Sign in to follow this  
Fire Lancer

2D rendering in D3D10 problem

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

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()
	//world - this is set by every draw method anyway
	device->SetTransform(D3DTS_VIEW, &mat);
		  (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;
	  (float)(size.h), 0, 0, 1);
//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()
	UINT stride = sizeof(Basic2DVertex);
	UINT offset = 0;
	device->IASetVertexBuffers(0, 1, &basic2DBuffer, &stride, &offset);
	for(UINT i=0; p<techDesc.Passes; ++i)
		device->Draw(3, 0);

and the shader
matrix Projection;

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

    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
        SetVertexShader  (CompileShader(vs_4_0, VS()));
        SetGeometryShader(NULL );
        SetPixelShader   (CompileShader(ps_4_0, PS()));

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 this post

Link to post
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.

Share this post

Link to post
Share on other sites
If I dont use the projection matrix it works fine with a triangle where (0,0) is centre and (-1,1) is top left. How can I check if its a culling probem, in d3d9 theres a method to disable culling, but it seems to have moved under d3d10?

I'll try changing the value in my vertices param, I thought 0,1 was inclusive, mayby not...

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!