Even when I don't slouch and try to sit straight up, I still get neck and back pain and cannot play for more than 15 minutes or so at a time. I usually play with the guitar going over my right knee. Is my posture wrong? This used to happen to me when I first started playing piano too. But the more I played, the longer I could sit without back pain.
You're probably tensing up without knowing it. Most sitting positions involving the guitar on the right knee have this. Try the classical position.