[SlimDX]

Started by
5 comments, last by skowronkow 15 years, 9 months ago
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
Advertisement
Show us what you've done so far and we will try to help you get it working.
Mike Popoloski | Journal | SlimDX
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.


[StructLayout(LayoutKind.Sequential)]    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;            stream.WriteRange(vertexData);            Vertices.Unlock();


and the last modification is in render method:

Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);Device.BeginScene();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);Device.EndScene();Device.Present();


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

What i missed?

First thing I noticed...from the docs:
Texture1	Vertex format contains 1 texture coordinate set.Texture0	Vertex format contains no texture coordinate sets.

You don't want Texture0.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Thanks Promit, my mistake, ofcourse i need texture2... :) now it works fine
Quote: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.
Mike Popoloski | Journal | SlimDX
You're right ofcourse.

This topic is closed to new replies.

Advertisement