Quick GDI+ question..

B

Brian Basquille

Hello all,

Just a quick GDI+ related question for you all. I've three ellipses being
drawn in my game. I'm trying to smoothen the edges of them out using
anti-aliasing. Why is it that my puck (and neither of the paddles) is only
looking like it's been affected by this anti-aliasing, even though i apply
the SmoothingMode property before drawing anything?

See what i mean here:
http://homepage.eircom.net/~basquilletj/antialiasing.JPG

And here's the code i used:

private void GameDraw(Graphics g)
{
// anti-aliasing
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;

CreatePaddle1Region();
CreatePaddle2Region();
CreatePuckPath();

// puck brushes
Brush puckBr = new SolidBrush(Color.Red);
g.FillPath(puckBr, puckPth);
puckBr.Dispose();

// paddle brushes
Brush paddleBr = new SolidBrush(Color.Black);
g.FillRegion(paddleBr, rgnPaddle1);
g.FillRegion(paddleBr, rgnPaddle2);
paddleBr.Dispose();
}

Many thanks in advance.

Brian
 
C

Carl Frisk

First off a jpg is not really a good format to display a sample of anti-aliasing in as it is a lossy format. BMP would
be better as it is lossless. jpg will naturally introduce it's own distortions depending on the amount of compression
used.

Second if you are working with anti-aliasing make sure you turn off anti-aliasing and anisotropic filtering in your
video driver.
Remember it's the video driver that ultimately paints what you see on your screen. In this case you want to see exactly
what your application is doing, not what the video driver is doing for you. And I can't imagine any two users in the
universe having the same exact same video configuration. Unless that configuration of setting are likely to make your
application crash that is:) Then it seems as if the whole known universe stumbles upon them.

Once you get to a known base state come back and let us know what is happening. I will probably tinker around with this
some more tonight and I will let you know if I discover anything unusual.
 
B

Bob Powell [MVP]

Hello Brian.
The problem lies in the fact that you're filling a path in one instance and
a region in another. The path is a record of graphical elements designed to
enable you to store lines and shapes. The region is a collection of
rectangles that are primarily concerned with restricting pixel output to a
specific area of the drawing surface.

When paths are stroked or filled the objects used such as bushes or pens are
subject to the settings of the GDI surface. When a region is filled then the
system simply restricts output on a pixel by pixel basis according the othe
content of the region.

This effect is demonstrated in the following code.

protected override void OnPaint(PaintEventArgs e)
{

e.Graphics.SmoothingMode=SmoothingMode.AntiAlias;

GraphicsPath pth=new GraphicsPath();

pth.AddEllipse(10,10,300,200);

Region rgn=new Region(pth);

rgn.Transform(new Matrix(1,0,0,1,350,0));

e.Graphics.FillPath(Brushes.Black,pth);

e.Graphics.FillRegion(Brushes.Black,rgn);

rgn.Dispose();

pth.Dispose();

base.OnPaint (e);

}

If you want smoothing you will need to draw the paddles with a graphicspath
as opposed to a region.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
B

Brian Basquille

Cheers for that fellas!

Never even realised it after staring at that block of code for an half an
hour!!

Thanks again!

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top