Hamlet and Ophelia were deeply in love. They were lovers in some sense. There are suggestions that they had sex, but that might have been Hamlet playing crazy or acting spiteful. But after watching his mother, Hamlet thinks all women are weak and only want sex. So he thinks the same with Ophelia (thats the reason for the closet scene). but he gets even more mad and angry at her when he finds out she has become one of her fathers "whores". Polonius dosent want them to get married because all he wants is power and if she marries Hamlet she will have more power then him. So he tells her she can no longer see Hamlet. Edit
And she willingly does what her father says. Hamlet is mad at this but gives her one last chance. When Polonius and Claudius are watching their conversation Hamlet says "where is your father" and she replys "at home." This was her last chance and when he sees that she has become corrupted by her father he becomes enraged with her. This contributes Ophelias insanity as well. He never stops loving her (shown at the funeral) and she still loved (shown when he was yelling and cursing at her and all she could do was beg for god to fogive him). Its just that Hamlets thoughts of revenge and his thoughts of his mother held his main attention and thus he more or less forgot about Ophelia and how he treated her until it was to late.
Later on Hamlet tells Opherlia to "get thee to a nunnery" (a euphemism for whorehouse), and that her father is a 'fishmonger' (a euphemism for pimp), which can be read as either that Hamlet had been sleeping with her, or that he was just trying to imply it, or that he was suggesting her father was using her to get at him (he was), or maybe a warning to Ophelia to get out of the way of the bloodshed that was coming. Or some combination thereof.
He's also extremely angry at her because she drops him without explaining why, and then allows herself to be manipulated so that the King and Queen can find out what's wrong with him. But she was a lower-status individual and both her father and brother warn her that Hamlet's just using her, so it's not clear if he actually loved her or she was just a flirtation.