在MonoGame项目中,当我在Initialize()方法中执行此操作时
graphics.PreferMultiSampling = true;
graphics.ApplyChanges();
Console.WriteLine($"Device: {graphics.GraphicsDevice.Adapter.Description}");
Console.WriteLine($"Anti-aliasing: {(rasterizer.MultiSampleAntiAlias ? "YES" : "NO")}");
Console.WriteLine($"MultiSampling: {(graphics.PreferMultiSampling ? "YES" : "NO")}");这是在我的Draw方法中
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(rasterizerState: rasterizer);
DrawCheckerboard();
spriteBatch.End();
base.Draw(gameTime);

但是,如果为PreferMultiSampling = false,则结果为:

这是用一个干净的新项目测试的,我唯一添加的是
RasterizerState rasterizer = new RasterizerState { MultiSampleAntiAlias = false };与SpriteBatch一起使用
spriteBatch.Begin(rasterizerState: rasterizer);但是添加/删除它不会有任何影响。
棋盘是使用放大的单像素纹理绘制的。
pixel = new Texture2D(GraphicsDevice, 1, 1);
pixel.SetData(new[] { Color.White });绘制过程(可能与问题的原因无关)如下所示:
void DrawCheckerboard() {
bool IsWhite(int x, int y) {
var a = x % 2 == 0;
var b = y % 2 == 0;
return a == b;
}
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
var coordinates = ScaleCheckerboardCoordinatesToScreen(new Point(x, y));
spriteBatch.Draw(pixel, new Rectangle(coordinates, new Point(squareSize)), IsWhite(x, y) ? Color.White : Color.Black);
}
}
}
Point ScaleCheckerboardCoordinatesToScreen(Point coordinates) {
return new Point(offsetX + coordinates.X * squareSize, offsetY + coordinates.Y * squareSize);
}这个问题的原因是什么?
发布于 2018-04-09 18:30:32
https://stackoverflow.com/questions/49720100
复制相似问题