# Antialiasing Bresenham Line

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

## Recommended Posts

Hey, I'm really pretty poor at graphics programming and am quite stuck with this. The tutor gave us a code snippet on how to full scene antialias the line, shown below:
void anti_alias()
{
glReadPixels(0, 0, viewport[2], viewport[3], GL_RGB, GL_FLOAT, buffer);

// process FSAA anti-aliasing here…

// draw anti-aliased pixels
glDrawPixels(viewport[2], viewport[3], GL_RGB, GL_FLOAT, buffer2 );
}

The line has already been drawn, and then this anti_alias() method is called. I know glReadPixels grabs the entire screen (which, incidentally, gives me a writing access violation when I try to do, so I have to lower the rectangle to about 100,100. Using an array 250,000 long just to store the buffer seems nonsensical), but I just don't know what exactly I'm supposed to do to all the pixels I'm supposed to get to antialias them before drawing them all to the screen again. Any help would be greatly appreciated :)

##### Share on other sites
Well, the buffer lenght depends on your resolution , a 800x600 res gives you a buffer with 480000 pixels.

Antialiasing after things have been rasterized is not possible, at least not "true" antialias. However you can blur the image a little bit (better if you do it only at edges), or you can downsample the image to half-size calculating the average of neighbor pixels to achieve an antialiasing effect.

I don´t know what your tutor is expecting you to do with these pixels but probably is something along the lines i mentioned. Search for "downsampling" or, if you have access to per pixel depth information, for "bilateral blur" and that should give you some info or even code.

##### Share on other sites
Heya,

"Full-scene anti-aliasing (FSAA) requires rendering the original image at a higher resolution than required. This larger image provides a number of samples for each pixel which can be averaged to provide a final value."

This is what he wants us to do, but I have no idea how to actually do that O_o

##### Share on other sites
Quote:
 Original post by Levante"Full-scene anti-aliasing (FSAA) requires rendering the original image at a higher resolution than required. This larger image provides a number of samples for each pixel which can be averaged to provide a final value."This is what he wants us to do, but I have no idea how to actually do that O_o

Typically, this is done by setting some flags when creating 3D device, the rest is up to GPU and driver.

But, if you want to render 400x400 image, you would instead render it at 1600x1600, then resample it down to target resolution using some filter, in worst case you'd just average the 4x4 areas of high resolution image.

##### Share on other sites
Quote:
 Original post by LevanteHeya,Thanks for the reply :)"Full-scene anti-aliasing (FSAA) requires rendering the original image at a higher resolution than required. This larger image provides a number of samples for each pixel which can be averaged to provide a final value."This is what he wants us to do, but I have no idea how to actually do that O_o

Ok, he wants you to go the downsampling way.

To do this, let´s assume the input pixel buffer has the scene rendered at twice the final resolution. So if it is 800x600 it will end up at 400x300. What you have to do is to loop trough all pixels, but skipping even pixels. That is, process, skip, process, skip...etc. Each time you encounter an odd pixel, you must do something with it, and there are several options on what you to do with them. The easiest one is to just copy it unaltered to the destination, this wont give you antialias, but will reduce the image size. More elaborated filters can be used, like computing the mean value of 4 neighboring pixels, for example, which will give you antialias and is easy to do.

Anyway, the key word you want to search for is "downsampling". There are many tutorials and papers out there, for example:

• 10
• 13
• 14
• 18
• 15