As the poem begins, a soldier is on the retreat. He and his companions have suffered a "loss severe," badly losing a battle, and only a "sullen remnant" (a few gloomily silent survivors), "hard-prest" and exhausted, remain. They're marching through dark woods on a "road unknown," going who knows where.
Notably, they're doing all of this in the present tense. Using his customary long, swinging lines of free verse, Walt Whitman puts readers right in the moment with this soldier, tracking his progress on what will turn out to be one of the more terrible nights of his life.
Whitman usually wrote in his own voice, but this poem is a story told by a character. It's based on real events observed by a real person, a wounded soldier named Milton Roberts whom Whitman met while he was volunteering in military hospitals during the American Civil War. There's a documentary quality here: Whitman is making a record of the real-life horrors of his era.
In these first lines, though, this poem feels as if it could take place during any war, anywhere—or as if it could be a sinister fairy tale, for that matter.
As the soldiers make their way through dark woods at midnight—so far, so mythic!—they at last encounter a "glimmer" of light. Not much of it, though: they see only the "lights of a dim-lighted building." They find that building in a clearing in the woods and stop there.
Listen to the way the speaker uses epistrophe here:
Till after midnight glimmer upon us the lights of a dim-lighted building,
We come to an open space in the woods, and halt by the dim-lighted building,
This gloomy building, the repetition suggests, is going to be important. It's also ominous. A few dim lights don't promise much warmth and comfort for a band of exhausted marchers. The retreating soldiers, readers might already suspect, aren't in for anything good in there.