A 21-year-old man accused of firing a semiautomatic rifle at the White House last week has been formally charged with attempting to assassinate President Obama or members of his staff.

Oscar Ramiro Ortega-Hernandez, of Idaho Falls, Idaho, will be tried in federal court in Washington, D.C., federal officials said.

If convicted, Ortega-Hernandez could face life in prison.

Law enforcement agents have been investigating whether Ortega-Hernandez -- accused of firing at least two bullets at the White House -- acted out of hatred for Obama, according to published reports.

President Obama, who is on a trip to the Asia-Pacific region, was not home at the time of the shooting.

Ortega-Hernandez, arrested Wednesday near Pittsburgh, made his first court appearance today in that city.

"Ortega sat quietly as the hearing began, his hands free but his feet shackled," reported the Associated Press. "The 21-year-old said only, 'Yes, ma'am' when he was asked if he understood that he would be going back to Washington to face the charge."

Added the AP:

Authorities said a man clad in black who was obsessed with Obama pulled his car within view of the White House on Friday night and fired shots from an assault rifle, cracking a window of the first family's living quarters while the president was away. Soon after, U.S. Park Police found an abandoned vehicle, with an assault rifle inside it, near a bridge leading out of the nation's capital to Virginia. The car led investigators to Ortega. The FBI took custody of Ortega's car Thursday afternoon to continue the process of reviewing evidence, said Lindsay Godwin, a spokeswoman for the FBI's Washington field office.

Police in Pennsylvania arrested Ortega-Hernandez on suspicion of firing a semiautomatic rifle at the White House on Friday night, with one bullet striking a bulletproof window in the residential part of the building.

The Secret Service reported that one bullet struck an upstairs window on the south side of the White House -- the residential portion of the building -- but was stopped by bulletproof glass.

Another bullet struck the exterior of the building, though the service has not said exactly where.

This has all taken place since Obama left for a nine-day trip to Hawaii, Australia and Indonesia.

The Washington Post reported: