我目前正在尝试通过组合两个三角形来制作一个简单的正方形,就像 Riemer 的教程中那样(教程链接),但由于从 3.x 到 4.0 发生了很多变化,我发现这很困难。
我还想知道如何纹理这个“正方形”,所以如果有人可以通过给出一些例子或其他方式帮助我,我将不胜感激:)
谢谢!
I'm currently trying to make a simple square by combining two triangles, like in the tutorials by Riemer (Link to tutorial), but since a lot has changed from 3.x to 4.0, I find it difficult.
I would also like to know how to texture this "square", so if anyone could help me by giving some example or whatsoever, I would appreciate it :)
Thanks!
发布评论
评论(1)
下面是一个绘制简单纹理正方形的 XNA 4.0 程序示例。它需要将 Green-gel-x 纹理(来自 wiki-commons - 代码中的链接)添加到内容项目中(或替换为您自己的纹理)。绘制纹理正方形后,会在顶部绘制一个线框正方形,以便您可以看到三角形。此示例使用正交投影和 BasicEffect 而不是效果文件,但在其他方面与您链接到的 Riemer 教程类似。
为了执行纹理化,每个顶点需要一个纹理坐标。对于在正方形表面上平铺一次的纹理,左上角顶点的纹理坐标为 (0, 0),右下角顶点的纹理坐标为 (1, 1),依此类推。如果您想在正方形上平铺纹理两次,可以将所有右下角纹理坐标设置为 2,而不是 1。
Here is an example XNA 4.0 program that draws a simple textured square. It requires the Green-gel-x texture (from wiki-commons - link in code) added to the content project (or replaced with your own texture). After the textured square is drawn, a wireframe square is drawn over the top so you can see the triangles. This example uses an orthographic projection and a BasicEffect instead of an effect file but is otherwise similar to the Riemer tutorial you linked to.
To perform the texturing each vertex requires a texture coordinate. For a texture that tiles once across the surface of the square the texture coordinates are (0, 0) for the top left vertex and (1, 1) for the bottom right vertex and so on. If you wanted to tile the texture across the square twice, you could set all the bottom right texture coordinates to 2, instead of 1.