[Interest] Filling a 3-Color Triangle - A Better Way?
Josiah Bryan
josiahbryan at gmail.com
Thu Jul 5 19:01:46 CEST 2012
On Thu, Jul 5, 2012 at 12:39 PM, Christoph Feck <christoph at maxiom.de> wrote:
> On Thursday 05 July 2012 17:12:04 Josiah Bryan wrote:
> > Hello, All!
> >
> > I have a particular need to fill a triangle (heck, I'll take a poly
> > if I could get it, but triangles are simpler to code) with a
> > different color at each vertex. However, since I can't use OpenGL
> > on my target device, I must use vanilla Qt. After much googling,
> > I found a routine in delphi (
> > http://www.swissdelphicenter.ch/en/showcode.php?id=1780) that I
> > translated to Qt/C++ (see attached file - MainWindow.cpp - should
> > compile and run just fine as is, just throw in a folder, qmake
> > -project && qmake && make then run it.)
> >
> > A sample of what the rendered triangle looks like is also attached
> > - "sample.jpg"
> >
> > The new routine, fillTriColor(), works fine quality-wise - but
> > performance is abysmal at best - almost 4 sec for 1K triangles on
> > a dual-core 3 GHz processor! Crikey. I also tried adapting the
> > routine to use a QLinearGradient to fill each scanline (instead of
> > iterating over each column and filling the pixels directly - code
> > is present in MainWindowp.cpp but commented out) - but that
> > ballooned the time it took for 1K triangles to almost *7 seconds*
> > - crikey!
> >
> > So, my Qt friends, is there a better way to fill a triangle with a
> > color specified for each vertex, interpolated across the triangle?
> > Some method that takes *less* than 4 milliseconds *per triangle*?
> > Did I just miss something in the Qt gradient routines that would
> > do this quite easily? Any ideas?
> >
> > Thanks so much!
> > -Josiah
>
> Here http://paste.kde.org/513062/ is some example code to fill a four-
> corner gradient quad, based on the idea described here
> http://kdepepo.wordpress.com/2010/05/03/accelerating-color-gradients/
>
> Unfortunately, due to the perspective transform it won't work for
> triangles...
>
Thanks, Christoph - that is an amazing trick! I just read the article with
my jaw dropped - nicely done! Even though I don't think this will work for
my particular application, I'll definitely tuck this little nugget of code
away in my list of "gems" to use later.
Thanks again!
--
Josiah Bryan
765-215-0511
josiahbryan at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120705/7d89f2f8/attachment.html>
More information about the Interest
mailing list