Correction: An earlier version of this story misspelled the last name of Matt Cloninger. The text below has been corrected.

With some trepidation, Tammy Smith visited her tiny home town in rural Oregon last year, shortly after being named a brigadier general in the Army Reserve.

Folks had known her as a tomboy active in the Future Farmers of America, and Smith wasn’t sure how they would react to her and her new wife, Tracey Hepner.

But at a reception the town threw for Smith, men from the Veterans of Foreign Wars post posed for pictures with her, often insisting that Hepner join the photo. One woman gave the couple a wedding present, a glass sculpture of two kissing doves that graces their living room in Arlington, Va. The local newspaper called Smith’s promotion the most positive news out of the town of fewer than 1,000 people that year.

“There was a sense of pride that Oakland, Oregon, had produced somebody who not only was a general, but someone prominent who is out,” said Smith, 50, the first openly gay officer of flag rank in the military. “It was an amazing and unexpected response.”

The welcoming embrace that Oakland showed Smith and Hepner is becoming increasingly common in the United States. In a Pew Research Center poll released Thursday, nine in 10 lesbian, gay, bisexual and transgender adults said society has become more accepting of them and that they expect it to become more so in the years ahead.

A look at the gay, lesbian, bisexual and transgender community today.

But only 19 percent said there is “a lot” of acceptance for gays, while 59 percent chose to characterize it more softly, as “some” acceptance, and 21 percent said there was little to none. More than half said they had been subjected to slurs or jokes about gays, and sizable numbers said they had been rejected by friends or family, threatened with physical attack, or made to feel unwelcome at a house of worship.

The Pew survey of 1,197 LGBT adults is the first of its kind by a major polling organization.

It asked them when they realized they weren’t straight, when they came out and how they have felt ostracized at times. Compared with the general public, Pew said, gay men and lesbians are more liberal, more Democratic, less religious, less happy with their lives, yet more satisfied with the direction the country is headed.

“For the LGBT population, these are the best of times,” said Paul Taylor, executive vice president of the Pew Research Center. “But that does not mean these are easy times or their lives are ­uncomplicated. Many are still searching for a comfortable, secure place in a society where acceptance is growing but still limited. That is part of the drama of their lives.”

Pew links the growing acceptance to familiarity. In a separate poll, almost nine in 10 people said they have a gay friend or relative, up from six in 10 only a decade ago.

The gay people polled by Pew said they think lesbians are more welcomed than gay men are. One in four said there is a lot of acceptance of lesbians. Just 15 percent characterized it that way for gay men. A third said bisexual women are accepted a lot, compared with just 8 percent of bisexual men. And only 3 percent of those polled said transgender adults are accepted.

One striking finding of the Pew poll is the young age at which many gay people say they realized they weren’t straight.

The median age at which gay men said they had their first inkling was 10, and they knew for sure by 15. For lesbians, the median age when the realization dawned was 13, and they were certain by 18. The median age when gay men first told someone was 18, and 21 for lesbians.

Janelle Thomas remembers feeling “different” when she was in second grade and enjoyed math lessons. In retrospect, she realizes she had a crush on the female teacher.

In high school in Southern Maryland, she dated boys, but she said it took going to college and meeting other lesbians to make her understand and accept who she is.

“I got into a very dark place where I didn’t feel I was myself,” said Thomas, now 27 and a Web content coordinator for the federal government who lives in the District with her wife, a D.C. police officer. “It just came to me. Oh, that’s probably what it is. I suddenly felt better.”

Older gays often recall their awakening sexuality as a time of struggle — with themselves, society at large and those who loved them. Many came out later in life. In the Pew survey, two in three gay men and lesbians younger than 30 said they came out before age 20. That was true of less than half those who are 30 to 49 and barely a third of those who are 50 and older.

Matt Cloninger, a 40-year-old government consultant who lives in the District, was confused by his lack of attraction to girls while he was in high school during the 1980s. But as the son of a Pentecostal minister at a time when the AIDS epidemic was depicted as a gay disease, he said he could not acknowledge, even to himself, that he wasn’t straight.

“In wrestling with this attraction I had and all the confusion, there’s many a night I remember sitting in my bedroom praying and crying and begging God to take away these feelings and give me feelings that would be normal or straight,” he said.

He was in college, on a Christian leadership scholarship at Southern Methodist University, before he came to grips with his sexuality and told co-workers at an off-campus restaurant. After he moved into an apartment with a gay friend, his father asked him flat out if he was gay.

Cloninger said he never has doubted his parents’ love for him, but he knows that his sexual orientation has caused them agony. The night before his 2008 wedding in San Francisco, Cloninger said, his father called in tears to say he could not attend. Cloninger said his nieces and nephews have never met his husband, and although he has told his brother he is gay, they never discuss it.

A senior warden at St. Thomas Episcopal Church near Dupont Circle, Cloninger said his family has become more accepting, but only to a degree.

“It’s certainly hard being comfortable with myself and seeing where my family is,” he said, “going to family reunions where my spouse is not necessarily welcome. My parents have come to love and accept Brett. But with the rest of the family, no one wants to say anything about it.”

In the Pew poll, a third said they haven’t told their parents that they are gay.

“There’s definitely this notion that it does get better, and it has gotten better for most people,” said Gary Gates, a Williams Institute demographer of the gay community who consulted on the Pew study. “But there are a lot of people who are sufficiently concerned that they don’t feel comfortable coming out.”