Sunday 19 August 2012

Intel Ultimate Coder Challenge - Part Two



The Story So Far

For the benefit of those joining us, you are reading the second instalment of a six part blog which tracks the antics of a developer hoping to win a $10,000 prize by creating a Windows 8 Metro app from scratch to take full advantage of a technology-packed Ultrabook. Last time I introduced myself and the technology I would be using, leaving details about the app itself cloaked in mystery.

So What Exactly Is The App?

The Love Hearts® app makes it possible to quickly create media messages on your Ultrabook and send them to your friends on Facebook, Twitter, Email and App-To-App.

A Love Hearts Sweet
The message can be tailored to include text, camera, photo album images and even your own doodles using the built-in art tool. The app then builds the message as a single image and sends it to your friend. If you send it to a friend who has the Ultrabook app installed, their device will notify them that they have a message and will present that message when they open their Ultrabook.

The App-to-App is an opportunity to experiment with a special feature of the Ultrabook called Always On Notifications. The idea is that when you close your Ultrabook, the app runs in low-power mode, and if someone sends you a new Love Hearts message, the Ultrabook will 'ping' you, even when closed. You can then open it up, and see the message running in the app.

Send messages any way you like

In addition, the app has a collection of daily surprises. For each day you own this free app, you are awarded a ‘surprise sweet’ which when tapped will open up to reveal what it contains. If you don’t like the wrapping, you can swipe it away and look at another one. When you see the one you like, you simply tap to unwrap.

Some of the actual Love Hearts(r) sweets

The surprise can be any number of things, from simple games, to pieces of puzzle that you can later assemble, or additional gadgets and tools to improve the messages you can send. Messages sent direct to another Ultrabook will additionally include music, sound and animation effects, all to make that message that little bit more special.  And to show you really care, you can include a sweet you have already unlocked in your message, which might be a game you quite like, or a vital piece of your friends puzzle.

So how does it make money?

No app is complete without a monetisation strategy, and no developer is complete without a freezer full of pizzas.


If you don’t wish to wait and prefer to unlock more than one sweet per day, you can buy ‘Love Credit’ top-ups, allowing you to unlock as many sweets as you like. I am toying with the idea that the daily credit is cumulative to encourage repeat usage. How to make your app pay is a little bit like alchemy, knowledge only takes you so far.


So What Will Make It an Ultrabook App?

It’s a great question and one that I will be wrestling with for the next few weeks. From using the Ultrabook over the last few days, I have gained a sense of what it does well and how it wants to deliver an app experience. Selecting tiles gracefully unfolds the app for you. Switching between Desktop and the Start page is slick and untroubled. I’m not left waiting for anything, and after an hour of playing I knew where everything was.

The new Windows 8 start screen

My gut feel is that the app should be an extension of this experience. I should be able to operate the app entirely from the touch screen, swiping and touching my way through every feature. If my keyboard fell off tomorrow, my app should carry on regardless. In practise, the full range of the accelerometer can only be enjoyed by putting the Ultrabook on my lap, but I have noticed the Z axis works great when I lift the keyboard up from the front, something I would never have thought without playing with the device itself.  As I continue using the Ultrabook, I am sure more insights will emerge, and I am keen to see how pre-installed apps are making use of other sensors like gyroscope and ambience.

And What Does It Do Right Now?

In anticipation of this question, I asked our tomb raiding, whip cracking coder Steve to knock up a version that I could demonstrate. Please excuse everything you see right now, and try to see past the app to a much better app buried deep within.

To protect ourselves from law suits, and to avoid strange looks in cafĂ©’s, we've decided to remove the requirement to pick-up and shake your Ultrabook. Instead, we’ve added a much nicer swipe gesture. In 3D, this will completely spin the packet in the direction and speed of your gesture so you get a real tactile experience right from the get-go. Your reward is a lovely wrapped sweet. The first one is by way of a tutorial and you are asked to ‘tap to unwrap it’. This will open the sweet and it gets added to your collection which is displayed at the top of the screen.

Sweets you own appear at the top

The tutorial continues into this freshly unlocked feature; a tool for designing and sending custom messages.

Have fun creating a custom message

As you can see, you can make some crazy media messages very quickly and with a single touch, the app sends it to your friend. A friends list will be added in a week or so.

Back in the main screen, you are free of the initial tutorial and you can use the app as normal. Swiping the packet will again spin the 3D model and a new sweet will fall out and float to the foreground. The sweet is supposed to be wrapped so you don’t see what’s inside. If you don’t like the shape, colour or style of the wrapping, you can swipe to fling the sweet away and it will curl its way back into the packet, and the packet will obligingly push out another sweet.  It just so happens in this demo the next ‘wrapped’ sweet looks fine so I tap to open and it gets added to my collection. I now have access to this sweet any time I like, and tapping this one reveals a game menu, with the game I discovered highlighted as available. In this demo, I can also play a bare bones version of this side scrolling game of skill.

An early screen shot of the game 'Wings Of Love'

Returning to the main screen, I can continue to swipe and spin the packet, and each time I do I am spending those most precious Love Credits. When I run out, I cannot have any more spins. The good news is that everything I unlocked I keep, so whether it’s playing the game again for a better score or sending an amusing message to a loved one, the app will be there for you. Better than that, each day you visit you get a free spin and a surprise to brighten up your day. For a complete list of surprises we have in store for you, you’ll have to play the app to find out!

Starting With Windows 8

Hopefully no-one has trademarked the word WINRT by the time this blog goes out, and I can explain what it is and how to use it before someone changes the name.  Before I can present my app in all its glory, I first need to get to grips with the new programming paradigm of Windows 8. That is, try to get “Hello World” running on my Ultrabook.

Windows 8 boot time is very quick

Writing an app from scratch using the templates provided by Visual Studio Express 2012 is simply a matter of studying how they work, and tweaking enough bits until you’ve got your own program. Trying to port a years’ worth of Win32 C++ engine code and squeezing it into the template is going to be trickier.  Step one is selecting the right template to start from.

New Project:Visual C++:Windows Metro style:Direct3D App

I recommend starting with the Direct3DApp project, NOT the Blank App (XAML). Chose XAML, and by the time you’ve got through the layers of helpful abstraction, it will be time for you to retire! I am an old school coder which means I need a main(), a loop() and an exit(), preferably in the same function!

Direct3D Application Template from VS Express 2012

You can compile and run this 3D demo and see a lovely spinning 3D cube, but the good stuff is the framework in which all that confusing 3D code sits. Look at the bottom of the “Direct3DApp1.cpp”, and you will find main().  Place a breakpoint there, run the demo and step into the functions and you will find yourself a few lines up in the Run() function which creates a timer and establishes a main loop, where it will sit happily until the window is closed. Pop in some clean-up code after the loop and presto, you have the makings of a no-frills, super-fast Windows 8 application.

It is this stripped down template that I will be using as the basis of my Ultrabook application. I have added it to a newly created FTP Area we can use to share files and demos in the coming weeks:

WEBSITE: http://partners.thegamecreators.com/
USERNAME: ultimatecoder
PASSWORD: ultimatecoder

FILE: Direct3DApp1.zip

Veteran coders who report to a higher power may wonder why I have just thrown away all the bits that actually do something and produced an app that does absolutely nothing. The more observant will go one step further and ask, “where does it say Hello World?”.

Essentially, I need to start from scratch to make room for my own C++ engine code. In theory, I should be able to drop it in, add some dependencies, click compile and go for an early lunch.

Researching Win32 vs. Metro Style

Before I commit to what in reality is a few days of work, I need to make certain of some basic requirements. Can I use standard C includes such as <stdio.h>, <malloc.h>.  Secondly, can I use <gl\gl.h> to access my precious OpenGL calls?  Already, I can feel the hairs on the back of my neck bristle. Is it me, or is that the sound of a thousand DirectX programmers laughing at me, surely not?

Two hours later, I arrived at the conclusion everyone reading this blog made right away and confirmed by a thousand DirectX programmers. A metro-style app is unable to include the OpenGL headers, and they are strictly for Desktop apps only. I can’t even ‘trick’ a Metro style app to render an OpenGL context. Even hacked, the metro style app would not be a valid app within the Metro style store as it would break the second it hit a device that did not have those legacy Desktop APIs. So that’s it friends, its metro style with no AGK graphics or desktop style with no access to WinRT. At least that’s what I thought. During my research hope was restored by an article published recently by Intel which goes into great length on how to access WinRT sensors from a Windows 8 Desktop app. When you have a few hours to spare, check out the article: http://software.intel.com/en-us/articles/ultrabook-and-tablet-windows-8-sensors-development-guide/



The limited WinRT desktop solution has enough COM code to put hairs on your chest, but it gets the job done and it will integrate instantly into my existing Win32 engine. I don’t even need to use VS2012 or learn what those ‘ref’ and ‘^’ symbols do, I can have sensors plugged in within the day.

Developer Dilemma

A question occurs. Is that the kind of thing the Ultimate Coder would do? Pick the easiest solution, slap in some cut and paste COM code then go for a little lie down somewhere. Fob off the judges with a desktop mode application that isn’t a real metro style app? I don’t think so.


The universe has put me in this challenge, and has just turned the heat up to see if I explode. I’ve looked at it from every angle, and there is only one way through. Write my own OpenGL library in DirectX 11.

Maybe not all of it, but enough bits that my AGK OpenGL routines compile normally, behave exactly as they would running under OpenGL but driven by DirectX.  As luck would have it, a few months ago we started updating our fixed function OpenGL ES 1.1 code to use OpenGL ES 2.0 shaders in anticipation of adding 3D commands to AGK. It further transpires that DirectX 11 likes shaders too. It transpires yet further that a few years ago I created a product called FPS Creator X10. Its claim to fame was a tech demo, one of the first third party demos to exploit the DirectX 10 graphics API.

From further research, it gets worse! Not only do metro style apps limit developers to DirectX, they also remove certain other liberties such as relative paths, unlimited system access and a blanket eviction of anything that might remind it of Win32. AGK is a full programming language, which means I’ll have to replace file, input and device code. The only things I think I can keep are physics, core logic and higher level graphics commands.

Don’t think me crazy though; there is method behind the mission to cure metro style apps of their clear lack of Win32 and OpenGL. Once complete, AGK programs will be able to run as genuine metro style apps, which means they will run on Windows tablets, and possibly Windows phones and consoles in the future.

I invite you to check back next week to see whether (a) I have achieved a small measure of success or (b) gone completely loco.

The AGK Advantage

You might be wondering how I can be demonstrating a running Love Hearts® app and at the same time agonise over how to render even one pixel to the Ultrabook. The good news for me is that AGK, the programming language we are using to run the BASIC script, already runs fine on Windows and several other platforms.  This means Steve, my back-up coder, can busy himself developing on Windows 7 while I set about making AGK work well with Windows 8. The magic happens in the next few weeks when I take the BASIC script that Steve has produced and drop it onto the new Ultrabook platform.


In addition, AGK has touch and sensor commands for many other platforms, so Steve will be able to add multi-touch and accelerometer functionality in his BASIC program long before I figure out how to do it on the Ultrabook.

What’s Next?

Are you kidding! Next week we will find out whether I can pull off even half of what I’ve just blogged. Steve is taking a short holiday, and I’ll be taking the opportunity to change all his code around and start the process of commissioning the artwork, so we might have some nice graphics to show. The real reveal will be a demo showing OpenGL calls that render to a metro style app context using DirectX as the underlying API. I’ve done some Googling, and there is not much on the subject, so it should be a good read!

More Information

For more information about the Ultimate Challenge, check out the official website at:http://software.intel.com/sites/campaigns/ultimatecoder/

Blog Videos

For everyone who likes videos, I have created two. One features the latest version of the Love Hearts® app, and a second takes a quick peek at my shiny new Ultrabook.  Until next time, have an app-y day!


No comments:

Post a Comment