The stars are used to meeting in major finals, but were taking part in an exhibition match in front of 11,000 fans in Glasgow’s SSE Hydro for Andy Murray Live tonight.
Murray was delighted to have the 19-time grand slam champion supporting the event and treated him to traditional Scottish products ahead of the game.
Federer took to Twitter to post a picture of a biscuit tin with a note reading “Andy’s granny’s homemade shortbread” and an open can of Irn Bru.
He wrote: “Can’t get a warmer welcome than this. Thanks @andy_murray ... is this your usual pre-match routine?”
Murray replied: “Yea that’s a good start but try a deep fried Mars bar on top of that and you’ll be properly ready @rogerfederer.”
Earlier the Swiss player posted pictures of the Scottish countryside as he flew into Glasgow with a caption reading: “In Glasgow for the evening to play in @andy_murray’s charity match.
“Scotland is beautiful even from the air!”
Murray has not played since July due to a hip injury, but was determined to perform in front of a home crowd in the charity event.
He joked that it could be the first time he will have more crowd support than Federer, but the Swiss player said: “I remember the Olympic Games (London 2012), so don’t forget that one.
“It’s an absolute pleasure to play Andy here. We’ve had some epic matches over the years in the biggest places, so to play in his backyard for a good cause is wonderful.”
Federer was presented with a picture of himself as a child wearing a Scotland football strip and tried to gain some extra support from the Glasgow crowd.
He said: “This is from South Africa and I have no idea why I got it, but you can say I was always a Scotland fan.”
The event is raising money for Unicef and Glasgow-based charity Sunny-sid3up.
More than £300,000 was raised last year at Murray’s first charity event and he hopes the support of Federer can help raise more.
He said: “It’s a big effort, Roger has a big event in a couple of days so I really appreciate him coming and we’re doing this for two great causes.
“This might be the only time that he ever plays tennis here so I really appreciate that he made it up for tonight.”
Murray fans watched the 30-year-old closely as he stepped up his preparation to return to competitive tennis in Australia at the start of next year.
Speaking before the exhibition match in Glasgow, he said: ‘’I hope I’m there. Things have been going pretty well so far in the rehab, but you just never know. You take each week as it comes.
“I’ve had setbacks and things can go quite quickly as well. I’ve been training for a few weeks now. Some days I’ve felt great and some days not so good.
“But I will come back when I’m ready and when I’m 100 per cent fit. I probably made a bit of a mistake trying to get ready for the US Open, but it was the last major of the year and I wanted to give it a go.
“And now it’s time to give my body the rest and recovery it needs. I’ll come back when I’m ready.”
Murray looked to be moving well enough during his match match with Federer, which the Swiss won on a tie-break after both men won a set 6-3.
It was not the most serious of matches. Federer played one game wearing a kilt after a light-hearted promise during an interview quickly turned to reality when a female fan appeared at the side of court and duly took one off with her coat protecting her modesty.
Murray said afterwards: “It went better than I expected. I was just really happy to be out here and it went pretty well.
“There are things I want to do better but, for a first match in four or five months, it went great.
“I felt pretty good, not perfect yet, but I’m going in the right direction.”
Federer produced a “see you Jimmy hat” for Murray to wear midway through the tie-break and declared himself impressed with his own tartan-wear.
“What impressed me was how quickly the kilt was organised,” he said.
“When I took it off I felt naked because it was nice and snug and heavy.”