嘿,我有点麻烦了。我使用xna已有一段时间了,但是我对3D完全陌生。我正在从msdn网站上的winformsgraphicsdevice示例中逐字查看代码。它具有一个将原始三角形绘制到屏幕上的控件。就这么简单,但是我在这一行遇到了一个例外:
GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1);
Run Code Online (Sandbox Code Playgroud)
其中说:
"The current vertex declaration does not include all the elements required by the current vertex shader. Normal0 is missing."
我假设它与我的VertexPositionColor变量有关vertices。该代码在这里:
vertices = new VertexPositionColor[3];
vertices[0] = new VertexPositionColor(new Vector3(-1, -1, 0), Color.Black);
vertices[1] = new VertexPositionColor(new Vector3( 1, -1, 0), Color.Black);
vertices[2] = new VertexPositionColor(new Vector3(0, 1, 0), Color.Black);
Run Code Online (Sandbox Code Playgroud)
您的顶点着色器要求一个正常值(用于光照计算),但VertexPositionColorstruct没有此值。
您必须创建一个结构来存储顶点位置,颜色和法线数据,因为它不是XNA上的预建类型。
您可以在此处了解如何创建它:http : //www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/Terrain_lighting.php
他在那里创建了一个名为的结构VertexPositionColorNormal,而不是VertexPositionColor您当前使用的结构。
如果您不想要任何照明并且不使用BasicEffect,只需从使用的技术中删除照明变量/计算即可。如果您正在使用,请BasicEffect尝试将设置LightingEnabled和TextureEnabled属性设置为false。
| 归档时间: |
|
| 查看次数: |
7334 次 |
| 最近记录: |