It could be to do with both genes or upbringing, like Shaun said. It probably depends on the person. For example, I have a friend who grew up without a father and was constantly surrounded by his mother, sisters and aunts and there are obvious feminine traits in him, but he's straight (well, he has a girlfriend and hasn't mentioned being gay). I grew up with a father and wasn't forced into a situation where I was surrounded by femininity, I chose to have female friends and like female oriented things (like Gary). As far as I know, I've always noticed boys just as much as I noticed girls when I was younger, which sounds kind of weird, so I definitely think in my case and many others, it's to do with genes.
No one in my family is gay though, so I don't get how it is done through genes.