No, it's not offensive. But it's about as subtle as knocking on a door by hitting it with your car. The question itself is more likely to get insecure folks up in arms if they aren't gay. As with most delicate topics, the way you say it is more important than what you say.
I find it's more effective to ask "Are you straight or gay?", and I usually slip it in during a conversation that's actually about sexual orientation instead of just popping it out of the blue. I am aware that there are other orientations, but if someone happens to be bi or pansexual or asexual they're going to understand what I'm asking.
If you're not sure about someone, and you really care enough about the answer, ask. Assuming one way or the other can make things kind of awkward. Some people might take offense to it, but that doesn't make it "offensive". It's a perfectly legitimate question to ask.