Improved portability

Removed glPushAttrib/glPopAttrib calls from DrawToImage. The calls are
replaced with saving and restoring the viewport.
Added some alternative code for glGetTexImage.