WP7 / XNA / Silverlight:绘制TriangleStrip后如何绘制spriteBatch?

时间:2012-04-05 14:06:35

标签: silverlight windows-phone-7 xna

我想在一些正方形的顶部绘制Silverlight-PhoneApplicationPage及其控件,我绘制为TriangleStrips。

另一种方式是完美的工作,但是方块是在我的控件上绘制的 - 我在Draw函数中做了类似的事情:

private void OnDraw(object sender, GameTimerEventArgs e)
{
    // Clean up device
    graphicsDevice.Clear(Microsoft.Xna.Framework.Color.Black);
    graphicsDevice.BlendState = BlendState.AlphaBlend;
    RasterizerState stat = new RasterizerState();
    stat.CullMode = CullMode.None;
    graphicsDevice.RasterizerState = stat;

    // Draw Silverlight UI element to Texture
    elementRenderer.Render();

    // Draw Silverlight UI element
    spriteBatch.Begin();
    spriteBatch.Draw(elementRenderer.Texture, Vector2.Zero, Microsoft.Xna.Framework.Color.White);
    spriteBatch.End();

    effect.Texture = tex;
    effect.TextureEnabled = true;
    effect.World = BillboardMatrix;
    effect.View = view;
    effect.Projection = projection;

    foreach (EffectPass pass in effect.CurrentTechnique.Passes)
    {
        pass.Apply();
        graphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, vertices, 0, 2);
    }
}

如果我尝试在三角形之后绘制spriteBatch,我会收到此错误: “NotSupportedException - 当使用不是2的幂的纹理大小时,XNA Framework Reach配置文件要求TextureAddressMode为Clamp。”

private void OnDraw(object sender, GameTimerEventArgs e)
{
    // Clean up device
    graphicsDevice.Clear(Microsoft.Xna.Framework.Color.Black);
    graphicsDevice.BlendState = BlendState.AlphaBlend;
    RasterizerState stat = new RasterizerState();
    stat.CullMode = CullMode.None;
    graphicsDevice.RasterizerState = stat;

    // Draw Silverlight UI element to Texture
    elementRenderer.Render();

    effect.Texture = tex;
    effect.TextureEnabled = true;
    effect.World = BillboardMatrix;
    effect.View = view;
    effect.Projection = projection;

    foreach (EffectPass pass in effect.CurrentTechnique.Passes)
    {
        pass.Apply();
        graphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, vertices, 0, 2);
    }

    // Draw Silverlight UI element
    spriteBatch.Begin();
    spriteBatch.Draw(elementRenderer.Texture, Vector2.Zero, Microsoft.Xna.Framework.Color.White);
    spriteBatch.End();
}

我也尝试设置graphicsDevice.SamplerStates[i] = SamplerState.LinearClamp;但它没有用。我做错了什么?

1 个答案:

答案 0 :(得分:0)

现在有效 - 我更改了CullMode:

stat.CullMode = CullMode.None;

stat.CullMode = CullMode.CullCounterClockwiseFace;