Home Game Development c# – XNA / Monogame Drawing Textured Quads

c# – XNA / Monogame Drawing Textured Quads

0
c# – XNA / Monogame Drawing Textured Quads

[ad_1]

I’ve been beginning to write some XNA / Monogame code these days, and needed to attract a quad with a Texture2D hooked up to it.

After looking out the web for some time, I’ve give you this render code:

public void Draw(GraphicsDevice gd)
{
    BasicEffect impact = new(gd);
    impact.Texture = this.texture;
    impact.TextureEnabled = true;

    VertexPositionTexture[] vertices = new VertexPositionTexture[4];
    vertices[0].Position = this.pointA;
    vertices[1].Position = this.pointB;
    vertices[2].Position = this.pointC;
    vertices[3].Position = this.pointD;

    foreach (EffectPass go in impact.CurrentTechnique.Passes) {
        go.Apply();
        gd.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices,
        0, 3, new[] { 0, 1, 2, 1, 2, 3 }, 0, 2);
    }
}

in a Quad class:

inner sealed class Quad
{
    Vector3 pointA;
    Vector3 pointB;
    Vector3 pointC;
    Vector3 pointD;
    Texture2D texture;
}

with this initialization code:

Quad quad = new Quad(new Vector3[] 
{ new Vector3(-0.5f, -0.5f, 1f), new Vector3(-0.5f, +0.5f, 1f),
  new Vector3(+0.5f, -0.5f, 1f), new Vector3(+0.5f, +0.5f, 1f) } //factors
debugTexture);

Currently, nothing seems on the display screen.
I’ve tried drawing 1 triangle solely, switching out the debugTexture,
utilizing DrawUserPrimitives as an alternative, and none of them appear to work.

Sorry if that is a straightforward repair or something, I’m unsure how OpenGL works.

Any assist will probably be apprieciated.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here