Re: Draw & fill regular polygon?
Jacobo RĂos <[email protected]> Wed, 10 Aug 2011 10:15:21 -0500
| Newsgroups | gmane.games.devel.algorithms |
|---|---|
| Message-ID | <CALF1PQJf5WRw3RthvYO66EeL=NQ_XO0LmuRs6W1iXW=cx8VYhA@mail.gmail.com> |
Hi Joel, Maybe what you're looking for is something like this: http://www.dpfiles.com/dpfileswiki/index.php?title=Tricks_of_the_Windows_Game_Programming_Gurus%2C_Chapter_8:_Vector_Rasterization_and_2D_Transformations#Solid_Filled_Polygons it's from an old book of Andre LaMothe, in this chapter he described how to rasterize poligons with just a pointer to vram. check it out. hope it's usefull. ;) *"It's not that I'm insane, it just happens that I'm very creative with my own sanity"* On Wed, Aug 10, 2011 at 8:21 AM, Richard Fabian <[email protected]> wrote: > On 10 August 2011 12:49, Joel B <[email protected]> wrote: > > I should know how to do this, but i don't. I only have the ability in my > system to draw lines (x1,y1,x2,y2)' to a bitmap, or write to the bitmap as a > byte array. Can someone tell me the stepwise procedure to draw a polygon of > n sides and then fill it? Having trouble finding anything online that > doesn't use pre-existing primitives or libraries. > > > > Thanks, > > > > Joel > > if you already have a line drawing function, then use the code from > that to update a pair of arrays of min/max on the x axis: > > int xmin[SCREEN_HEIGHT] = { SCREEN_WIDTH... } > int xmax[SCREEN_HEIGHT] = { -1... } > > then for each step of your line drawing function update the min/max: > > replace your: put_pixel(x,y,colour) > with: xmin[y] = min(x,xmin[y]); xmax[y] = max(x,xmax[y]); > > Once you have the arrays, it's a simple case of iterating over them > and rendering all pixels between the min and max where the difference > is positive. > > foreach y in SCREEN_HEIGHT: > if( xmax[y] > xmin[y] ) > foreach( x in range( xmin[y], xmax[y] ): > put_pixel( x,y, colour ) > > and you have an untextured triangle. > if you want it textured, don't forget to store only UV values when the > max/min is updated. > > -- > fabs(); > Just because the world is full of people that think just like you, > doesn't mean the other ones can't be right. > > > ------------------------------------------------------------------------------ > uberSVN's rich system and user administration capabilities and model > configuration take the hassle out of deploying and managing Subversion and > the tools developers use with it. Learn more about uberSVN and get a free > download at: http://p.sf.net/sfu/wandisco-dev2dev > _______________________________________________ > GDAlgorithms-list mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list > ------------------------------------------------------------------------------ uberSVN's rich system and user administration capabilities and model configuration take the hassle out of deploying and managing Subversion and the tools developers use with it. Learn more about uberSVN and get a free download at: http://p.sf.net/sfu/wandisco-dev2dev _______________________________________________ GDAlgorithms-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list Archives: http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list