MUCH like the hero of the new comedy “Forgetting Sarah Marshall” -- who is merrily undressed at home and expecting an entirely different purpose for his girlfriend’s visit than her dumping him -- actor-screenwriter Jason Segel endured his own Naked Breakup.

But there is a key difference between what Segel’s state of mind was when it happened to him and that of his movie character, who is too despondent to even pull on a pair of jeans as he gets the news. “It’s like my sickness,” Segel says, “but the whole time I’m trying to be present, and all I’m thinking is, ‘This is the funniest thing that has ever happened! Let her leave so I can write this down immediately!’ ”

By “this,” the graduate of the golden Judd Apatow School of Comedic Training means turning his dating humiliation into fodder for a romantic-comedy-literate and raunch-attuned movie audience. As heart-crushed TV music composer Peter Bretter, Segel wrings some cringe-worthy laughs out of a literally and figuratively naked romantic who flies to Hawaii to recuperate only to find his sexy TV actress ex (Kristen Bell) cavorting at the very same luxury resort with her new British rock star beau (Russell Brand).

“I thought, disaster in paradise, a funny juxtaposition,” says Segel, who gives his protagonist hope in the form of a cute, compassionate hotel employee (Mila Kunis), but not before subjecting him to several broken-guy gags that would make even Alan Alda tell him to man up: fetal position wailing, ill-timed confrontations, self-pitying piano playing.

As the 28-year-old Segel put it over dinner recently at the Chateau Marmont, “For some reason, I was born without a sense of embarrassment or shame.”

It’s a trait comedy impresario and “Sarah” producer Apatow picked up on 10 years ago when he cast the gangly teenage Segel -- a high school basketball state champion nicknamed “Dr. Dunk” -- to play the unabashedly obsessive torch-carrier Nick Andopolis for his seminal, short-lived coming-of-age series “Freaks and Geeks.” After that was a memorable guest stint as the jealous, weepy boyfriend Eric on Apatow’s other brief-run series, “Undeclared.” Now as Marshall, the youthful urbanite Segel plays on the CBS sitcom “How I Met Your Mother,” he is a happily married man, but last season’s busted-engagement story line afforded the actor plenty of hilariously mopey episodes.

Segel traces the roots of this comic persona to a piece of direction Apatow gave him for “Freaks” when Nick serenaded his crush Lindsay (Linda Cardellini) with the cheesy Styx ballad “Lady.” Recalls Segel, “He came up beforehand and said, ‘It has to be really embarrassing but really sweet, really genuine and really funny.’ And I just figured that’s what my life is like in general, so I would just be as honest as I could.”

Segel dated Cardellini for a few years after “Freaks.” Does he think people might assume Bell’s philandering girlfriend role is based on his ex? “I can’t control what people think,” says Segel. “I was still very much a child [then], and this was more an amalgamation of a lot of different relationships and breakups I’ve had. People are bound to talk, but she was a great girlfriend.”

Bell, meanwhile, stresses that what impressed her about her costar’s script was its acknowledgment of the complexities of romance. “It was less about siding with people and more about the real dynamic of a relationship at the breaking point,” says Bell. “It was great to play the comedy of her being a little bitchy or ditsy, but she’s also allowed to show her human side and say it’s nobody’s fault. Everyone gets to speak their mind.”

Bell, however, did have to act opposite the full frontal Segel. “I just committed to eyes in the sky,” she jokes about filming that scene. Segel knows it will be an Internet frame capture forever, so when he first showed the film to his family, he opted not to warn them. His kid sister Alison roared, but he caught a tear rolling down his mother Jill’s face. “It broke my heart,” he said. “The next day she sent e-mails to my entire family saying, ‘I just want to make you aware about Jason’s full frontal nudity but’ -- and this is my favorite part -- ‘I do want to emphasize that it is completely in context.’ ”

For Apatow, Segel’s goofy, pained vibe felt like star material from the outset. “He has a hilarious neediness about him that has always made me laugh,” the producer says. “He’s a fun actor to watch because he’s the guy who thinks he’s hiding his emotions, but they’re so obvious. He cannot hide his intent.”

Segel is the latest, after “Freaks” colleague Seth Rogen, to feel the guiding hand of Apatow in transitioning from a business-unsavvy teen actor to fully functioning multi-hyphenate movie guy. It started for the Los Angeles native when his outlook appeared uncertain after “Freaks” ended abruptly in 2000. “I’m 19 years old, I’m 6-foot-4, I’m too old to steal the SATs but too young to play a doctor or husband, and Judd said, ‘The only way you’re going to make it is if you start writing your own material.’ There was a lot of improv on ‘Freaks,’ and he said to me, ‘If you can improv like this, then you can write.’ ”

Apatow gave Segel a weekend crash course in outlines, beat sheets and script formatting; with that, Segel sold a script at age 21. (“A kids’ adventure movie that never got made,” he says.) But for the most part he couldn’t catch a break as an actor, even in Apatow projects like “The 40-Year-Old Virgin.” “There was a character called Jason,” recalls Segel. “Judd said, ‘I’ve written this for you.’ I could not have been more excited. I hadn’t worked in a while. But he couldn’t get me approved. I wasn’t famous enough. That was my low point.”

His stint on a cult show finally began paying off when he didn’t have to audition for “How I Met Your Mother.” “They were big ‘Freaks and Geeks’ fans,” says Segel of the show’s creators.

He then filmed a part in Apatow’s “Knocked Up” and during a Friday night Lakers game at Staples Center pitched him his idea for “Forgetting Sarah Marshall.” Segel’s diploma from Apatow U came that Monday in the form of contracts from Universal.

Segel believes it’s been Apatow’s mission to prove to everyone that the “Freaks” cast deserved better than first-season cancellation. “We were on a plane, Judd and I, and he leaned back and let out a deliberate exhale, like you could tell a joke was about to come. He said, ‘I finally got you a lead in a movie. Now I can sleep.’ ”

Although “Sarah” may be Segel’s exorcising of certain relationship demons, the irony is it comes at a time when he’s too busy to be any girl’s devoted paramour. Amid the post-writers-strike flurry of new “How I Met Your Mother” episodes, promoting “Sarah,” shooting a new film, and writing new scripts, Segel says, “I’m a bit of a ragamuffin. I wouldn’t trust someone like me. I mean, I think I’m a good guy and all that, but I’m pretty focused at the moment.

“And I have to start going to the gym for this movie” -- a buddy comedy with Paul Rudd called “I Love You, Man” -- “and it’s the worst. I hate it.” (It seems Segel has exorcised Dr. Dunk as well.)

The partnership he is willing to nurture right now is with “Sarah” director Nicholas Stoller. The pair, who first met when Stoller was an “Undeclared” writer, are developing another treacherous boy-girl comedy for Apatow with the self-explanatory title “Five-Year Engagement.” Says Segel, “Hopefully it’s like ‘Annie Hall’ in tone.”

Then there’s his dream project: writing the new Muppet movie. “I was a huge Muppet fan growing up,” says Segel, who used the Henson Company’s puppets for the big finale of “Sarah” and then sold Disney on a pitch. “I want to bring it back to the early ‘80s Muppet movies, when the scripts could have been performed by humans.”

His favorite Muppet? “Kermit was the Everyman, the original Tom Hanks.” Segel pauses. “But I have a special place in my heart for Fozzie Bear. The classic borderline hacky entertainer.”