Opengl component in audio plugin


#1

Hi,

I’m trying to get a simple OGL renderer running in plugin window (editor), everything compiles and runs fine, except the OGL component doesn’t seem to be redrawing consistently. I can force the component to redraw by switching to another window, and then back to draw a single frame. I do know for a fact that renderOpenGL is getting called on the timer interval.

Please take a look at the code below and let me know if you see anything that I’m doing wrong. Also I’m using the latest source as of about 2 days ago, and I’m compiling via Xcode. This is happening with both plugins (VST and AU) in Ableton Live.

Any help at all would be appreciated as this is absolutely killing me!!!

-Ellis


////////////////////////////////////////////////////////////////////////////////

struct OglComponent : OpenGLComponent, Timer
{
	OglComponent() : OpenGLComponent()		
	{
		startTimer(16);
	}
	~OglComponent()							
	{}

	virtual void timerCallback()			
	{
		repaint();
	}	
	virtual void renderOpenGL()
	{
                // simplified version of my actual code, but still I should see a black screen...
		glClearColor(0, 0, 0, 0);
		glClear(GL_COLOR_BUFFER_BIT);
	}
	virtual void newOpenGLContextCreated()	
	{}
};

////////////////////////////////////////////////////////////////////////////////

struct OglEditor : AudioProcessorEditor
{
	OglComponent* _ogl;

	OglEditor(OglAudioProcessor* ownerFilter)
	{
		setSize(480, 320);
		setVisible(true);

		_ogl = new OglComponent();
		_ogl->setSize(getWidth(), getHeight());	
		addAndMakeVisible(_ogl);
	}
	~OglEditor()
	{
		deleteAllChildren();
	}

	OglAudioProcessor* getProcessor() const
	{
		return (OglAudioProcessor*)getAudioProcessor();
	}
};

////////////////////////////////////////////////////////////////////////////////

#2

Hey Ellis, in your timerCallback change from using repaint to…

renderAndSwapBuffers()

And for good measure move your startTimer() to

void newOpenGLContextCreated()
{
startTimer();
}

This way you don’t start rendering until the context is created and ready for you


#3

Works perfectly, thank you!!