My opinion is just an opinion, though it is coming from an openly gay guy, so take that for what you will. If you are asking someone "Are you gay?" because you think it would be nice to know, as you state you do in the OP, it's not offensive, but it's not exactly the best way to phrase it. This isn't because it's a bad question, it's because of two major things: 1) Several insecure straight guys will assume you're questioning their "manhood" (even though that is completely ridiculous) and 2) If the guy you're talking to is closeted, you just made his life a living hell. While I was closeted, the idea that someone could have figured out my sexuality constantly made me aware of what I was listening to, how I responded to situations, etc. and if anyone had questioned my sexuality (even as a straightforward question) I would have freaked out.
It might be easier to ask "What do you look for in a relationship?" or "Who are you interested in?" It allows a ton of plausible deniability for the closeted gay guys, and preserves the "masculinity" of the insecure straight guys. Sure it's more unwieldy, but honestly, after the stress I was under by being closeted, I think it's a better question to ask.