【问题标题】:Graphical Glitch Xna GraphicsTutorial - Debug图形故障 Xna GraphicsTutorial - 调试
【发布时间】:2011-05-05 19:33:52
【问题描述】:

我的地形变得像这样奇怪的颜色:

http://tinypic.com/view.php?pic=307w421&s=7

有人知道这里出了什么问题吗? 我应该在代码的哪个区域(从概念上)进行调试?

更新:

它来自我学校的一个教程,基于:http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/Starting_a_project.php

我们使用了 BasicEffect 着色器并制作了引擎的各个部分,例如:相机、从高度图派生的 3d 顶点地形、基本照明、基本软法线和用于优化的缓冲区。

VertexPositionColorNormal 结构:

public struct VertexPositionColorNormal : IVertexType
{
    #region Field
    public Vector3 Position, Normal;
    public Color Color;

    #endregion

    #region Constructor

    public VertexPositionColorNormal(Vector3 position, Color color, Vector3 normal)
    {
        Position = position;
        Color = color;
        Normal = normal; 
    }

    #endregion

    #region properties
    
    public static VertexElement[] VertexElements =
    {
        new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
        new VertexElement(sizeof(float) * 3, VertexElementFormat.Color, VertexElementUsage.Color, 0),
        new VertexElement(sizeof(float)*3+4,VertexElementFormat.Vector3, VertexElementUsage.Normal,0),
    };

    public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration(VertexElements);

    VertexDeclaration IVertexType.VertexDeclaration
    {
        get { return VertexDeclaration; }
    }

    #endregion

【问题讨论】:

  • 也许您忘记发布图片了?我看不到
  • 你能显示你的结构VertexPositionColorNormal代码吗?
  • 你确定颜色是 sizeof(float)*3 吗?我希望 sizeof(int)*4 (RGBA) 代替。

标签: c# xna rendering terrain heightmap


【解决方案1】:

尝试删除此行末尾的,

new VertexElement(sizeof(float)*3+4,VertexElementFormat.Vector3, VertexElementUsage.Normal,0),

我还注意到您在代码中添加了constructor,但 Riemer 的网站上没有。

此外,将代码以 zip 文件的形式发布在某处可能会更容易,这样我们就可以查看。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-26
    • 2014-06-24
    • 1970-01-01
    • 1970-01-01
    • 2020-03-28
    • 2014-07-09
    • 1970-01-01
    相关资源
    最近更新 更多