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.
Note: the snappers picture is from james_wicks, distributed under the Creative Commons Attribution 2.0 Generic.
12 Responses to “Underwater effect”
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 ![]()
@Giuseppe: Check it again, please. Thanks for noticing!
Builds fine here, but I get a
ASSERT: “img->size() != result1->size()” in file underwater.cpp, line 31
as soon as I run it
@Nikolaj: I just committed a couple more bug fixes, check it again. Thanks!
@ariya
Works like a charm now, thanks! ![]()
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.
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$
if you set change m_enableEffect->setChecked(true); to m_enableEffect->setChecked(false); then the app comes up on mac os x
andre
@Mocky, @Axel: should be fixed now. Try it again and many thanks!
I’m amazed at how little CPU this effect is using!
It would be very usefull to see how to implement a image effect using GPU (GLSL) and Qt !
> 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 ![]()
