Adapted from a 63-year-old Patricia Highsmith novel, “Carol” doesn’t end the way most gay movies do — which is to say, nobody dies. Instead, the movie lingers on a look between Cate Blanchett and Rooney Mara, one that offers hope instead of tragedy, daring to suggest that two same-sex lovers could make longterm companionship work.

It’s taken the American legal system a long time to consider the same conclusion. With public opinion changing so fast, Hollywood is awfully quick to take credit for having played its part. Invigorated by California’s Prop. 8 battle, showbiz activists claim the high-profile representation of gay characters paved the way for public awareness of LGBT rights, the way “Guess Who’s Coming to Dinner” advanced discussion of mixed-race relationships in the 1960s — only, “Guess Who’s Coming to Dinner” didn’t end with Sidney Poitier being tire-ironed to death by the side of the road, the way fate punishes Jake Gyllenhaal in “Brokeback Mountain.”

Yes, Hollywood has given us more and better movies about the LGBT experience in recent years, but the upsetting truth is, the vast majority of mainstream cinema still presents gay characters as victims. Whereas straight romantic couples have long been allowed to live happily ever after onscreen (aka a “Hollywood ending”), their gay counterparts haven’t been so fortunate, nearly always dying of AIDS, hate crimes or suicide, rather than riding off into the sunset with their partners.

The operating assumption seems to be that straight audiences won’t care about these relationships if handled in a conventionally uplifting way. Format them as tragedy, however, and we shed a tear when bigots rape and murder trans man Brandon Teena in “Boys Don’t Cry,” or when a deranged assassin robs gay San Francisco official Harvey Milk of true love at the end of “Milk.” Evidently, popular audiences can only stomach so much gaiety in their gay-themed movies.

On one hand, these downer outcomes seem reasonably progressive and empathetic (after all, they do successfully inspire audiences to identify with gay protagonists). But they descend from a troubling tradition of didactic entertainment, one in which censors wary of cinema’s power to influence behavior demand that such monsters be punished, lest susceptible audiences get the wrong idea.

Beginning in 1930, the Motion Picture Production Code decreed “any inference of sex perversion” as being right up there with drug trafficking, miscegenation and white slavery on the studios’ list of taboo subjects. For decades, homosexuality remained the love that dare not speak its name in Hollywood, yielding ambiguously undefined characters depicted as outsiders to pity (the victim), to parody (the sissy) or to fear (the predatory homosexual).

When gay desire did rear its head, the Hays Code demanded that the aberrant characters be suitably punished for their amorality. The penance for such crime was often severe and usually death: Playing a conflicted closet homosexual, Don Murray slits his throat in “Advise & Consent”; Audrey Hepburn finds Shirley MacLaine (who loved her “that way”) hanging at the end of “The Children’s Hour”; and so on.

For anyone seeking to better understand the tradition of gay victimhood onscreen, the stereotype-shattering documentary “The Celluloid Closet” becomes required viewing. Made 20 years ago, that film ends on a note of optimism, pointing out how independent cinema is challenging Hollywood’s homophobic paradigm.

But it would be wrongheaded to congratulate the studios for any progress we’ve seen since, apart from having set such a bad example that LGBT filmmakers have been compelled to take representation of gay characters into their own hands, the way Lisa Cholodenko did in the aptly titled “The Kids Are All Right,” which illustrated how a lesbian couple copes with the setbacks any relationship faces, while raising two well-adjusted teens in the process.

Though contemporary mainstream cinema has long since eroded the other prohibitions once censored by the Production Code, the ghost of moral rectitude still haunts the gay topic. And so LGBT characters continue to pay with their lives for their refusal to conform: In “Philadelphia,” Tom Hanks’ otherwise healthy relationship with Antonio Banderas is cut short when he succumbs to AIDS; in “A Single Man,” a grief-stricken Colin Firth contemplates suicide after his partner’s death, decides against it, and then suffers a fatal heart attack.

Since the beginning of cinema, popular movies have instructed straight audiences on how to court, how to kiss and even how to keep the spark alive. Meanwhile, gays are starved for depictions of themselves onscreen — compounded by the fact that so few gay actors have come out and identified themselves as such, depriving the LGBT community of offscreen role models.

Gay marriage may finally be accepted, but it’s not because Hollywood helped to depict what it might look like. Rejected by religion, deprived of public examples, thousands of real-world gay couples found themselves trying to invent the same wheel at the same time, forced to define for themselves what a committed relationship actually means.