Although they are commonly bracketed together, it is hard to think of two more antithetical writers than J R Tolkien and Mervyn Peake. Tolkien's fictional writings are fantasies, and not only in the literary genre to which they belong. The donnish cleverness with which Tolkien fabricated his imagined world cannot disguise the truth that it is no more than a fusty pastiche, composed from his own deeply conventional Christianity and the class hierarchies of prewar England. It is a regression to a vision of childhood as understood by a certain sort of adult. Lord of the Rings answers the need for a world in which good and evil are not intertwined, and where the final outcome of their conflict is never in doubt. It is essentially an escape.
There may be something childlike in the Gormenghast trilogy, but Peake's childhood was more fantastic than anything invented by Tolkien, and he used its resources to far better effect. The castle and its inhabitants are plainly a reworking of the expatriate British colony in which he grew up, but the style in which Peake's memories are reassembled has more in common with the playful wit of Laurence Sterne than it has with Tolkien's laboured whimsy. Encircled by wilderness and a castle of artisans they rarely meet, Gormenghast's inhabitants are shown pottering through lives ruled by private obsessions, spent hopes and pointless ritual. Peake's characters are drawn with a pitiless eye, and the destruction of their curious way of life is recounted with unfaltering good humour.
What sets the Gormenghast books apart from the regressive exercises in fantasy with which they are so often confused is the gaiety with which Peake plays with horror and tragedy. He infuses acts of murder with the flavour of farce, and even the descent into insanity is rendered as an episode in a dark comedy. Unlike the cosy worlds created by Tolkien or C S Lewis, Gormenghast contains no benign providence that can be relied on to set wrongs right. In this pagan universe, evil can be clear-minded and courageous, goodness muddled and ineffectual, and defeat is final. There is no trace of Christian theodicy or Enlightenment hope of progress here. Yet Titus Groan and Gormenghast are works of superabundant vitality. If they have a message, it is that human life can be affirmed without denying any of its horrors.
In the last book of the trilogy, this affirmation is absent. By the time Titus Alone was written, Peake was suffering from the illness that was to deprive him of his creative powers, but it is wrong to suggest, as some have done, that its disjointed style and nightmarish imagery signal the onset of madness. Peake's illness was never conclusively diagnosed, but those closest to him believed it to be a neurological disorder, probably Parkinson's disease, which may have been aggravated by a virus he picked up as a child in China. What shaped Titus Alone was not so much Peake's worsening health as his travels through the ruins of postwar Europe and his visit to Belsen as a war artist not long after its liberation. The dying men and women whom Peake sketched there seem to have scarred him for life. Titus Groan was written during the war; Gormenghast was written in the years immediately following it. If Gormenghast lacks the perfection of Titus Groan, as I think it does, it is because, when he wrote it, Peake had seen too much not to be afraid. After Belsen, he could no longer toy so lightly with despair and madness.
Titus Alone is the only book of the trilogy not to be set in Gormenghast, and it is the closest Peake came to giving his view of the late modern world. Peake's account of what Titus finds when he leaves the closed universe of the castle is given in a series of 20th-century ciphers: casualties of war marooned in forgotten camps; new technologies effervescing in the midst of poverty; natural beauty desolated by ephemeral wealth. Peake had no remedy for these evils. He was an artist and poet, not a thinker, and the Gormenghast books are not novels of ideas. Yet they grapple with questions from which more mainstream fiction shies away. How can human lives have meaning in the absence of religious faith and its secular substitutes such as the belief in progress? How much in our moral outlook rests on these beliefs? Doesn't even the idea of tragedy presuppose a moral order in which we no longer believe?
Graham Greene wrote to Peake's wife, Maeve, of how the Gormenghast books were unfilmable. Greene was one of Peake's earliest and staunchest admirers, without whose intervention Titus Groan might never have been published, and a perceptive film critic. But in this judgement, Greene was mistaken. Peake was a draughtsman of genius, as Greene acknowledged, and this is evident on almost every page of the Gormenghast trilogy. Each book is an enormous gallery of pictures. J G Ballard - who also grew up in China - said that all his books are paintings. Much the same could be said of Peake's. Far from being unfilmable, Titus Groan and Gormenghast sometimes read like a film director's notes in their precise attention to details of light, costume and landscape.
Still, Greene had a point. Gormenghast is a work of fancy that could easily melt away by being envisioned too clearly. Its singularity and lack of historical context are daunting. Should Gormenghast be shown as a medieval castle or as something more like a Tibetan monastery? How should the inhabitants be dressed? How much of the paraphernalia of the modern world, if any, should be allowed into the visible details of their lives? If radio seems a more natural medium for Peake's books, it is because it can leave these nagging questions unanswered. The most successful broadcast version of the Gormenghast books to date has been as a radio play. It might well seem that Peake's vision is best left off the screen.
Yet Peake's books have now been re-envisioned for television in a production that achieves what Greene thought impossible. The Art of Gormenghast, by Estelle Daniel, producer of the BBC series, is a fascinating guide to the formidable difficulties that the project faced - and how they were overcome. The result is a feast for the senses, a triumphant fusion of brilliantly conceived sets with superb acting and music in which - astonishingly - nothing of the book's strangeness has been lost. The series has been described by Sebastian Peake, the writer's son, as "the defining moment of glory in the life and times of Mervyn Peake". He is right. In this magnificent BBC production, a unique writer has at last received his due.
John Gray's most recent book is "False Dawn: delusions of global capitalism" (Granta, £8.99)