how can i fill a triangle?

This is a discussion on how can i fill a triangle? within the Game Programming forums, part of the General Programming Boards category; I want to fill with color a triangle?...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    3

    how can i fill a triangle?

    I want to fill with color a triangle?

  2. #2
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Which graphics API are you using?
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  3. #3
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    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.
    Last edited by psychopath; 05-01-2007 at 06:03 AM.
    Memorial University of Newfoundland
    Computer Science

    Mac and OpenGL evangelist.

  4. #4
    Registered User
    Join Date
    Jul 2006
    Posts
    162
    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. #5
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    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. #6
    Registered User IdioticCreation's Avatar
    Join Date
    Nov 2006
    Location
    Lurking about
    Posts
    229
    Quote Originally Posted by psychopath View Post
    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. #7
    Registered User pronecracker's Avatar
    Join Date
    Oct 2006
    Location
    netherlands
    Posts
    158
    If you use GDI you can call CreatePolygonRgn() and FillRgn

  8. #8
    Registered User pronecracker's Avatar
    Join Date
    Oct 2006
    Location
    netherlands
    Posts
    158
    Quote Originally Posted by psychopath View Post
    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. #9
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    Quote 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:
    Quote 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.
    Last edited by psychopath; 06-04-2007 at 11:10 AM.
    Memorial University of Newfoundland
    Computer Science

    Mac and OpenGL evangelist.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recursive Triangle Function
    By w2look in forum C Programming
    Replies: 14
    Last Post: 11-13-2010, 01:31 PM
  2. Right Triangle Program
    By BSmith4740 in forum C# Programming
    Replies: 9
    Last Post: 02-26-2008, 11:24 PM
  3. Stupid Logic Problem Need Outside Viewpoint
    By RP319 in forum C++ Programming
    Replies: 5
    Last Post: 03-03-2005, 09:59 PM
  4. Replies: 3
    Last Post: 12-22-2004, 06:29 PM
  5. Just in case: "Odd" Triangle Challenge (for me)
    By BB18 in forum C Programming
    Replies: 3
    Last Post: 10-09-2004, 12:02 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21