ariya
Qt
Graphics Dojo
Posted by ariya
 in Qt, Graphics Dojo
 on Saturday, July 05, 2008 @ 19:48

Time for another fresh example for the Graphics Dojo. This time I present a small tool that does nothing but showing the famous HSV cylinder. To give some realism, subtle blurred reflection is also added but can be easily disabled. Manual full-scene anti-aliasing is provided by the usual multisampling approach. Everything is done using pure QImage per-pixel manipulation along with some tricks, no OpenGL (or even its GLSL) is involved.

HSV Pie

For the code, check it out using:

svn checkout svn://labs.trolltech.com/svn/graphics/dojo/hsvpie

Note that the tool is not optimized for speed (evidenced by lots of setPixel() calls) so there is definitely room for improvement. Some possible further enhancements left as exercises for the readers are interactivity (mouse dragging to change e.g. the depth of the pie) and threaded rendering (so that the application remains responsive, just adapt the Mandelbrot example).

Have some dojo-fun!

5 Responses to “Let there be color”

» Posted by Sebastian Werner
 on Monday, July 07, 2008 @ 21:16

You may be interested in this one. Fabian Jakobs has ported the whole thing to JavaScript using the Canvas element.

http://news.qooxdoo.org/let-there-be-color-in-the-browser

» Reply from ariya
 on Monday, July 07, 2008 @ 22:26
ariya

@Sebastian Werner: the HTML Canvas version looks really cool!

» Posted by Fabian Jakobs
 on Monday, July 07, 2008 @ 22:57

Thanks :-)

Take a look at the JavaScript code. You will be surprised how similar it is to your C++ version.

» Posted by anonymous coward
 on Tuesday, July 08, 2008 @ 23:10

Hm, I wonder why in line 211 of hsvpie.cpp we have:
class QImage createHsvPie(int radius, int depth, qreal ratio, qreal limit, qreal init)
{

}

instead of

QImage createHsvPie(int radius, int depth, qreal ratio, qreal limit, qreal init)
{

}

what is the keyword class is doing there and why does it compile without any errors?

» Posted by Daniel Albuschat
 on Wednesday, July 23, 2008 @ 12:23

The “class”-keyword in this context is used for in-place forward-declarations, but doesn’t quite make sense because we’re not using pointers here.
You can return previously unknown classes in two ways. The first is the usual forward-declaration:

class Return;

Return *returnSomething();

The other way is the in-place forward-declaration:

class Return *returnSomething();

By prefixing the “class”, Return does not need to be declared in this scope. It only needs to be declared when dereferencing the resulting pointer later.
When not using pointers or references, you can still use the “class”-prefix on return types and parameter types, but the class needs to be fully declared at this point.



© 2008 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.
All other trademarks are property of their respective owners.