Sorry to sound needy, but I have been trying really hard to get one! I have been happily using monogame in my 2D hex map hobby - spritebatch goes a long way! - but now I would like to programitacally generate antialiased curves and so forth - in a windowed form. I have tried monogameforms
enableantialias, but I can’t seem to hit the mark. Is there a shortish program examplar that draws an antialised triangle that I could build from?
I didn’t add triangles yet, but you could use this code as a base: https://github.com/Apostolique/Apos.Shapes
I use the math from: Inigo Quilez :: fractals, computer graphics, mathematics, shaders, demoscene and more
Alternatively did you try rendering a triangle mesh? Drawing Triangles - RB Whitaker's Wiki
Thanks I will check them both out and get back.
I have finally cracked it! The following code draws antialiased lines and triangles. PrimitiveBatch can also be modified to accept textured primitives. I like the idea of PrimitiveBatch being so used to SpriteBatch. It sets up the orthographic projection etc so you’re all ready to go withouot delving into 3D stuff directly.
I spent an awful long time not getting things to work, but it turns out nicely simple - I hope my example will help others starting off. (P.S. dont’t forget to put your triangles in clockwise order … derrrrr!!)
The code below is not all in a codebox - how does it work please and I will edit…
{
using MonoGame.Forms.Controls;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
//my library that includes DoogeJ/MonoGame.Primitives2D
//and CartBlanche/MonoGame-Samples/primitives/PrimitiveBatch.cs
using GrafLib;
namespace monogamecontroltest
{
//inherits off Monogame.Forms.Controls.InvalidationControl,
//which is a windowed monogame screen that gets drawn only when invalidated
class MGcontrol : InvalidationControl
{
SpriteBatch sb;
PrimitiveBatch pb;
protected override void Initialize()
{
base.Initialize();
SetMultiSampleCount(8); //setting of only 2 gave cruder antialiasing
sb = new SpriteBatch(GraphicsDevice);
pb = new PrimitiveBatch(GraphicsDevice);
}
protected override void Draw()
{
base.Draw();
GraphicsDevice.Clear(Color.White);
//make use of the MonoGame.Forms.Services "Editor"
Editor.BeginAntialising();
sb.Begin();
sb.DrawLine(20, 20, 40, 100, Color.Black, 10);
sb.End();
pb.Begin(PrimitiveType.TriangleList);
pb.AddVertex(new Vector2(100, 100), Color.Red);
pb.AddVertex(new Vector2(200, 100), Color.Red);
pb.AddVertex(new Vector2(170, 195), Color.Red);
pb.End();
Editor.EndAntialising();
}
}
}
You can use 3 backticks:
```csharp
Console.WriteLine("Hello World!");
```
I see, thanks!
I can now also add some information about the wrapping mode of textures used by device.DrawUserPrimitives in the PrimitiveBatch Flush method- just put it immediately before each call … " I have the power!!"
device.SamplerStates[0] = SamplerState.PointWrap;
device.DrawUserPrimitives<VertexPositionColorTexture>(primitiveType, vertices, 0,
primitiveCount);
using MonoGame.Forms.Controls;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
//my library that includes DoogeJ/MonoGame.Primitives2D
//and CartBlanche/MonoGame-Samples/primitives/PrimitiveBatch.cs
using GrafLib;
namespace monogamecontroltest
{
//inherits off Monogame.Forms.Controls.InvalidationControl,
//which is a windowed monogame screen that gets drawn only when invalidated
class MGcontrol : InvalidationControl
{
SpriteBatch sb;
PrimitiveBatch pb;
protected override void Initialize()
{
base.Initialize();
SetMultiSampleCount(8); //setting of only 2 gave cruder antialiasing
sb = new SpriteBatch(GraphicsDevice);
pb = new PrimitiveBatch(GraphicsDevice);
}
protected override void Draw()
{
base.Draw();
GraphicsDevice.Clear(Color.White);
//make use of the MonoGame.Forms.Services "Editor"
Editor.BeginAntialising();
sb.Begin();
sb.DrawLine(20, 20, 40, 100, Color.Black, 10);
sb.End();
pb.Begin(PrimitiveType.TriangleList);
pb.AddVertex(new Vector2(100, 100), Color.Red);
pb.AddVertex(new Vector2(200, 100), Color.Red);
pb.AddVertex(new Vector2(170, 195), Color.Red);
pb.End();
Editor.EndAntialising();
}
}