[Solved] OpenGLContext - Flickering when resizing window

If you see flickering when you resize the window, you can try this:

class MainWindow : public DocumentWindow, private Timer
{
	public:
		MainWindow (String name) : DocumentWindow (name, juce::Colours::lightgrey, DocumentWindow::allButtons)
		{
			startTimer(100);   // to avoid white flickering when starting the application
		}

		void timerCallback()   // to avoid flickering when resizing the window
		{
			_openGLContext.attachTo(*getTopLevelComponent());
			stopTimer();
		}

		void resized() override
		{
			_openGLContext.detach();   // to avoid flickering when resizing the window
			DocumentWindow::resized();
			startTimer(100);   // to avoid flickering when resizing the window
		}

I hope it helps somebody.

1 Like

This is definitely a good fix - but perhaps it would be better applied to the resized() call stack within the JUCE framework itself, so it becomes a standard handling for those using OpenGL … ?