Two weeks ago, along with 500 Rhondda movie-goers, I was lying on a cricket pitch in Treorchy watching Freddie Mercury snog his boyfriend in Bohemian Rhapsody. The age of the crowd varied between 18 and 94 – and nobody so much as sniggered or blushed, but I smiled to myself. I don’t suppose the film would have had the same reaction when Freddie was alive, and even when I was first elected in 2001, the statute book still had criminal offences that applied exclusively to gay men. Amazingly, under ancient laws, men were still being prosecuted for meeting someone in a bar and taking them home. Since then – and in remarkably short order – we’ve introduced civil partnerships, same-sex marriage, gay adoption, gay people in the military and we’ve outlawed discrimination on the basis of someone’s sexuality in the workforce or in providing goods and services. Who says voting never makes any difference?

As the latest edition of the British Social Attitudes survey shows, views have changed as well. Yes, there’s been a tiny dip in the percentage of people in the UK who think it’s OK to be gay – more or less within the margin of error – but still the vast majority are cool with gays. It seems that changing the law has helped change attitudes, and politicians have led where others were at first reluctant to follow. And when it came to Northern Ireland legislation this week the Commons delivered the largest majority ever in favour of gay equality – 383 to 73 – even though some fellow gay MPs and our allies felt it more important to leave it to Northern Ireland’s own politicians to introduce equal marriage.

So far so good. But there’s a danger in this euphoria of acceptance if we forget our history. The truth is, homosexuality did not burst on the scene in the UK with Elton and Freddie strutting their stuff with gay abandon. Both of them had to live in the shadows of shame and denial for many years. The law was still hideously repressive.

When I was young and coming to terms with being ever so slightly gay, the unacknowledged secret gay anthem was not a brave upbeat torch song like I Am What I Am or I Will Survive. True, Tom Robinson had already come out with Glad to Be Gay in 1978, but my memory of early Pride marches was of people furtively holding hands as they listened to the much darker, more wistful lyrics of Somewhere, which Maria sings over Tony’s dead body at the end of West Side Story. Somewhere, surely, we hoped, we might be accepted.

The trouble was that having been branded and bullied as queer for so many years we had inherited a love of tortured frailty. We were half in love with furtive glances, stolen looks and the terror of misunderstanding someone else’s come-on. Shame came naturally, without so much as a priest’s sermon or a parent’s condemnation. So it was no surprise that St Sebastian, his beautifully buff body shot through with arrows, was our patron saint – and we delighted that nobody else seemed to have worked out that the tortured soul in Brideshead Revisited was called Sebastian Flyte for a very precise coded reason.

From 1880 to 2001 we had tough anti-homosexuality laws. Men were sent to prison for seven years with hard labour. They were arrested, convicted and flogged for “importuning”, that is to say, chatting up a stranger. They were convicted on the flimsiest of evidence – a touch of mascara or a powder puff in their pocket. They were subjected to intimidation, abuse and blackmail. They never dared report a queer-bashing lest they be the subject of the police investigation.

But that would never happen again, I hear you cry. We’ve turned the page. All I say is let’s not forget that the most liberal city in the world in the 20th century was Berlin, during the Weimar Republic. Rich gay men travelled from England to enjoy the pleasures of dozens of bars and clubs that catered for every purse and every preference. But in 1934 Hitler killed off gay Nazis such as Edmund Heines and Ernst Röhm in the Night of the Long Knives, and started sending gay men to Dachau and other concentration camps. Thousands were murdered without a memorial.

Progress is never a one-way street. Some of us look at the increase in hate crimes, the homophobic demands to stop teachers referring to homosexuality in schools, the increasing violence in Russia and elsewhere as signs that the battle is not yet won. Gay youngsters still face abuse. Shame still forces many to self-harm or take their own lives. And as long as that continues we’ll still need to sing the tender ballads.

• Chris Bryant is Labour MP for Rhondda