When you fly into Johannesburg, solar panels seem to gleam everywhere, from the roofs of mansions and small township homes alike.

But those glittering 21st-century panels mask South Africa's dependence on a dirty 19th-century energy source: coal.

Like many developing countries, South Africa is struggling to meet growing energy needs yet avoid deepening Earth's carbon crisis -- one of the many dilemmas besetting the UN climate talks, which resume in Glasgow on October 31.

South Africa's continuing addiction to coal has to be seen in the context of rolling blackouts that have been a part of life since 2007.

Schedules for power cuts are shared on apps and in news reports, along with quotidian news like weather and traffic jams.

Coal dependence: Rooiwal power station on the outskirts of hte South African capital Pretoria
Coal dependence: Rooiwal power station on the outskirts of hte South African capital Pretoria AFP / Michele Spatari

"As a young South African I am scared," environmental activist Ditebogo Lebea said during a webinar organised by the think-tank South African Institute of International Affairs. "Our country is facing an energy crisis that needs urgent attention."

The power cuts are a headache for residents and disastrous for businesses, undermining efforts to bring down a 34 percent unemployment rate.

When the crisis first erupted, entire cities were unexpectedly plunged into darkness, prompting angry finger-pointing.

The government sifted through every conceivable solution to try to resolve the problem.

Steep discounts -- up to 100 percent -- were offered for homes to adopt solar water heating. Wind farms sprouted up. A desert blossomed into Africa's largest solar farm.

But the country also decided to build not one, but two gargantuan coal-powered plants, each producing about 4,800 Megawatts.

South Africa is pushing hard on solar energy but coal remains its main choice for meeting electricity needs
South Africa is pushing hard on solar energy but coal remains its main choice for meeting electricity needs AFP / GIANLUIGI GUERCIA

Operating as a unit, they will form the biggest coal power complex in the world, topping even China's massive coal expansion.

By comparison, the solar farm produces 50 megawatts of power.

The first new plant has come online in fits and starts, dogged by design flaws and corruption at the state power company Eskom. The second is still under construction.

Coal already provides 80 percent of South Africa's power, making it the world's 12th largest greenhouse gas emitter in 2019, according to Global Carbon Atlas.

South Africa's energy crisis is a major political issue
South Africa's energy crisis is a major political issue AFP / Phill Magakoe

Yet South Africa enjoys 2,500 hours of sunshine per year on average -- around 600 more than solar power champion Germany.

"Everyone acknowledges renewable energy is a massive opportunity in South Africa," said energy analyst Argon Poorum of the non-profit GreenCape.

The country has tried to tap that opportunity.

In 2010, South Africa launched an avant-garde renewable power auction system to attract private investors.

Five years later, Eskom unexpectedly pulled the plug, claiming renewable power was too pricey.

Chaos in energy policy was fuelled by former president Jacob Zuma, who took office in 2009.

He tossed out solar plans and tried to negotiate a back-channel, one-trillion-rand (67-billion-dollar) nuclear energy deal with Russia.

That plan was thwarted by activists, the opposition and a rebellion within Zuma's own cabinet, but the damage was done.

Greenhouse gases rose 10 percent from 2000 to 2017, according to government figures.

Zuma's successor Cyril Ramaphosa is steering a new course. He revived the renewable energy scheme last year, and made it easier for companies to generate their own solar and wind power.

Nuclear remains part of the mix, and three licences have been approved for floating power plants that use natural gas,a fossil energy that is far more fuel-efficient than coal.

Eskom has meanwhile set out to gradually decommission old coal plants over the next three decades, aiming to balance the new plants' emissions.

Coal retains some political heft. Energy Minister Gwede Mantashe has championed controversial "clean coal" technologies, partly to retain badly needed mining jobs, in a sector that overall employs around 500,000 people, according to latest official figures.

But the government is hoping to secure financing at COP26 to finance Eskom's migration away from coal.

One goal of the conference is to get rich nations to follow through on pledges to raise at least 100 billion dollars a year to help developing countries shift to green energy.

South Africa wants a slice of that money, which could go a long way toward filling gaps in domestic funding.

"We have left it too late," said energy expert Chris Yelland. "But better late than never."