I’m only starting with 3D so I have a question about drawing pretransformed stuff onto the screen.
I was able to figure out how to draw colored polygons in pretransformed form by using some tutorials, but I just can’t understand how to texture them… Is that even possible? If so how?
What I have now:
private void TestVertices()
{
vertices = new VertexPositionColor[3];
vertices[0].Position = new Vector3(-0.5f, -0.5f, 0f);
vertices[0].Color = Color.Red;
vertices[1].Position = new Vector3(0, 0.5f, 0f);
vertices[1].Color = Color.Green;
vertices[2].Position = new Vector3(0.5f, -0.5f, 0f);
vertices[2].Color = Color.Blue;
}
and
protected override void Draw(GameTime gameTime)
{
device.Clear(Color.DarkSlateBlue);
effect.CurrentTechnique = effect.Techniques["Pretransformed"];
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
device.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1, VertexPositionColor.VertexDeclaration);
}
base.Draw(gameTime);
}
Instead of
VertexPositionColor, useVertexPositionColorTexturefor your vertices, and set theTextureCoordinatemember to a value between 0 and 1 on each axis.When drawing, set
GraphicsDevice.Texture[0]to the texture you want to use.Ensure that your pixel shader does something like this:
If you are using
BasicEffect, the equivalent is to useVertexPositionColorTexture, set theBasicEffect.Textureto your texture, and setBasicEffect.TextureEnabled = true.