Gandalf has worked his magic in 54 secondary schools over the past two years. His dream? An education system free from homophobia and a curriculum that fully includes lesbian, gay and bisexual people. Hundred of Hoo has recently come out of so-called "special measures" imposed by government on problem schools and is no stranger to underachievement. Sir Ian and Stonewall see visits to schools like this as crucial to ensure that not one ounce of potential is lost for today's gay pupils — especially for those who underperform because their confidence has been battered by bullying. Homophobia was rife when I was a pupil. "Freak", "queer" and "disgusting" were familiar words, aimed at anyone, like me, who was perceived to be gay. Consequently, nobody dared to come out. This created an un-virtuous circle; teachers could see no reason to address gay issues in lessons when there appeared to be no gay pupils. It wasn't until I left that I discovered three of my best school friends were also gay. We had been too scared even to admit it to each other. The notorious "Section 28" legislation, introduced in 1988 as part of the Local Government Act when Margaret Thatcher was prime minister, was to blame for much of this. This made it illegal to "promote" homosexuality in schools. So homophobia festered unchallenged for 15 years until the law's repeal in 2003. But the hangover remains. Recent research for Stonewall found that nine in 10 secondary school teachers say their pupils experience homophobic bullying, but nine in 10 have never received any training on how to tackle it. Up to 95 per cent of teachers tell Stonewall they hear the phrases "you're so gay" or "that's so gay". Homophobia is so commonplace that "gay" is a synonym for anything inadequate.

But I hardly recognised this school upon my return. Gay issues are very much on the agenda — and pupils are refreshingly honest about their prejudices. "We Googled you yesterday Ganda . . . I mean Sir Ian!" says a 12-year-old girl. "We were well surprised when we found out you were gay, because you're nothing like Alan Carr! [a very camp television comic]" Sir Ian replies that gay people come in all shapes, sizes and personalities, just like straight people. He knows Alan and says he is just like that off-screen, too. "The most important thing is that he can be himself." The class listens eagerly as the actor tells them he didn't come out until he was 49 in 1988, and did it then because Section 28 was being debated in Parliament. "Did you worry it might destroy your career?" a pupil asks. Yes, but that was a risk he was willing to take, Sir Ian says. How has he found the pupil reactions? "Until I visited secondary schools recently, I hadn't realised how much anti-gay bullying goes on," he says. "By talking frankly about my own life as a gay man and listening to the concerns of staff, students, parents and governors, I hope the visits may make a difference and also give confidence to gay students about their lives in the future." It's time for the all-school assembly, the grand finale of Sir Ian's visit. "I'm not useless," Sir Ian asserts in my old school hall, "but when you use that word as an insulting adjective, that's what you're saying about me. So please, watch your language. Because if you don't, you mightn't watch your actions . . ." He goes on to tell how Ian Baynham, a 62-year-old gay, was recently killed in a homophobic hate attack by teenagers. "The girl who stamped on his head might have used 'gay' to mean anything rubbish and useless. And that probably convinced her that gay people were rubbish and useless — and don't deserve to live." His statement had a profound effect on two year 10 pupils, who tell me: "We didn't realise calling things 'gay' could offend someone. It was touching when he talked about never being able to tell his mum he was gay. One of our best friends is gay and he gets abused for it. We hope it will stop now."

Sir Ian also takes part in lessons to promote Stonewall's curriculum guidance, titled Oh no! Not the gay thing!, which advises teachers on how to integrate gay issues into class. In science lessons, for example, it can be a relief for gay pupils to learn about same-sex attraction as a natural fact in other species. And same-sex relationships can make pupils think carefully about grammar in modern languages. Stonewall's new campaign in schools also includes the story of Lance Corporal James Wharton, who, at 24, is the new poster boy for modern gay equality — he was the first openly gay soldier to appear on the cover of Soldier, the British armed forces' magazine. He will be touring British schools with Stonewall over the next three months. There are also plans for a school intervention from a celebrated high-achieving lesbian or bisexual woman role model. GUARDIAN