[Interest] Filling a 3-Color Triangle - A Better Way?

Josiah Bryan josiahbryan at gmail.com
Thu Jul 5 17:12:04 CEST 2012


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

-- 
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/d8f0d903/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MainWindow.cpp
Type: text/x-c++src
Size: 9925 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120705/d8f0d903/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sample.jpg
Type: image/jpeg
Size: 5314 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120705/d8f0d903/attachment.jpg>


More information about the Interest mailing list