The most important difference between Ophelia and Hamlet's madness in Act 4 is the fact that Ophelia is, in fact, gone crazy, while Hamlet is merely continuing to put his "antic disposition on." Hamlet's behavior in the first few scenes is "crazy" because he needs to maintain the illusion of madness as a cover story for his murder of Polonius. He didn't intend to kill him, but he did nevertheless kill a man and that act has put in more danger with Claudius. Claudius will now be seen as more "justified" in taking action to control Hamlet. Hamlet seems to enjoy acting crazy because each time he does, he gets to say all the things he wants to say without regard to the relationships he supposedly has with the people around. He can tell Rosencrantz and Guildenstern that they are merely sponges who soak up the King's favors. He can call his uncle his mother and defend himself. He can insult the king by explaining how the king, as worm food, could actually go through the digestive track of a lowly beggar. In his "right mind" he would never speak this way!
Ophelia, on the other hand, has been put through too much for her mind to handle, and she has truly lost her sanity. Over the course of a few days she has been told to break up with her boyfriend, who later told her to go to a nunnery and that the never loved her. That same boyfriend killed her father. Her behavior -- specifically the singing of seemingly random snatches of songs (alluding to her father's death and her betrayal by Hamlet) and handing out flowers while hardly engaging with those around her are sure signs of madness. Her subsequent suicide is the final act of a crazy woman.