Page 1 of 1

What's the best way to fill in a triangle?

Posted: Thu Nov 29, 2007 8:54 pm
by Mentat
I just figured out how to do it. My book was talking about rasterization of polygons. Though it does some complicated stuff with vectors and matricies. I didn't figure out how to do it the way the book said, but the chapter/section on culling did lead me to a question. Which in turn, led me to an idea of filling a triangle by sweeping a line. Unfortunately, my design only works if the 2nd point is to the left of the 3rd (By the nature of the For loops).

So are there better ways, and ways that don't leave holes at the edges?

And what is the deffinition of rasterization. The book says everything about rasterization except the definition. :roll:

Posted: Thu Nov 29, 2007 11:29 pm
by burger2227
You did not mention what programming language, but QBasic can use PAINT. It requires an enclosed shape of one border color only.

PAINT(x, y), fillcolor, bordercolor

You also have to place the PAINT coordinates x and y inside of the shape.

Ted

Posted: Fri Nov 30, 2007 12:00 am
by k7
I can't remember the proper syntax of PAINT, but I once did it with it by painting in the centre of the triangle:
PAINT(width/2, height/2), fillcolor, bordercolour.

Posted: Fri Nov 30, 2007 6:22 am
by nkk_kan
Rasterization or rasterisation is the task of taking an image described in a vector graphics format (shapes) and converting it into a raster image (pixels or dots) for output on a video display or printer.

and you should get good info on this too..

http://en.wikipedia.org/wiki/Rasterisation

because i think this is what you are looking for..

Posted: Fri Nov 30, 2007 6:54 am
by Mentat
I don't want to use paint due to the possibility of a sideways triangle (a line). I forgot to mention, these triangles are in 3D.

Posted: Fri Nov 30, 2007 9:21 am
by D.S
Relsoft's 3d tutorials talk about polygon filling (in the vector article). The math was a little over my head, but it probably wont be for you.

Also, one of his programs uses the PAINT statement to fill a 3d box. You can check that out too.

Posted: Fri Nov 30, 2007 7:58 pm
by Nodtveidt
Honestly? The best way to fill a triangle is to just use OpenGL. :D

Posted: Fri Nov 30, 2007 9:21 pm
by Mentat
Nodtveidt wrote:Honestly? The best way to fill a triangle is to just use OpenGL. :D
In FB?
I wouldn't be surprised if it could.

Posted: Sat Dec 01, 2007 7:58 am
by Nodtveidt
Oh, if you're using FB then you can just use OpenGL anyways. No point in reinventing the wheel.

Posted: Sat Dec 01, 2007 8:28 am
by Mentat
Nodtveidt wrote:Oh, if you're using FB then you can just use OpenGL anyways. No point in reinventing the wheel.
Ohhhhhhh. I thought OpenGL was just for C++.

Posted: Sun Dec 02, 2007 6:26 am
by Codemss
Well, I thibk it has something to do with interpolation and flat bottom and flat top triangles. Check out this article:

http://www.petesqbsite.com/sections/tut ... apter3.htm

If you scroll a bit down, to: 'III. Different Polygon fillers', there is MUCH info on how to make polygon fillers. Solid, but also with interpolating colours, and even environment mapped polygons.

Also look on Petesqbsite > tutorials > Graphics, then look at some of the 3d series (the link I sended you is that from Relsoft).

Posted: Thu Dec 06, 2007 10:47 pm
by Nodtveidt
Mentat wrote:Ohhhhhhh. I thought OpenGL was just for C++.
Hehe, of course not. The headers use procedural prototypes anyways, so any compiler that can link the libraries and pass arguments using the correct convention can use OpenGL. Hell, I use OpenGL on the Nintendo DS. :D