填充 XNA 中顶点所包围的 2D 区域
我正在通过实践来学习 XNA,正如标题所述,我试图看看是否有一种方法可以填充由平面上的顶点集合定义的 2D 区域。我想填充颜色,而不是基于文件的纹理。
例如,采用一个圆角矩形,其顶点由四个四分之一圆三角形扇形定义。顶点是通过构建三角形集合来定义的,但三角形可能不相邻。
此外,我想用多种颜色填充它——即将边界区域分为四个垂直带,并且每个带都有不同的颜色。您不必向我提供代码,向我指出资源将会有很大帮助。我可以很方便地使用谷歌(我确实首先尝试过,但惨败了)。
这既是对“什么适合 XNA”的探索,也是它的实现。作为 XNA 的新手,我还想了解除了可以做什么和不能做什么之外,应该做什么和不应该做什么。
I'm learning XNA by doing and, as the title states, I'm trying to see if there's a way to fill a 2D area that is defined by a collection of vertices on a plane. I want to fill with a color, not a file-based texture.
For an example, take a rounded rectangle whose vertices are defined by four quarter-circle triangle fans. The vertices are defined by building a collection of triangles, but the triangles may not be adjacent.
Additionally, I would like to fill it with more than a single color -- i.e. divide the bound area into four vertical bands and have each a different color. You don't have to provide me the code, pointing me towards resources will help a great deal. I can be handy with Google (which I did try first, but have failed miserably).
This is as much an exploration into "what's appropriate for XNA" as it is the implementation of it. Being pretty new to XNA, I'm wanting to also learn what should and shouldn't be done on top of what can and can't be done.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不算太多,但这是一个开始:
颜色填充是通过使用着色器完成的。 Reimer 的有关像素着色器的 XNA 教程 是一个很棒的资源关于这个话题。
您需要计算几何图形并建立顶点缓冲区来保存它。请注意,XNA 中的所有矢量几何体都是 3D 的,但使用固定在平面上的相机将模拟 2D。
要向不同的三角形添加不同的颜色,您基本上需要将几何体分组到单独的顶点缓冲区中。然后,对于每个缓冲区,使用带有
color
参数的着色器,在将缓冲区传递到图形设备之前设置适当的颜色。或者,您可以使用包含颜色信息的顶点格式,它基本上可以让您为每个顶点分配一种颜色。
Not too much but here's a start:
The color fill is accomplished by using a shader. Reimer's XNA Tutorials on pixel shaders is a great resource on the topic.
You need to calculate the geometry and build up vertex buffers to hold it. Note that all vector geometry in XNA is in 3D, but using a camera fixed to a plane will simulate 2D.
To add different colors to different triangles you basically need to group geometry into separate vertex buffers. Then, using a shader with a
color
parameter, for each buffer,set the appropriate color before passing the buffer to the graphics device. Alternatively, you can use a vertex format containing color information, which basically let you assign a color to each vertex.