Misadventures in Direct2D

Another CRT pixel shader example (also not my screenshot)

Another CRT pixel shader example (also not my screenshot)

This post is the third in a series (see the previous posts Unnatural constraints, or my first 18 byte computer program and Adventures in Direct2D) chronicling my project to write an 8-bit virtual machine.  I’m currently working on rendering the screen using the GPU and using a pixel shader to make it look like a CRT.

This has been a frustrating week – the SharpDX Windows 8 Direct2D sample code seemed to have no relation to what I had working in Windows 7.  It turned out that the recommended way of doing things had changed between Direct2D v1 and v1.1 and instead of using a HwndRenderTarget I needed to use a device context and a DXGI swap chain – which supports Effects including pixel shaders.

Unfortunately this involves jumping through a LOT of hoops, some of them flaming.

This is actually all there in the SharpDX Windows 8 samples, but it’s spread over several classes in the common folder, which is why I couldn’t understand it.  I’m sure arranging the code this way makes perfect sense when creating a suite of samples, but it’s extremely inconvenient when trying to learn this as a noob.

Considering Direct2D was supposed to make accelerated 2D easy, this is a real mess – every stage of the process seems to include dealing with a Direct3D, DXGI and Direct2D version of everything linked together in byzantine ways.

My plan was:

  1. Get it to render using a swap chain
  2. Get it to apply a built-in Effect
  3. Get it to apply a custom pixel shader
  4. Get it to apply a CRT pixel shader

Unfortunately having got as far as initializing the swap chain I ran into a brick wall trying to convert the rendering code from HwndRenderTarget to swap chain.  I haven’t found any examples that are similar enough to what I want to do, and I don’t understand it well enough to just work it out on my own.  It’s really just loading a bitmap containing sprites, drawing the sprites onto a temporary bitmap and then drawing the temporary bitmap to the screen – I’m sure it’s perfectly possible, I just don’t know how.

Just when I’d fully committed to the swap chain method (and ground to a halt), someone mentioned that it was possible to use pixel shaders with HwndRenderTarget.  So now I’m not sure which avenue to pursue, but in either case I’m at a standstill.  The HwndRenderTarget method is a lot simpler and I understand it better, so if I can work out how to apply a pixel shader to it that might be the simplest solution.  The down side is that the HwndRenderTarget method doesn’t have vsync built into it like the swap chain does.

I guess over the course of the next week I’ll do my best to do research and get one of the methods working…

Enhanced by Zemanta

Book Review – Gun, with Occasional Music by Jonathan Lethem

Gun, with Occasional Music by Jonathan Lethem

Gun, with Occasional Music by Jonathan Lethem

The blurb says:

Gumshoe Conrad Metcalf has problems-there’s a rabbit in his waiting room and a trigger-happy kangaroo on his tail. Near-future Oakland is a brave new world where evolved animals are members of society, the police monitor citizens by their karma levels, and mind-numbing drugs such as Forgettol and Acceptol are all the rage.

Metcalf has been shadowing Celeste, the wife of an affluent doctor. Perhaps he’s falling a little in love with her at the same time. When the doctor turns up dead, our amiable investigator finds himself caught in a crossfire between the boys from the Inquisitor’s Office and gangsters who operate out of the back room of a bar called the Fickle Muse.

Mixing elements of sci-fi, noir, and mystery, this clever first novel from the author of Motherless Brooklyn is a wry, funny, and satiric look at all that the future may hold.

My favorite genres are Sci-Fi and Noir, so a combination of the two is like candy to me.  There aren’t that many books that combine the two genres – Altered CarbonLow TownThe City & The City, and Equations of Life are the only ones that come to mind.

The Sci-Fi aspects don’t really seem necessary through most of the book, although by the end a few of them are integral to the plot.

Noir is retro and Sci-Fi is futuristic, so the author has ended up with a retro-futuristic world – uplifted animals and phone booths at the same time.  It actually works pretty well, although it’s pretty surreal at times.

The Kindle edition of this book unfortunately had a lot of OCR errors, but I guess since the book was originally published in 1994 it’s possible that the original manuscript wasn’t digital.  I guess that might explain some of the retro as well.  In any case it could use a pass from a human being to clean up the obvious mistakes.

I found the main character’s relationship with women to be strange.  In one case a woman comes on to him and he hits her – I would think it was completely bizarre except that I remember something similar happening in The Maltese Falcon so maybe the author was trying to emulate Dashiell Hammett.

The ending is fine, except that the main character doesn’t really bring us along with his train of thought as he solves the case – it’s a set of confusing clues and then he presents you with the answer.  I didn’t feel like I had a chance to solve it along with him.

Enhanced by Zemanta

Book Review – Sun of Suns by Karl Schroeder

Sun of Suns by Karl Schroeder

Sun of Suns by Karl Schroeder

The blurb explains:

It is the distant future. The world known as Virga is a fullerene balloon three thousand kilometers in diameter, filled with air, water, and aimlessly floating chunks of rock. The humans who live in this vast environment must build their own fusion suns and “towns” that are in the shape of enormous wood and rope wheels that are spun for gravity.

Young, fit, bitter, and friendless, Hayden Griffin is a very dangerous man. He’s come to the city of Rush in the nation of Slipstream with one thing in mind: to take murderous revenge for the deaths of his parents six years ago. His target is Admiral Chaison Fanning, head of the fleet of Slipstream, which conquered Hayden’s nation of Aerie years ago. And the fact that Hayden’s spent his adolescence living with pirates doesn’t bode well for Fanning’s chances…

You can probably guess from the blurb that there’s some pretty cool world building in this book.  It comes right out with an extreme concept and runs with it – that’s the good part.

The bad part is that it feels like everything else took a back seat because of that.  Specifically, the characterization is weak in places (people do things that people wouldn’t do) and some plot elements seem to come out of nowhere.

The ending was also unsatisfying – there were a lot of cliffhangers and unfinished business in an obvious opening to a series.  I haven’t decided if I’ll pursue it or not.

Book Review – A Dance of Cloaks by David Dalglish

A Dance of Cloaks by David Dalglish

A Dance of Cloaks by David Dalglish

Quoth the blurb:

“I cut off his hand, yet he thanks me for not doing worse. That is the power you must one day command. Let them think every breath of theirs is a gift, not from the gods, but from you.”

Thren Felhorn is the greatest assassin of his time. Marshalling the thieves’ guilds under his control, he declares war against the Trifect, an allegiance of wealthy and powerful nobles. His son, Aaron, has been groomed since birth to be his heir. Sent to kill the daughter of a priest, Aaron instead risks his own life to protect her from the wrath of his guild. In doing so, he glimpses a world beyond poison, daggers, and the iron control of his father.

I’ve read a few books with similar plots recently (The Farseer Trilogy, The Gentleman Bastard Sequence, The Night Angel Trilogy) so I get the impression that modern fantasy writers are a bit obsessed with assassins, thieves guilds and coming-of-age stories.

This book is reasonably well written, but through what I assume are failures of editing there’s a lot of clumsiness.  I’d put it in last place compared to the other similar books I’ve read.

I didn’t find out until after I’d read it that this book (and the rest of The Shadowdance Trilogy) is a prequel to the author’s The Half-Orcs series, focusing on the back story of one of the characters.  Finding this out explained some of the clumsiness to me.

Book Review – The Winds of Khalakovo by Bradley P. Beaulieu

The Winds of Khalakovo by Bradley P. Beaulieu

The Winds of Khalakovo by Bradley P. Beaulieu

Here comes the blurb:

Among inhospitable and unforgiving seas stands Khalakovo, a mountainous archipelago of seven islands, its prominent eyrie stretching a thousand feet into the sky. Serviced by windships bearing goods and dignitaries, Khalakovo’s eyrie stands at the crossroads of world trade. But all is not well in Khalakovo. Conflict has erupted between the ruling Landed, the indigenous Aramahn, and the fanatical Maharraht, and a wasting disease has grown rampant over the past decade. Now, Khalakovo is to play host to the Nine Dukes, a meeting which will weigh heavily upon Khalakovo’s future.

When an elemental spirit attacks an incoming windship, murdering the Grand Duke and his retinue, Prince Nikandr, heir to the scepter of Khalakovo, is tasked with finding the child prodigy believed to be behind the summoning. However, Nikandr discovers that the boy is an autistic savant who may hold the key to lifting the blight that has been sweeping the islands. Can the Dukes, thirsty for revenge, be held at bay? Can Khalakovo be saved? The elusive answer drifts upon the Winds of Khalakovo…

The concept of flying ships, as demonstrated by the cover art is great.  Unfortunately it’s also the best part of the book.

The world building is strange – a combination of Russian, Arab and something like Buddhism.  It doesn’t really mesh well.

There are also inconsistencies and unevenness – things that are important in the beginning of the book are barely mentioned at the end.

It didn’t hook me enough to read the rest of the series.

Enhanced by Zemanta

Adventures in Direct2D

CRT pixel shader example (not my screenshot)

CRT pixel shader example (not my screenshot)

This post is a follow-on from a previous post about a project I’m working on to write an 8-bit virtual machine.

I got the VM using Direct2D last week so that some of the VPU could be offloaded to the GPU of the host computer.   In case you’re not aware, Direct2D is part of recent versions of DirectX, which is why it performs better than GDI.  As you can tell by the name it’s 2D, but that’s all I need for my VM.

In spite of the fact that .NET is a Microsoft product, it gets left out in the cold a lot by them.  I assume this is because most of Microsoft’s developers still use C++, so products like Office and Visual Studio (ironically) are still written in C++.  As a consequence, DirectX has always been available in C++ and either unavailable or poorly supported in .NET.  I understand that for games (where performance is paramount) it would be important to use a language built for speed, but you would expect Microsoft to be the foremost advocate of .NET’s performance.

In the past the way to use DirectX in .NET was XNA, but Microsoft abandoned it shortly after finally adding VB.NET support.  The impression is that XNA was for use by hobbyists and indie developers, neither of which made Microsoft enough money to justify supporting it.

The current way to use DirectX in .NET is the Windows API Code Pack.  Like XNA before it, it only supports C# , however that isn’t an insurmountable problem when developing in VB.NET because the binaries work and the examples are translatable.

Having got my VM to use the Windows API Code Pack, the next step was to add a pixel shader to get a CRT effect.  I really liked some pixel shaders that people had created for SNES emulators.

Unfortunately it turns out that Direct2D v1 doesn’t support pixel shaders, but they were added in Direct2D v1.1 in Windows 8.  Fortunately Microsoft ported some of the functionality of v1.1 back to Windows 7 in a platform update which is included with Internet Explorer 10 for Windows 7.

The problem then was that the Windows API Code Pack hadn’t been updated since 2010 so it didn’t include support for the new features.  There was some evidence that a 3rd party managed DirectX project called SharpDX could do pixel shaders, so I changed the VM over to use that instead.  SharpDX has been used to create a well known game (Miner Wars 2081) and an open source replacement for XNA (MonoGame), and it seems to have an active community.

Unfortunately it doesn’t look like the Windows 7 components of SharpDX have been updated with the new features of Direct2D v1.1.  I’ve been told that I can use the Windows 8 components, but so far I’m having a hard time working out what I’m supposed to do.  Documentation always seems to be lacking (who wants to write a manual?) and Visual Studio won’t even open the sample projects in Windows 7.

Hopefully I’ll get that working soon, and then the challenge will be finding a good looking pixel shader and getting it to work.

Enhanced by Zemanta

Book Review – Get Shorty by Elmore Leonard

Get Shorty by Elmore Leonard

Get Shorty by Elmore Leonard

The blurb assumes you’ve seen the movie:

The Chicago Tribune has dubbed Elmore Leonard, “the coolest, hottest writer in America.” In the same league as the legendary great ones—John D. MacDonald, Dashiell Hammett, James M. Cain—the “King Daddy of crime writers” (Seattle Times) demonstrates his remarkable mastery with Get Shorty, one of the most adored of his forty-plus novels. The basis of the hit movie starring John Travolta and Danny DeVito, Get Shorty chronicles the over-the-top, sometimes violent Hollywood misadventures of a Florida mob loan shark who chases a deadbeat client all the way to Tinseltown and decides to stick around and make movies. Get Shorty’s shylock protagonist, Chili Palmer, is a truly inspired creation—as memorable as another unforgettable Leonard hero, U.S. Marshal Raylan Givens of the hit TV series Justified—and readers will relish his moves and countermoves in this electrifying, funny, bullet train-paced winner from “the greatest crime writer of our time, perhaps ever!” (New York Times Book Review)

I really like the movie Get Shorty (and its sequel Be Cool), which is why I read this book.  I also really like Out Of Sight which was also written by Elmore Leonard.

It was hard to read the book as if I hadn’t seen the movie, which is the same problem I had when reading Nothing Lasts Forever (the book that Die Hard was based on).  I can’t tell if I liked the book because the book’s good or because it made me remember a movie I enjoy.

I’d heard the name Elmore Leonard before, but I didn’t know much about him.  The one thing I’d gathered was that he has a distinctive voice, and having read one of his books, I agree.  It reads like the transcript of someone recounting the story out loud rather than like a written story.  The author’s distinctive voice is the most noticeable in the dialogue.  I’m not sure whether I would have found it annoying without the movie.

Something that I found strange was how preoccupied the characters were with race.  I assumed that the book had been written a long time ago, but I was surprised to find that it was published as recently as 1990.  Maybe it’s because Elmore Leonard was born in 1925.  Another thing that made the book feel old-fashioned was the technology – the characters used landlines rather than cellphones and I don’t think computers were mentioned at all.

Enhanced by Zemanta

Book Review – The Hitman’s Guide to Housecleaning by Hallgrimur Helgason

The Hitman's Guide to Housecleaning by Hallgrimur Helgason

The Hitman’s Guide to Housecleaning by Hallgrimur Helgason

The blurb says:

With some 66 hits under his belt, Tomislav Bokšić, or Toxic, has a flawless record as hitman for the Croatian mafia in New York. That is, until he kills the wrong guy and is forced to flee the States, leaving behind the life he knows and loves. Suddenly, he finds himself on a plane hurtling toward Reykjavik, Iceland, borrowing the identity of an American televangelist named Father Friendly. With no means of escape from this island devoid of gun shops and contract killing, tragicomic hilarity ensues as he is forced to come to terms with his bloody past and reevaluate his future.

I got this book from the Kindle Owners’ Lending Library, so I didn’t have high expectations, although the title interested me enough to give it a shot.

I was impressed by how much the main character (a Croatian hitman) sounded like English wasn’t his first language (ditto culture) but then I realized that the author is Icelandic, so that explains it.

The main character’s perverse world view is interesting, but I think the best thing about the book is the culture clash caused by how different Iceland is from countries I’m used to.

The author makes the same mistake as a lot of authors and screenwriters by misrepresenting what a sociopath is.

The first 90% of the book was OK although I wondered where it was going.  The ending answered that question, but unsatisfactorily.

Enhanced by Zemanta

Book Review – Realms Unreel by Audrey Auden

Realms Unreel by Audrey Auden

Realms Unreel by Audrey Auden

Here comes the blurb:

Dom Artifex watched the woman he loved give up her undying body in exchange for passage into a land beyond Death. Dom was afraid to follow her, and he despairs of ever seeing her again.

Dom discovers that a strange connection remains between him and his lost love, binding him to each of her reincarnations. Her latest reincarnation is Emmie Bridges, a girl born in the Silicon Valley of the near future.

Emmie grows up to become a designer of virtual worlds in a society shaped by pervasive virtual reality technology and the global alternet information network. When Emmie’s beloved mentor is assassinated, leaving Emmie in possession of a mysterious manuscript that Dom believes contains the secret of death, Dom makes contact with Emmie in an effort to obtain both her trust and the manuscript.

Despite Dom’s efforts to protect Emmie, the assassin is now looking for her and will stop at nothing to keep the manuscript secret. Emmie must retrace the steps of her past reincarnations through worlds both real and virtual to uncover the secret Dom seeks.

I liked this book.  This is one of those “big idea” books that just might expand your mind.  I do feel like the author pulled a punch with the ending though.

Most of the book feels like sci-fi and/or fantasy but how the story ties into the real world is what really got me.

It’s apparently the first book in a series, but it’s been two years and the second one isn’t out yet.

Book Review – The Quantum Thief by Hannu Rajaniemi

The Quantum Thief by Hannu Rajaniemi

The Quantum Thief by Hannu Rajaniemi

The blurb says:

Jean le Flambeur is a post-human criminal, mind burglar, confidence artist, and trickster. His origins are shrouded in mystery, but his exploits are known throughout the Heterarchy— from breaking into the vast Zeusbrains of the Inner System to stealing rare Earth antiques from the aristocrats of Mars. Now he’s confined inside the Dilemma Prison, where every day he has to get up and kill himself before his other self can kill him.

Rescued by the mysterious Mieli and her flirtatious spacecraft, Jean is taken to the Oubliette, the Moving City of Mars, where time is currency, memories are treasures, and a moon-turned-singularity lights the night. What Mieli offers is the chance to win back his freedom and the powers of his old self—in exchange for finishing the one heist he never quite managed.

As Jean undertakes a series of capers on behalf of Mieli and her mysterious masters, elsewhere in the Oubliette investigator Isidore Beautrelet is called in to investigate the murder of a chocolatier, and finds himself on the trail of an arch-criminal, a man named le Flambeur….

The Quantum Thief is a crazy joyride through the solar system several centuries hence, a world of marching cities, ubiquitous public-key encryption, people communicating by sharing memories, and a race of hyper-advanced humans who originated as MMORPG guild members. But for all its wonders, it is also a story powered by very human motives of betrayal, revenge, and jealousy. It is a stunning debut.

I really enjoyed reading this book.  It’s the first sci-fi book I’ve read in a while that’s so full of ideas, but related to that I guess it suffers a bit from First-Book Syndrome in that the author tries to cram all of his ideas into his first book.

While there were a lot of ideas, as a consequence only a few of the ideas were explored in depth, although I get the impression that they might be delved into more in the sequel and further books.

Enhanced by Zemanta