ariya
Qt
Graphics Dojo
Posted by ariya
 in Qt, Graphics Dojo
 on Sunday, July 13, 2008 @ 14:27

Distorting the geometry of an image with a specific periodic pattern can give the illusion of being underwater. This trick was for example employed in the very first version of Quake, either to oscillate the water surface or to modify the view when you jump inside the water. Apparently, it is not difficult to do that, even with pixel-per-pixel manipulation of QImage.

Check out the code from the usual place:

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

It is recommended to build the program and see the effect by yourself, the following screenshot can hardly describe the animation. As usual, once the example is running (it would show the included bridge picture), you can change the picture by dragging an image (from local disk or a web browser, e.g. Flickr or Picasa Web) and dropping it on the main window.

Qt for doing underwater effect

Note: the snappers picture is from james_wicks, distributed under the Creative Commons Attribution 2.0 Generic.

12 Responses to “Underwater effect”

» Posted by Giuseppe
 on Sunday, July 13, 2008 @ 15:58

Please, can you check the code on that repository? Revision 681 doesn’t compile:

underwater.cpp: In function ‘void applyUnderwater(const QImage*, QImage*, QImage*, int, qreal)’:
underwater.cpp:29: error: ‘result’ was not declared in this scope

thanks ;)

» Reply from ariya
 on Sunday, July 13, 2008 @ 18:33
ariya

@Giuseppe: Check it again, please. Thanks for noticing!

» Posted by Nikolaj Hald Nielsen
 on Sunday, July 13, 2008 @ 18:43

Builds fine here, but I get a

ASSERT: “img->size() != result1->size()” in file underwater.cpp, line 31

as soon as I run it

» Reply from ariya
 on Sunday, July 13, 2008 @ 20:01
ariya

@Nikolaj: I just committed a couple more bug fixes, check it again. Thanks!

» Posted by Nikolaj Hald Nielsen
 on Sunday, July 13, 2008 @ 20:48

@ariya

Works like a charm now, thanks! :-)

» Posted by Mocky
 on Sunday, July 13, 2008 @ 20:59

Now I get “ASSERT: “img->size() == result1->size()” in file underwater.cpp, line 36″ (Rev 683). Specifying the picture on the commandline does not help, either.
I commented out the widget.loadImage() in main. The widget shows but it still dies after dragging and dropping a picture into it with “ASSERT: “img->size() == result1->size()” in file underwater.cpp, line 36″.

If I comment out the Q_ASSERTS I only get “Bus error”.
I’m on OS X btw.

» Posted by Axel
 on Monday, July 14, 2008 @ 08:33

Same here on OSX:

surface:underwater axeljager$ underwater.app/Contents/MacOS/underwater
ASSERT: “img->size() == result1->size()” in file underwater.cpp, line 36
surface:underwater axeljager$

» Posted by andre
 on Monday, July 14, 2008 @ 08:52

if you set change m_enableEffect->setChecked(true); to m_enableEffect->setChecked(false); then the app comes up on mac os x

andre

» Reply from ariya
 on Monday, July 14, 2008 @ 12:03
ariya

@Mocky, @Axel: should be fixed now. Try it again and many thanks!

» Posted by David Johnson
 on Monday, July 14, 2008 @ 19:53

I’m amazed at how little CPU this effect is using!

» Posted by Hugo
 on Monday, July 14, 2008 @ 21:00

It would be very usefull to see how to implement a image effect using GPU (GLSL) and Qt !

» Posted by Giuseppe
 on Monday, July 14, 2008 @ 23:29

> It would be very usefull to see how to implement a image effect using GPU (GLSL) and Qt !

to read as: it would be very useful to have QtCoreImage :-)



© 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.