Jump to content
  • Advertisement
Sign in to follow this  
Stormtrooper

SlimDX - Back to the basics

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

Ok, I wanted to test out shaders using actual vertex data instead of sprites. So I duplicated the Minitri example to use as my test bed. The current step I'm on is creating a quad. I found c++ tutorials at directxtutorials.com which explains how to create a quad. Aside from my code being SlimDX and C# everything is the same. Now my code is drawing the first triangle, but not the second. I am using the debug runtimes and DebugView and no errors come up.
            Vertices = new VertexBuffer(Device, 4 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Managed);
            DataStream stream = Vertices.Lock(0, 0, LockFlags.None);
            Vertex[] vertexData = new Vertex[4];
            vertexData[0].PositionRhw = new Vector4(150.0f, 100.0f, 0.5f, 1.0f);
            vertexData[0].Color = Color.Red.ToArgb();
            vertexData[1].PositionRhw = new Vector4(650.0f, 500.0f, 0.5f, 1.0f);
            vertexData[1].Color = Color.Blue.ToArgb();
            vertexData[2].PositionRhw = new Vector4(150.0f, 500.0f, 0.5f, 1.0f);
            vertexData[2].Color = Color.Green.ToArgb();
            vertexData[3].PositionRhw = new Vector4(650.0f, 100.0f, 0.5f, 1.0f);
            vertexData[3].Color = Color.Green.ToArgb();
            stream.WriteRange(vertexData);
            Vertices.Unlock();

...
            Device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
...

Share this post


Link to post
Share on other sites
Advertisement
A triangle strip with 4 vertices renders 2 triangles using the vertices in this order:
First Triangle: 0 1 2
Second Triangle: 1 3 2

As you have the vertices ordered, one of them will be culled.

Try putting them in this order:
(150,100,0.5)
(650,100,0.5)
(650,500,0.5)
(150,500,0.5)

That order is based on you seeing the first triangle correctly. If you're really seeing the second triangle correctly, that order is incorrect!

Share this post


Link to post
Share on other sites
Thanks for the reply. Now only the second triangle gets drawn(Or the first triangle is simply flipped). I didn't know the order mattered...that definitely helps.

Share this post


Link to post
Share on other sites
Quote:
Original post by Buckeye
Where is your eyepoint and what point are you looking at?



projMat = Matrix.PerspectiveFovLH((float)Math.PI / 4, 800 / 600, 1f, 20f);
viewMat = Matrix.LookAtLH(new Vector3(0, 0, 0), new Vector3(0, -1, 0), new Vector3(0, 1, 1));

Device.SetTransform(TransformState.Projection, projMat);
Device.SetTransform(TransformState.View, viewMat);

Share this post


Link to post
Share on other sites
I don't know how to set it in SlimDX, but two useful tricks are to enable wireframe and to disable back/front culling. You can then use this to verify that your position data is correct and toggle the ordering until you get it correct - should you prefer the trial-and-error approach.

Alternatively, have a read of the SDK documentation on geometry types and draw your patterns out on paper first. Pen and paper solves this every time for me [cool]

Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffers
I don't know how to set it in SlimDX, but two useful tricks are to enable wireframe and to disable back/front culling. You can then use this to verify that your position data is correct and toggle the ordering until you get it correct - should you prefer the trial-and-error approach.

Alternatively, have a read of the SDK documentation on geometry types and draw your patterns out on paper first. Pen and paper solves this every time for me [cool]

Jack


Aha! I enabled wireframe and disabled culling and found the culprit.

Share this post


Link to post
Share on other sites
I find your view a little confusing, but that's my problem, not yours! [smile]
So..
Try:
(150,100,0.5)
(650,100,0.5)
(150,500,0.5)
(650,500,0.5)

If that doesn't work, try:
(150,100,0.5)
(150,500,0.5)
(650,100,0.5)
(650,500,0.5)

[grin] That's from working with pencil and paper!

Share this post


Link to post
Share on other sites
Quote:
Original post by Buckeye
I find your view a little confusing, but that's my problem, not yours! [smile]
So..
Try:
(150,100,0.5)
(650,100,0.5)
(150,500,0.5)
(650,500,0.5)

If that doesn't work, try:
(150,100,0.5)
(150,500,0.5)
(650,100,0.5)
(650,500,0.5)

[grin] That's from working with pencil and paper!


Hehe...yea I just did that too and got your first answer. It works, the triangles are in the correct location. But when culling is turned on, they both disappear.


EDIT: I turned culling to Clockwise and it works. Now to figure out why the heck shaders aren't working.

Share this post


Link to post
Share on other sites
Quote:
I turned culling to Clockwise and it works.

Glad it works!

However, it might be better to use the second set of vertices I posted and leave culling at CCW. Depends on how your mind thinks, but DirectX is generally a left-handed system (cross-products, etc.) and things may get balled up if you render triangles CCW and forget to take that into account.

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!