我找不到解决这个问题的方法:
我正在使用VertexPositionTexture创建带有纹理的矩形,并使用DrawUserPrimitives来绘制一些原始图形。
矩形是:
tmpPoint.VerticesList[0] = new VertexPositionTexture(new Vector3(-size, size, 0), new Vector2(0, 0));
tmpPoint.VerticesList[1] = new VertexPositionTexture(new Vector3(size, size, 0), new Vector2(1f, 0));
tmpPoint.VerticesList[2] = new VertexPositionTexture(new Vector3(-size, -size, 0), new Vector2(0, 1f));
tmpPoint.VerticesList[3] = new VertexPositionTexture(new Vector3(size, -size, 0), new Vector2(1f, 1f));
效果已设置:
Effect = new BasicEffect(game.GraphicsDevice) {
VertexColorEnabled = true,
TextureEnabled = true };
Effect.EnableDefaultLighting();
绘制方法:
public void DrawRectangle()
{
originalBlend = game.GraphicsDevice.BlendState;
game.GraphicsDevice.BlendState = BlendState.AlphaBlend;
Effect.World = PointScale * PointRotation * PointTranslation;
Effect.CurrentTechnique.Passes[0].Apply();
game.GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, VerticesList, 0, vertexBuffer.VertexCount / 2); 0, 0, 4, 0, 2);
game.GraphicsDevice.BlendState = originalBlend;
}
所有都很好,但是带有纹理的矩形没有颜色,只有alpha通道和黑色的渐变。它看起来像这样:
![enter image description here](https://istack.dev59.com/tz8HU.webp)
![enter image description here](https://istack.dev59.com/20m1J.webp)
Effect.EnableDefaultLighting();
Effect.LightingEnabled = true;
VertexColorEnabled = true;
颜色已经可以使用了...
你可能会感到困惑,但在Windows 7机器上,颜色已经可以正常工作。当我在TFS中提交所有更改,并在Windows 10机器上获取最新版本时,就出现了这个问题。我还没有Windows 7机器。但是我在另一台装有Windows 7可执行文件的机器上进行了检查,没有成功...
没有问题的主机:
C:\Program Files (x86)\MonoGame\v3.0\Assemblies\DesktopGL路径下的DLL为3.5.1.1679
C:\Program Files (x86)\MSBuild\MonoGame\v3.0\Tools路径下的DLL为3.5.1.1679
Debug\路径下的DLL为3.5.1.1679
加载的程序集(仅列出差异):
mscorlib.dll 4.6.1076
System.Core.dll 4.6.1055.0
System.dll 4.6.1075.0
System.Drawing.dll 4.6.1068.2
System.Windows.Forms.dll 4.6.1055.0
在出现问题的另一台Windows 10(任何版本的Windows 7+)机器上(没有差异):
C:\Program Files (x86)\MonoGame\v3.0\Assemblies\DesktopGL路径下的DLL为3.5.1.1679
C:\Program Files (x86)\MSBuild\MonoGame\v3.0\Tools路径下的DLL为3.5.1.1679
Debug\路径下的DLL为3.5.1.1679
加载的程序集(仅列出差异):
mscorlib.dll 4.6.1080
System.Core.dll 4.6.1038.0
System.dll 4.6.1081.0
System.Drawing.dll 4.6.1078.0
System.Windows.Forms.dll 4.6.1038.0
已打开问题: https://github.com/mono/MonoGame/issues/5029
更新: 看来这只是在英特尔HD图形上无法正常工作,但在Radeon和NVidia上却可以正常工作...
game.GraphicsDevice.Clear(Color.Transparent);
? - Nejc Galof