0
Answer

DirectX - Obtaining part of a texture

Noir

Noir

15y
3.2k
1
I currently have a 128 x 32 px image file that I would like to grab the leftmost 32 x 32 px chunk out of. (Hope that makes sense) This is the code that I have at the moment:

private void OnCreateVertexBuffer(object sender, System.EventArgs e)

{

VertexBuffer buffer = (VertexBuffer)sender;

CustomVertex.PositionTextured[] verts = new CustomVertex.PositionTextured[4];

verts[0].Position = new Vector3(0, 0, 1f);

verts[1].Position = new Vector3(0.25f, 0, 1f);

verts[2].Position = new Vector3(0.25f, -0.25f, 1f);

verts[3].Position = new Vector3(0, -0.25f, 1f);

verts[0].Tu = 0; verts[0].Tv = 0;

verts[1].Tu = 0.25f; verts[1].Tv = 0;

verts[2].Tu = 0.25f; verts[2].Tv = 1;

verts[3].Tu = 0; verts[3].Tv = 1;

buffer.SetData(verts, 0, LockFlags.None);

}

Unfortunately, whenever I run the program, it simply displays the entire image file squeezed into a small square space, instead of the square section that I asked for. What am I doing wrong?

Note: The only reason I do not wish to use many separate image files is because I plan on expanding the image file to include many different textures, and having a folder filled with small image files is going to leave a big mess.