【发布时间】:2016-07-23 18:42:17
【问题描述】:
我找不到这个问题的解决方案:
我正在使用 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 通道和黑色渐变。它看起来像这样:
但纹理图像是:
当我尝试删除时:
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
更新: 似乎它不仅不适用于英特尔高清显卡,但在 Radeon 和 NVidia 上运行良好......
【问题讨论】:
-
发布您的代码。 minimal reproducible example
-
MickyD,谢谢。完成。
-
我调查了新的行为。
-
我很困惑,你说它在 Windows 7 上有效,但在 Windows 7 上无效。它是什么?
-
我有主机 Windows 7 机器,示例工作正常。而且我有另一台 Windows 7 机器的虚拟机,示例不工作。第二台机器,VM 系统没有安装 Monogame Desktop 组件,只运行从第一台机器复制的可执行文件。在主机上安装 Monogame Desktop。