After the QUItIndicator trilogy which introduced idea, design and performance of a specific Qt5 QML component there's room for more, right?! Something like this:
This time we have a dynamic QML component for showing the remaining power of your mobile device battery. As a recap, with "Dynamic QML component" I mean someting which utilizes not only basic QML animation properties (position, opacity, scale etc.) but also new Qt5 features (shaders, particles, scenegraph powa!) to appear "more dynamic". Maybe it's just me, but I would love to see UIs really utilizing modern GPUs... and accelerating this progress is one of the reasons why I code these examples and blog about them. Another reason being to rule-the-world, obviously ;-P
Instead of explaining design & features of QUItBattery component I'll let this video to do that:
If you want to use this liquid battery component in your UI: Download the sources from here, copy QUItBatteryComponent directory, import it in your QML and off you go. Happy hacking!
Planet maemo: category "feed:ffedab845b17ad5f072a1f90af70d0f9"
(This is part II, for the introduction see part I)
Few months ago I wrote a normal mapping series with part I and part II. That was a good experience, so series it is again! This time about implementing dynamic QML components, with an example case being busy&progress indicators. We'll call these specific ones QUItIndicators.
Let's start with obligatory video which demonstrates these components, BusyIndicator and ProgressIndicator, with few examples:
Traditionally indicators like these would be implemented as an animated GIF or a sprite. Cons of that approach are zero customization and memory consumption: 2s animation of 256x256px 32-bit color indicator at 60fps would mean 2*60*256*256*4 = 31.5Mb memory consumption. That's quite a bit for just one indicator, so usually frames are animated slower than 60fps which makes animation less smooth.
Alternative way to implement animated indicator would be using imperative drawing API (QPainter, Cairo, Skia etc.). Drawing freely to a canvas gives a lot of possibilities, but can easily lead to non-optimal performance. Many of these APIs have OpenGL backends which sounds good in theory, but the reality is that they can't take full gains out of modern GPUs. Like wise Tro^H^H^HDigians have said, combining QPainter with OpenGL backend doesn't make a perfect harmony.
So as you probably guessed, our indicators use Qt5+QML+GLSL instead. The pros of this approach compared to sprites or imperative drawing are rendering performance, low memory consumption and customization possibilities. There is also at least one con: Indicator needs to be designed so that required animations can be achieved with vertex & fragment shaders.
Next blog post goes through design thoughts behind these indicators. In the meantime, you can get the sources from here and try yourself!
Let's start with obligatory video which demonstrates these components, BusyIndicator and ProgressIndicator, with few examples:
Traditionally indicators like these would be implemented as an animated GIF or a sprite. Cons of that approach are zero customization and memory consumption: 2s animation of 256x256px 32-bit color indicator at 60fps would mean 2*60*256*256*4 = 31.5Mb memory consumption. That's quite a bit for just one indicator, so usually frames are animated slower than 60fps which makes animation less smooth.
Alternative way to implement animated indicator would be using imperative drawing API (QPainter, Cairo, Skia etc.). Drawing freely to a canvas gives a lot of possibilities, but can easily lead to non-optimal performance. Many of these APIs have OpenGL backends which sounds good in theory, but the reality is that they can't take full gains out of modern GPUs. Like wise Tro^H^H^HDigians have said, combining QPainter with OpenGL backend doesn't make a perfect harmony.
So as you probably guessed, our indicators use Qt5+QML+GLSL instead. The pros of this approach compared to sprites or imperative drawing are rendering performance, low memory consumption and customization possibilities. There is also at least one con: Indicator needs to be designed so that required animations can be achieved with vertex & fragment shaders.
Next blog post goes through design thoughts behind these indicators. In the meantime, you can get the sources from here and try yourself!
(This is part II of the normal mapping journey, check the part I first for details.)
So you have all now played with Qt5 NMapper tool, right? Goody, that means we have gained experience of normal mapping and created some perfectly tuned normal mapped textures. Now it's time to use these in a separate application.
Let's assume that you are working on a 2D QML application, but would want 3D-looking effect into some part(s) of the UI. To visualize, here's an example NMapCarousel demo application:
(Qt5 NMap Carousel, running on PC and on Raspberry Pi)
Here normal mapping is used to make the carousel icons more dynamic by applying lighting. To increase the 3D impression, there are also extra shadows reflected behind the icons.
To implement something similar, here's how to proceed:
Source codes of this demo are available from here. I'm waiting to see cool normal mapping uses!
PS: To learn shaders from the master, check out Andrew's thndl.com!
So you have all now played with Qt5 NMapper tool, right? Goody, that means we have gained experience of normal mapping and created some perfectly tuned normal mapped textures. Now it's time to use these in a separate application.
Let's assume that you are working on a 2D QML application, but would want 3D-looking effect into some part(s) of the UI. To visualize, here's an example NMapCarousel demo application:
(Qt5 NMap Carousel, running on PC and on Raspberry Pi)
Here normal mapping is used to make the carousel icons more dynamic by applying lighting. To increase the 3D impression, there are also extra shadows reflected behind the icons.
To implement something similar, here's how to proceed:
- If not already, setup Qt5 to your PC/Mac/RPi or equivalent platform.
- Create normal maps of your graphic assets using Gimp, Blender, Photoshop etc. tool of your choice. Name the normal mapped image with extra "n" in the end, so images are something like "thing.png" and "thingn.png".
- Test your graphics with NMapper by copying these images into "images" folder and adding "thing" into imageFiles array property. Play with the light intensity, diffuse, switching x&y coordinates etc. If you are not happy with the results, jump back to step 2 to edit the images and iterate.
- Make your own application. Copy NMapEffect.qml and NMapLightSource.qml from NMapper, use your freshly made images, the lighting settings you tested earlier and implement rest of the UI.
- Profit! (Sorry that this took a bit more steps than normally... but on the positive side there is no unknown ???-step in the middle!)
Source codes of this demo are available from here. I'm waiting to see cool normal mapping uses!
PS: To learn shaders from the master, check out Andrew's thndl.com!
This one has been on my "blog at some point" back burner for some time now...
'Normal mapping' is a graphics rendering technique used for faking the lighting conditions. In 3D software it is often used for bringing small bumps and dents of textures visible to achieve more realistic graphical appearance without using huge amount of polygons. Normal mapping is kinda advanced version of preceding 'Bump mapping' technique. Where bump mapping uses just one channel for 'bumps', normal mapping uses 3-channel (RGB) bitmaps and can therefore contain more detailed normal vector information.
Normal mapping technique can also be used in 2D applications to get 3D'ish looking UI elements, which means it can be used also in normal non-Qt3D QML applications. Combining image textures with specifically made normal map textures using a suitable shader is all you need. And normal maps can be automatically created with Gimp, Blender, Photoshop etc. drawing tools, although for best results some tweaking may be required.
But enough about theoretical mumbling, here comes visuals:
(Qt5 NMapper tool, running on PC and on Raspberry Pi)
To experiment with normal mapping I implemented a simple Qt5 NMapper application. As seen from video, it can be used to play with different graphical assets, change lighting conditions, switch normal map x&y-coordinates etc. It also includes the essential 'cave mode' for wiggly fire light.. ;-)
Download NMapper application from here and try it on PC/Mac/RPi or equivalent platform with Qt5.
After this brief intro I'll make a follow-up post within few days about example usage. Have a hacking weekend everyone!
'Normal mapping' is a graphics rendering technique used for faking the lighting conditions. In 3D software it is often used for bringing small bumps and dents of textures visible to achieve more realistic graphical appearance without using huge amount of polygons. Normal mapping is kinda advanced version of preceding 'Bump mapping' technique. Where bump mapping uses just one channel for 'bumps', normal mapping uses 3-channel (RGB) bitmaps and can therefore contain more detailed normal vector information.
Normal mapping technique can also be used in 2D applications to get 3D'ish looking UI elements, which means it can be used also in normal non-Qt3D QML applications. Combining image textures with specifically made normal map textures using a suitable shader is all you need. And normal maps can be automatically created with Gimp, Blender, Photoshop etc. drawing tools, although for best results some tweaking may be required.
But enough about theoretical mumbling, here comes visuals:
(Qt5 NMapper tool, running on PC and on Raspberry Pi)
To experiment with normal mapping I implemented a simple Qt5 NMapper application. As seen from video, it can be used to play with different graphical assets, change lighting conditions, switch normal map x&y-coordinates etc. It also includes the essential 'cave mode' for wiggly fire light.. ;-)
Download NMapper application from here and try it on PC/Mac/RPi or equivalent platform with Qt5.
After this brief intro I'll make a follow-up post within few days about example usage. Have a hacking weekend everyone!
I received a Raspberry Pi this week (thanks Nokia & QtonPi!) and naturally baked Qt5 into it as the first thing. Started by just installing premade RPi Qt5 package, but as qmlscene is not yet included, went for building Qt5 following loosely these instructions. About 2 hours later, I had system setup with latest Raspbian image running Qt5 QML apps.
Last month when Qt5 first beta was coming together I prepared this "Qt5 Cinematic Experience" technology demo and got some good feedback. Samuel Rødal (btw check out his awesome "Qt 5 based 3D Wayland compositor" video!) kindly tested that it works also in RPi. Yes, it worked and was pretty fast also, but not even close to perfect... Now armed with RPi I wanted to spend some quality time with it, experimenting what the GPU (Broadcom VideoCore IV) likes and hates. So here comes "Qt5 Cinematic Experience - Raspberry Pi Edition":
The changes made for this RPi version are:
Last month when Qt5 first beta was coming together I prepared this "Qt5 Cinematic Experience" technology demo and got some good feedback. Samuel Rødal (btw check out his awesome "Qt 5 based 3D Wayland compositor" video!) kindly tested that it works also in RPi. Yes, it worked and was pretty fast also, but not even close to perfect... Now armed with RPi I wanted to spend some quality time with it, experimenting what the GPU (Broadcom VideoCore IV) likes and hates. So here comes "Qt5 Cinematic Experience - Raspberry Pi Edition":
The changes made for this RPi version are:
- Original version was quite scalable, but it was optimized for ~N9 screen resolutions. I wanted to run RPi in full HD 1080p (1920x1080) so adjusted things to fit better for the larger screen, making everything bigger and better. Though more pixels means more work for CPU&GPU so..
- Added FPS item in the top-left corner which shows how frequently QML animation loop gets called. Seeing this all the time while developing gives good feedback on how different changes affect the performance and also adds some demonstration sugar.
- Reduced smoke particles amount & size as that was a clear bottleneck.
- Another slowdown was DropShadow effect for big movie title texts, switched it now to plain Text.Outline style.
- On the other hand, increased shooting star sprite and its particles sizes as these changes didn't notably decrease the performance.
- On the RPi side used 128/128 CPU/GPU memory split and to get even more juices out, overclocked it to "medium" 700MHz -> 900MHz (see instructions)
- Went for a more colorful theme by default, raspberries are bright!
During the past ~20 months I've made several blog posts about Qt5, QML Scene Graph, shaders and whatnot. As Qt5 beta is getting reeeeally close, I thought this would be a good time for a fresh Qt5 technology demo. This one is called 'Cinematic Experience' and looks a bit like this:
(best viewed in HD)
Cinematic Experience collects many of the new Qt5 QtQuick 2.0 features into the same UX demo application. It uses particles, sprites, path animation, custom shaders etc. features which Qt5 introduces for QML UIs. As usual, source codes are available from here.
Performance note: The GPU in N9 (SGX530, released Jul 2005) is showing its age. Especially fragment shaders need to be very conservative as the GPU just isn't powerful enough for the N9 screen resolution. To get the application perform in N9, some optimizations were required like disabling the normal-mapping lighting and reducing the amount of fog particles. As seen in the video, after these tweakings N9 can run the demo okeyish. Definitely far from velvet, but I would say it's more like butter ;P
PS. In case you own RPi, Beagleboard, Pandaboard, Snowball or any other embedded hardware running Qt5, please grab the demo and give it a go. I'm waiting for feedback and videos!
Howdy! Do you remember the time before HD, amoled etc. super sharp screens? When pixels were so big that you could easily count them and any colors were luxury? This is your ticket back to these good ol' times: LedScreen Qt5 & QtQuick 2.0 component! Here is a video presenting it with example applications:
This component allows you to use any QML content as the source for the ledscreen, define led size and color or use colors from the source item. So it doesn't contain kitchen sink yet, but there's only so much you can fit into 60 lines of QML + GLSL with API documentation.. ;-)
Feel free to grab sources from here & modify & use as you want!
PS: Hoping to be able to develop & demo Qt5 soon on Raspberry Pi!
Smoke the Bugs is now available to download from Nokia Store for Harmattan N9 and for Anna/Belle. No bugs (except software bugs!) were harmed while developing the game, but to know whether this virtual bug smoking is suitable for you, check this video of game play on N9:
As explained here earlier, this was partly an expedition on making a game with pure QML + JavaScript + shader effects. Plan was to make it totally without C++ (excluding the launcher which Qt SDK generates automatically) and to see what the outcome would be.
So summing up some random development notes here:
P.S. I joined Nokia ~month ago which may increase my bias towards Qt... But it's not like I wouldn't have made my opinion pretty clear already ;-)
As explained here earlier, this was partly an expedition on making a game with pure QML + JavaScript + shader effects. Plan was to make it totally without C++ (excluding the launcher which Qt SDK generates automatically) and to see what the outcome would be.
So summing up some random development notes here:
- Harmattan version of the game utilizes Qt-components for portrait main window and for disabling swipe while playing. Symbian version does not use Qt-components as pure QML was enough.
- It's good to use Loader for separating rest of the UI from initial "splash screen" for faster startup. Another option on Harmattan would be to show static splash screen image with invoker.
- In this game, loaders are also used for help and high score views. As these are not often used, it is better to save memory and only load them when needed. Loading is fast enough not to cause notable delay.
- ShaderEffectItem is available on Harmattan, Belle and Anna+Qt 4.7.4, so it's possible to target quite a many devices. Exception is Nokia 500 which is lacking GPU for OpenGL.
- With Symbian, setting QGLWidget for viewport is required to be able to use ShaderEffectItem. On Harmattan this is not needed as the default graphics system is already set to use OpenGL.
- When application is minimized, unload ShaderEffectItems or set their 'visible' property to false. Not doing this causes minimized application to use resources unnecessarily. Application state can be tracked with Qt.application.active
- When writing shaders, be careful to keep them performing well. Symbian devices and especially newer Belle ones can handle heavy fragment shaders better than N9. As an example, moving night effect math from fragment shader to vertex shader improved performance notably on N9.
- Avoid too many ShaderEffectItems to save resources. As an example, instead of each bug containing its own burning effect, there are three global effect items in a queue, positioned and animated when needed. If three simultaneously burning bugs are not enough, it's easy to add more effect items into queue.
- QML performance notes give good general guidelines what to avoid. Qt5 version of this document is even better and provides also information on how Qt5 scenegraph and V8 engine changes reflect to optimizing QML performance.
P.S. I joined Nokia ~month ago which may increase my bias towards Qt... But it's not like I wouldn't have made my opinion pretty clear already ;-)
Catchy title right? Don't worry, content partly matches to that description... ;)
It seems that I quite often include videos in my blog posts. There is no reason to stray away from that habit now, so here's a video showing a beta version of "Smoke the Bugs!" game on N950 & N8:
By looking at the graphics, effects, dynamic lights etc. what you saw was a pretty average OpenGL (ES 2.0) game, right? Well yes and no... Yes, GLSL shaders have been used for the effects. But no, there is zero lines of OpenGL and in fact also zero lines of C/C++ in the game. It's all QML + GLSL + JavaScript.
To work on current Harmattan & Symbian devices, game uses Qt 4.7 with the shaders plugin. This is an okay-ish platform, as you see from the video: N8@680MHz runs at smooth ~60fps. But I have also smelled, tasted and floated in the sweet velvet of Qt5 and can tell you as a fact that it will be much better. With Qt5 & QtQuick 2.0, applications will get a healthy boost of performance, smoothness and possibility for even better effects.
Here is a short list of improvements QtQuick-based games will gain from Qt5:
- Performance: QML Scene Graph will render everything faster than Qt4 QGraphicsView-based renderer, especially when the amount and complexity of (animated) items rises.
- Performance2: New V8 JavaScript engine performs much better than the JavaScriptCore engine in Qt4. Also thanks to this integration work, there is deeper co-operation between QML and JavaScript.
- Smoothness: Qt5 moves rendering into a separate thread which makes UI feel much smoother.
- Effects: QtQuick 2.0 supports shader effects to make QML UI's much more dynamic. Using shaders with Qt4 is possible with the shader plugin as shown above, but Qt5 native support will be more complete.
- Particles: QtQuick 1.0 contains particles plugin but it's very basic when compared to QtQuick 2.0 particles. No game can survive without particles!
- QML features: There are additions in QML which will suit games very well like SpriteImage for sprite animations and PathAnimation & PathInterpolator to animate along a custom path instead of linear path.
- QtCreator: Had to mention this one still as the work done in QtCreator Qt5 integration, QML debugger & analyzer etc. will improve the developer (that's me) productivity.
Now look at the video again to see what the old 2011 QML looked like, add all the above improvements to it and use your imagination... For me it feels like Qt5 & QtQuick 2.0 can offer a great platform not just for applications but also for games. Billion or two, I don't really care... ;) Happy New Year 2012 Everyone!
It seems that I quite often include videos in my blog posts. There is no reason to stray away from that habit now, so here's a video showing a beta version of "Smoke the Bugs!" game on N950 & N8:
By looking at the graphics, effects, dynamic lights etc. what you saw was a pretty average OpenGL (ES 2.0) game, right? Well yes and no... Yes, GLSL shaders have been used for the effects. But no, there is zero lines of OpenGL and in fact also zero lines of C/C++ in the game. It's all QML + GLSL + JavaScript.
To work on current Harmattan & Symbian devices, game uses Qt 4.7 with the shaders plugin. This is an okay-ish platform, as you see from the video: N8@680MHz runs at smooth ~60fps. But I have also smelled, tasted and floated in the sweet velvet of Qt5 and can tell you as a fact that it will be much better. With Qt5 & QtQuick 2.0, applications will get a healthy boost of performance, smoothness and possibility for even better effects.
Here is a short list of improvements QtQuick-based games will gain from Qt5:
- Performance: QML Scene Graph will render everything faster than Qt4 QGraphicsView-based renderer, especially when the amount and complexity of (animated) items rises.
- Performance2: New V8 JavaScript engine performs much better than the JavaScriptCore engine in Qt4. Also thanks to this integration work, there is deeper co-operation between QML and JavaScript.
- Smoothness: Qt5 moves rendering into a separate thread which makes UI feel much smoother.
- Effects: QtQuick 2.0 supports shader effects to make QML UI's much more dynamic. Using shaders with Qt4 is possible with the shader plugin as shown above, but Qt5 native support will be more complete.
- Particles: QtQuick 1.0 contains particles plugin but it's very basic when compared to QtQuick 2.0 particles. No game can survive without particles!
- QML features: There are additions in QML which will suit games very well like SpriteImage for sprite animations and PathAnimation & PathInterpolator to animate along a custom path instead of linear path.
- QtCreator: Had to mention this one still as the work done in QtCreator Qt5 integration, QML debugger & analyzer etc. will improve the developer (that's me) productivity.
Now look at the video again to see what the old 2011 QML looked like, add all the above improvements to it and use your imagination... For me it feels like Qt5 & QtQuick 2.0 can offer a great platform not just for applications but also for games. Billion or two, I don't really care... ;) Happy New Year 2012 Everyone!
Hey! Qt Developer Days '11 are over and I want to thank all organizers & attendees, what a great event again!!
For fresh owners of N9 (congratulations!), I'll say that 5inarow game is now available through Nokia Store. Here's how to get beaten by medium level:
Symbian version may follow later, but for now game is only available on N9/N950. It's free and contains no ads so if you feel like it, go grab it from here.
PS. If this tickles your "How to implement a Qt game like that?" or "I could do much better than that!" -nerves, source codes and Qt Quick Game Programming tutorial are still available from here. These are for the older N900 version, without e.g. sounds and computer AI. But an idea of updating the document for Qt5 & shader effects is floating in my mind, we'll see, we'll see...
For fresh owners of N9 (congratulations!), I'll say that 5inarow game is now available through Nokia Store. Here's how to get beaten by medium level:
Symbian version may follow later, but for now game is only available on N9/N950. It's free and contains no ads so if you feel like it, go grab it from here.
PS. If this tickles your "How to implement a Qt game like that?" or "I could do much better than that!" -nerves, source codes and Qt Quick Game Programming tutorial are still available from here. These are for the older N900 version, without e.g. sounds and computer AI. But an idea of updating the document for Qt5 & shader effects is floating in my mind, we'll see, we'll see...