Jump to content
  • Advertisement
Sign in to follow this  
skowronkow

[SlimDX]

This topic is 3643 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
Advertisement
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?

Share this post


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

Share this post


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

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!