The rousing “Dallas Buyers Club,” opening locally Friday, is a glorious star vehicle for Matthew McConaughey. Since turning 40 three years ago he had become dissatisfied with the rom-com roles that were threatening to stereotype him as the male Kate Hudson.

Now he’s choosing projects small (such as last summer’s sublime indie drama “Mud”) and large (Martin Scorsese’s upcoming “The Wolf of Wall Street”) that showcase his acting chops. The onetime matinee idol is fast becoming one of the most interesting, entertaining and engaging actors of his generation.

“I try to grow somehow in each one of the roles,” McConaughey said in an interview after “Dallas Buyers Club” was screened at the Toronto International Film Festival. “I feel like I’ve been doing that more so in the last few years. At least I’m enjoying the experience. And I had an incredible experience doing this.”

In “Dallas Buyers Club,” he tackles a showy, high-degree-of-difficulty role. He plays the late Ron Woodroof, a Texas oil-field worker, rodeo rider and onetime loudmouth homophobe turned AIDS activist. Woodroof, a straight man whose notion of a good time included unprotected sex and needle drugs, contracted AIDS in the mid-1980s, when the new disease was a puzzle to the medical community. The testing protocols researchers followed looked like foot-dragging to AIDS sufferers.

Given a month to live at the time of his diagnosis, Woodroof told his doctors to go proctoscope themselves. He found alternative treatments and made a fortune smuggling unapproved drugs from around the world. McConaughey and co-star Jared Leto, who plays a transvestite hustler, are considered front-runners for Oscar nominations.

The film, directed by Jean-Marc Valee, was a guerrilla production, with a $4.7 million budget, a single camera, skeleton crew and bare-bones equipment. It was shot on location in Texas in an exhilarating “hellbent for leather” 27 days. Crucial work for McConaughey was done in the five months prior. To play the emaciated Woodroof, McConaughey dropped 50 pounds on a medically supervised diet. The transformative moment came when Woodroof’s family passed along his diary. Suddenly the actor had a window into the spirit of the person he was about to portray.

The diary “gave me ownership of the man,” McConaughey said. “I started saying to Jean-Marc, ‘Just press “Record.” I’ve got it.’

“Here’s a guy with a seventh-grade education, a guy who hadn’t really found his way or purpose in life. He got purpose when he got HIV.” But McConaughey was not interested in making a preachy message movie about a roughneck’s conversion to empathy and political correctness.

“We’ve got this hell-raising bigot at the beginning,” he said. The typical path would be to suggest, “Well, we’ve got a real opportunity at the turn of Act Three to have him have this real coming-to-God moment. ‘Oh, woe be my ways of the past. Who was I? Now please forgive me and let me go forward,’ ” he said in choirboy tones.

McConaughey and the director pushed the character’s rowdy, mercenary personality so forcefully they often worried if they’d gone too far.

Ultimately, McConaughey decided, “It’s not my job to worry whether he’s sympathetic. If we keep him [real], the humanity will come out. If we keep him a businessman, if we keep him a selfish son of a bitch, the crusader will reveal himself. If it had been a studio film, someone would have intended to sanitize that.”

McConaughey said he’s grateful for the financial security his mainstream hit movies gave him, which enabled him to take a breather and “sit out in the shadows” until more challenging and rewarding fare came his way. “I felt like the films I was getting offered, I’d read ’em and I felt like I could do it tomorrow. But I don’t know if I’m really going to have an experience.”

He added, “There were some action films that I thought were good and came with beautiful paychecks. But I just said, ‘No, not for me right now.’

“My agent and I had some real good sit-downs,” he said with a chuckle.

Holding out paid off, and challenging filmmakers began to think of him in a new light. That’s when William Friedkin (“Killer Joe”), Steven Soderbergh (“Magic Mike”) and Lee Daniels (“The Paperboy”) called, he said.

“Dallas Buyers Club” was a project the actor tried to launch for four years. It finally moved ahead because of “pure willpower” on the part of the producers, cast and crew, who simply insisted that the film be made.

“Eight days before we were supposed to shoot, the director calls me and says, ‘We don’t have the financing, I don’t think we’re going to be able to make this movie on this budget. But we’re supposed to begin in New Orleans Tuesday. I’ll be there ready to shoot if you will.’ We just said, ‘Let’s go’ and the rest of the financing sort of caught up with us.”

To McConaughey’s way of thinking, the film’s greatest achievement is balancing its serious theme with its antihero’s anarchic sense of humor. “There could be a version of this film that feels like good medicine and you should see it and it’s an important film. But we made one that I think is entertaining. That’s something that some independent films dealing with a subject like this aren’t going to get. That, I’m proud of.”