Oedipus Rex has a dark and foreboding mood, as one might expect of an ancient Greek tragedy. From the discussion of the plague that begins the play to Jocasta's suicide and Oedipus' self-blinding, woeful subject matter dominates. Sophocles includes detailed descriptions of the darkest moments of the story, intentionally dwelling on the most visceral and even gory elements. It is not just the subject matter that contributes to the mood, then, but the way Sophocles highlights these horrifying moments.
The play's themes of guilt and shame, as well as free will versus fate, further work to create a mood of despair and sadness. After all, in some sense there was nothing Oedipus could do to avoid his grisly fate. Furthermore, Sophocles's use of foreshadowing and dramatic irony create a sense of dread in the reader as they can see the ending of the play coming while Oedipus is still blind to it. This swell of dread as Oedipus comes closer and closer to figuring out the truth makes the climax more powerful while also contributing to the play's serious and melancholic mood. Because Oedipus's fate is foreshadowed quite early in the story, there is a backdrop of misery even as Oedipus remains hopeful that he can help the city of Thebes.