Jump to content
  • Advertisement
Sign in to follow this  


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

Hi! I have little problem with texturing in SlimDX. I create simple triangle and i want to add texture to it. Could someone give me a simple example how can i get it? (I've read some tuts for MDX 2.0 so i would be appreciated to see WORKING slimDX's examples) Thanks for Yor help

Share this post

Link to post
Share on other sites
OK, so lets try to modify MiniTri example from D3D9 folder in your SlimDX examples to get our triangle textured.

I guess, firstly we need to modify our custom vertices type.

struct Vertex
public Vector4 PositionRhw;
public int Color;
public float Tu;
public float Tv;

Is it correct? (Color ofcourse its not important here)

Then i load texture form png, lets called it tex, and modify our VertexBuffer to:

Vertices = new VertexBuffer(Device, 3*Marshal.SizeOf(typeof(Vertex)), Usage.WriteOnly,VertexFormat.None,Pool.Managed);

DataStream stream = Vertices.Lock(0, 0, LockFlags.None);
Vertex[] vertexData = new Vertex[3];
vertexData[0].PositionRhw = new Vector4(400.0f, 100.0f, 0.5f, 1.0f);
vertexData[0].Color = Color.Red.ToArgb();
vertexData[0].Tu = 0.0f;
vertexData[0].Tv = 0.0f;
vertexData[1].PositionRhw = new Vector4(650.0f, 500.0f, 0.5f, 1.0f);
vertexData[1].Color = Color.Blue.ToArgb();
vertexData[1].Tu = 1.0f;
vertexData[1].Tv = 0.0f;
vertexData[2].PositionRhw = new Vector4(150.0f, 500.0f, 0.5f, 1.0f);
vertexData[2].Color = Color.Green.ToArgb();
vertexData[2].Tu = 1.0f;
vertexData[2].Tv = 1.0f;

and the last modification is in render method:

Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);

Device.SetTexture(0, tex);
Device.SetStreamSource(0, Vertices, 0, Marshal.SizeOf(typeof(Vertex)));

Device.VertexFormat = VertexFormat.PositionRhw | VertexFormat.Diffuse | VertexFormat.Texture0;

Device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);

And what i get is the same triangle with a little bit more darked colors..

What i missed?

Share this post

Link to post
Share on other sites
First thing I noticed...from the docs:

Vertex format contains 1 texture coordinate set.

Vertex format contains no texture coordinate sets.

You don't want Texture0.

Share this post

Link to post
Share on other sites
Original post by skowronkow
Thanks Promit, my mistake, ofcourse i need texture2... :) now it works fine

I believe you want Texture1, since you only have one set of texture coordinates in your structure.

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.

GameDev.net 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!