# Antialiasing Bresenham Line

This topic is 3372 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:

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634134
• Total Posts
3015750
×
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.31929194927215576, "perplexity": 1379.740288697865}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-04/segments/1547583879117.74/warc/CC-MAIN-20190123003356-20190123025356-00047.warc.gz"}