Just because he was given lots of nice things doesn't mean he was given the love and affection he needed. His father seemed especially distant to me. It's not rare for rich kids to get everything they want material wise but not be given the love and affection they need from their parents (think Tony Stark/Iron Man), which can really mess them up. Plus, his friends were idiots that did everything he said and couldn't think for themselves so it's understandable that he would be envious of Harry, Ron and Hermione's friendship. It's really sad to think about that he may have been so mean to them because he craved their attention and secretly wanted to be their friend. He probably started to change because he started thinking for himself and didn't just believe everything his parents had taught him and being placed in situations where he was expected to do thing that he knew were wrong, like killing Dumbledore. I like to think he became a much better person when he got older.