Jump to content
  • Advertisement
Sign in to follow this  

[Slimdx] antialiased hexagon D2D

This topic is 2863 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,
I have problem with SlimDX and D2D I am trying to draw a hexagonal grid. It should look like this: http://svn.belczyk.com/share/grid1.jpg but looks like this:
http://svn.belczyk.com/share/grid2.jpg.

I know that it's already anti-aliased but quality is quite poor. Is there any way to draw grid better?

Here's my code:

foreach (var oCell in SimMatrix.SelectMany(oRow => oRow))
{
var oColor = ...
var oBrush = new SolidColorBrush(Context2D.RenderTarget, new Color4(oColor.R, oColor.B, oColor.G));
var oBlackBrush = new SolidColorBrush(Context2D.RenderTarget, new Color4(0f, 0f, 0f));

Context2D.RenderTarget.AntialiasMode = AntialiasMode.PerPrimitive;

Context2D.RenderTarget.DrawGeometry(oCell.Polygon, oBlackBrush);

Context2D.RenderTarget.FillGeometry(oCell.Polygon, oBrush);


}

And Context2D (it's from SlimDX examples):
using System;
using System.Drawing;
using SlimDX.Direct2D;



public class DeviceContext2D : IDisposable
{


internal DeviceContext2D(IntPtr handle, DeviceSettings2D settings)
{
if (handle == IntPtr.Zero)
throw new ArgumentException("Value must be a valid window handle.", "handle");
if (settings == null)
throw new ArgumentNullException("settings");

this.settings = settings;

factory = new Factory();
RenderTarget = new WindowRenderTarget(factory, new WindowRenderTargetProperties
{
Handle = handle,
PixelSize = new Size(settings.Width, settings.Height)
});
}


~DeviceContext2D()
{
Dispose(false);
}


public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}


protected virtual void Dispose(bool disposeManagedResources)
{
if (disposeManagedResources)
{
RenderTarget.Dispose();
factory.Dispose();
}
}


public WindowRenderTarget RenderTarget
{
get;
private set;
}

DeviceSettings2D settings;

Factory factory;

}

Share this post


Link to post
Share on other sites
Advertisement
Have you tried doing the FillGeometry() and DrawGeometry() the other way round? You will probably need to do all the fills first then do a second pass with all the draws.

Share this post


Link to post
Share on other sites
I simply use textured hexagons: I made a similar sized hexagon in photoshop with anti-aliased edges. The inside of the edges that matters, that means the the hexagons on the edge of the hex-field won't be anti-aliased.

Share this post


Link to post
Share on other sites
@Adam_42: Yes, I have, same result.

@szecs: I was thinking about that but:

I checked my code once again and I find out, that I have mistake in my calculations (the length of hexagon edge was not constant for each side of hexagon). When I fix it my grid looks quite ok:
http://svn.belczyk.com/share/grid3.jpg

Thanks for all suggestions.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!