• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

# [SlimDX] Triangle not Drawing Correctly

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

1 reply to this topic

### #1jdub  Members   -  Reputation: 394

Like
0Likes
Like

Posted 20 August 2012 - 09:09 PM

Trying to render a triangle on the screen. Here's the code which sets up the transform:

Triangle Vertices:
Vector3[] vertices =
{
new Vector3(1.0f, 1.0f, 1.0f),
new Vector3(1.0f, 0.0f, 1.0f),
new Vector3(0.0f, 0.0f, 1.0f),
};


private void setShaderParams(Matrix view, Matrix world, Matrix projection)
{
BufferDescription bufferDescr = new BufferDescription(
Marshal.SizeOf(typeof(ConstantBuffer)),
ResourceUsage.Default,
BindFlags.ConstantBuffer,
CpuAccessFlags.None,
ResourceOptionFlags.None,
0);
DXBuffer buffer = new DXBuffer(this.device, bufferDescr);
DataStream stream = new DataStream(Marshal.SizeOf(typeof(ConstantBuffer)), true, true);
stream.Write<ConstantBuffer>(new ConstantBuffer() {View = Matrix.Transpose(view), World = Matrix.Transpose(world), Projection = Matrix.Transpose(projection)});
stream.Position = 0;
this.context.UpdateSubresource(new DataBox(0, 0, stream), buffer, 0);
}


this is called at the end of my init function:
Matrix view = Matrix.LookAtLH(Vector3.Zero, -Vector3.UnitZ, Vector3.UnitY);
Matrix world = Matrix.AffineTransformation(1f, Vector3.Zero, Quaternion.RotationAxis(Vector3.UnitY, 0f), Vector3.Zero);
Matrix projection = Matrix.PerspectiveFovLH(0.523598776f, 480 / 640, 1.0f, 100.0f);


here's my shader code:
cbuffer ConstantBuffer : register( b0 )
{
matrix World;
matrix View;
matrix Projection;
}

float4 VShader(float4 position : POSITION) : SV_Position
{
float4 output = position;
mul( output, World );
mul( output, View );
mul( output, Projection );
return output;
}

float4 PShader(float4 position : SV_POSITION) : SV_Target
{
return float4(1.0f, 1.0f, 0.0f, 1.0f);
}


Note that the camera is facing down the negative Z-Axis so the triangle would be out of view right? Wrong. triangle is in view which makes me think that none of the transformations are being applied and DirectX is treating the vertices of the triangle as if they were already transformed. Anybody have any clue where I'm going wrong?
J.W.

### #2Mike.Popoloski  Crossbones+   -  Reputation: 2670

Like
1Likes
Like

Posted 20 August 2012 - 09:51 PM

mul does not take the first parameter as in/out, only in. You seem to be ignoring the return value, which is why your positions aren't getting transformed.

A good way to track down problems like this is to look at the draw calls in PIX. It will show you the inputs and outputs of the vertex shader, so you can see immediately that it's going wrong.
Mike Popoloski | Journal | SlimDX

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS