Are you using glGetError after every function when you say you're getting GL_INVALID_ENUM everywhere? The error doesn't clear until you call glGetError, so if you called 100 functions before calling glGetError the error could be for any one of the 100 functions. If so, it's probably only the first GL_INVALID_ENUM that matters since the others are likely just ripple effects.
The code you provided is way too long for me to try to debug without being able to compile and run it, so knowing which OpenGL call is the first one to generate an error would really help focus on a small enough amount of code to be manageable.
Also, it appears GL_RGB is a valid internal format for glTexImage2D since it's in table 1. People do normally use sized or compressed formats though.