The vast majority of my practice is in State courts. Most of the time the officers and troopers who come to court to testify know they are going to see (and be seen by) the same judges, prosecutors, and defense attorneys over and over and over again. As such, it is usually in their best interest not to deviate too far from the truth too often. It just makes sense and all but a small number seem to get it. Nevertheless, some few don't and when an officer gets a reputation for not being truthful he quickly becomes less effective in court.
There are signs. Other officers will not corroborate first officer's version of the events. Officer2 won't say the Officer1 is being untruthful. However, Officer2 "didn't hear the confession because he was out of earshot", "was at the other end of the car with the another suspect during Officer's search of the suspect", or was "calling dispatch when Officer1 got permission to search the car." Prosecutors start trying to call other officers who were at the scene rather than Officer1 and sometimes just stop asking him questions when he's in the middle of his testimony (usually after an amazingly juicy bit of testimony). And you can really tell when a judge catches on. I've seen judges who never doubted an officer before suddenly start asking if there was a recording of the statements against interest and finding people not guilty in swearing matches with a particular officer (around here nobody wins a swearing match with an officer). I've seen judges focus in on incredibly minor errors in the prosecution's case and dismiss (rather than taking judicial notice or reopening for correction). I've seen judges dismiss on minor technicalities for which I'd be laughed at if I argued for dismissal based upon them.
However, much as Mike points to in federal court, I've never actually seen a judge bluntly tell an officer that he is lying. But that doesn't mean that anyone in the courtroom, including the officer, doesn't understand what just happened.