# Thread: how can i fill a triangle?

1. ## how can i fill a triangle?

I want to fill with color a triangle?

2. Which graphics API are you using?

3. I want to fill with color a triangle?
I dunno, do you? Be sure to weigh the pros and cons first and make sure you really want to fill a triangle with colour.

EDIT: sorry, I couldn't resist.

4. For each x draw a line such that x -> T(x), :-D (imagine integrals). This could be a stupid answer, i mean I guess there's a better way to do it.

I do know OpenGL supports such functionality, just envoke the right properties or something, google.com.

If your triangle is at an angle you'd just find the slope and include it in to the calculation for x->T(x), where T(x) is each point of the triangle above what ever side you use as the base.

Like if you're using side A, then draw a line from every point at A to B->C, or just C/B if it's 90d triangle...

This is probably a really dumb idea since it would likely take a lot of calculations and there's probably low level API exposed in what your using to fill shapes.

Why didn't you just google what ever your using and look for documentation... ?

How on earth do you just say "i want to fill a triangle with a color." I can't read your freaking mind!!! What are you making triangles with? Noodles? Because if your using noodles, just pour the sauce in the gap.

Or if you made a triangle with plastic spoons, I'd probably use cardboard cut outs, make sure to get a variety pack of colored papers.

*sorry, -I- couldn't resist.*

5. quick OpenGL code
Code:
glColor3f(1.0, 1.0, 1.0);//fils triangle with white
glBegin(GL_TRIANGLES);
glVertex3f(-1.0, -1.0, 0.0);  //bottom left vertex
glVertex3f(0.0, 1.0, 0.0);  //top vertex
glVertex3f(1.0, -1.0, 0.0);  //bottom right vertex
glEnd();

6. Originally Posted by psychopath
I dunno, do you? Be sure to weigh the pros and cons first and make sure you really want to fill a triangle with colour.

EDIT: sorry, I couldn't resist.
I love it! I was thinking the same thing before I saw your post.

7. If you use GDI you can call CreatePolygonRgn() and FillRgn

8. Originally Posted by psychopath
I dunno, do you? Be sure to weigh the pros and cons first and make sure you really want to fill a triangle with colour.

EDIT: sorry, I couldn't resist.
I think you guys are not funny at all, despite how hard you're trying to.
Any idiot can see that he's looking for an efficient solution, and that the question mark was just a typo. If you knew a way, you didn't have to know his graphics library to explain it.
If you think you know a function call to do this, the only thing you would ask is: "What graphics API are you using". Period.
Question mark, actually.
But you seem to know none of these, so we don't need your comments at all.

9. Originally Posted by pronecracker
If you knew a way, you didn't have to know his graphics library to explain it.
Except if he's using GDI (presumably 2D), then there are, as you pointed out, functions that create 2D filled triangles. If he's using OpenGL or Direct3D, you don't fill a triangle with colour by colouring the pixels in the region like you generally do in a 2D library, you define a triangle with verticies and set the vertex colour. So yeah, I do need to know the graphics library.

In any case, it was a joke. It was also meant to (perhaps a little too sarcastically) point out to the OP that he gave basically no information for us to go by to help him. Lighten up.

EDIT:
Originally Posted by pronecracker
Any idiot can see that he's looking for an efficient solution
I don't see where he asked us how to effeciently fill a triangle.