2
\$\begingroup\$

I am trying to draw a textured ractangle like in this example. But instead of a texture the rectangle is just black.

Draw method:

protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);

    effect.EnableDefaultLighting();
    effect.World = world;
    effect.Projection = camera.Projection;
    effect.View = camera.View;
    effect.TextureEnabled = true;
    effect.Texture = grass;
    effect.LightingEnabled = true;

    foreach (var pass in effect.CurrentTechnique.Passes)
    {
        pass.Apply();

        GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, quad[0].Vertices, 0, 4, AlignedQuad.Indexes, 0, 2);
    }

    base.Draw(gameTime);
}

The effect is like a in the example a BasicEffect. The texture is existing and is not a black rectangle.

What am I missing or doing wrong? Thank you for your help.

\$\endgroup\$
5
  • \$\begingroup\$ The problem is in the code that you don't show. The code you show works for me. Just use the code from the example. There is no point in messing with the effect and changing it in every single draw call. In the example that code was in LoadContent() so that it only gets called once. \$\endgroup\$
    – dimitris93
    Commented May 28, 2015 at 7:59
  • \$\begingroup\$ Copied everything into a new project but I am still getting a black rectangle \$\endgroup\$
    – a-ctor
    Commented May 28, 2015 at 8:39
  • \$\begingroup\$ @Shiro could you upload your code i want to test if your program is generating a black rectangle too. \$\endgroup\$
    – a-ctor
    Commented May 28, 2015 at 8:42
  • \$\begingroup\$ You are saying that you get a black rectangle with the code of the example you posted ? Textured_Quad_Sample.zip is the download link from the link you posted. That's what I downloaded as well. \$\endgroup\$
    – dimitris93
    Commented May 28, 2015 at 13:05
  • \$\begingroup\$ Disable lighting and try again. If works, you know where is the problem :) \$\endgroup\$ Commented Oct 22, 2015 at 18:31

1 Answer 1

1
\$\begingroup\$

Try adding effect.Alpha = 1f; The alpha channel was probably premultiplied (check the texture properties in your content section).

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .