# Scanline Rendering

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

## Recommended Posts

Hey, I have a project which involves drawing a cube without using any libraries. Instead, we are meant to use scan-line algorithm to draw the cube. However, I have no clue on where to begin coding. I have chosen to do it in c++ using MFC, as it's the only language where we have been taught on how to do graphics, besides XNA. Does anyone have any ideas on where to begin or any links so I can better understand the algorithm? Thanks in advance.

##### Share on other sites
There's something I find surprising, how did we all manage to do school work without internet. And all those before us without even having computers....

Eitherway, putting "scanline rendering" and "bresenham algorithm" into google will lead you to explanations. For implementation, anything that allows you to manipulate and display raster/bitmap images will work.

##### Share on other sites
are you expected to texture map/shade the cube in someway?

the general process of scan converting a polygon is based upon line drawing algorithms,
such as this one;

http://en.wikipedia.org/wiki/Bresenham's_line_algorithm

its worth studying this in more detail.

you're basically meant to find adjacent sides of a polygon and draw a horizontal line between those sides. you use the line algorithm to interpolate between the points of polygon at both sides.

##### Share on other sites
<Edit> below comments only apply if you scan convert all the polygons in one sweep (more computationally effecient in terms of the sort complexity). if instead you scan convert each face of the cube seperately it would be simpler.

You need to think about the fill rule used on the scanline - a binary in/out type fill (which can be used to render font outlines for instance) on consequtive segments wont work if the cube polygons edges are stitched together but all need to be filled. you need some adaption of a winding rule - in fact it seems a bit tricky if i understand the problem correctly.

Also I dont think sweepline/scan line algorithms are related to Bresenham line drawing.

[Edited by - chairthrower on March 22, 2008 4:14:44 PM]

##### Share on other sites
Quote:
 Original post by chairthrowerAlso I dont think sweepline/scan line algorithms are related to Bresenham line drawing.

After projecting the 3D object, you use bresenham's algorithm to break down the edges of resulting polygon to perform the scanline-fill, generally described here.

Sweep line algorithm is just a concept, that in above case is most trivially implemented in mentioned way.

##### Share on other sites
To add to the previous advice and you are using a wireframe display (lines representing the edges of the cube - maybe using Bresenhams algorithm, or even scanline filling the polygons which represent the faces of the cube) do a search on "windows device context", and if using MFC as you stated, then search on CDC which is the MFC class which encapsulates a windows device context. Also search on the CDC::SetPixel function for setting the pixels which represent the (scan)lines.

##### Share on other sites
Hey, Thanks all for the help, because Im really struggling on understanding how to code it, but more importantly, understand it. I'm gonna quote my Lecturer here on what is required.

"You need to render a static cube using the Normal-vector interpolation shading scan line rendering algorithm. Your implementation must include a specular highlight."

How the specular part is for another's day work, I have some formula's related to this which I have a fairly good understanding of (I just need to code it ;) ).

As for Bresenhams, I'm not sure whether we can use that either, I'll have to check with our lecturer. In fact at the moment, I have the cube drawn using Bresenhams just to ensure my translations and rotations are working. Although, that adaption of Bresenhams is interesting, and because I understand Bresenham, it shouldn't be too difficult for me to understand what's going on.

I'm gonna read into it and scanline a little more, and see if I can understand it better, as I don't feel I know enough to even form an outline of what I need to do. I'll post back when I feel I can explain what is involved, cause that's half the battle I guess :(

##### Share on other sites
Quote:
 Original post by Benzino"You need to render a static cube using the Normal-vector interpolation shading scan line rendering algorithm. Your implementation must include a specular highlight."

Ok, this somewhat changes the problem.

This would imply either Phong or Gourard shading, depending if your interpolation is per-pixel or per-scanline respectively. Look those up. The formula you refer to makes me believe it's Phong.

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
19
5. 5

• 14
• 26
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631771
• Total Posts
3002253
×