Advertisement Jump to content
Sign in to follow this  

[SlimDX] Triangle not Drawing Correctly

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

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(
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);
this.setShaderParams(view, world, projection);

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?

Share this post

Link to post
Share on other sites
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.

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!