VSTGUI4 and pure opengl editor

I am looking into porting our plugin to VST3 and I would like to use VSTGUI to get a platform independent editor window where I can draw with pure OpenGL (maybe NanoVG).
I just need OpenGL functions, mouse and keyboard events. (No UI components from XML etc.) I cannot find examples on the internet.
How do I create my editor (which class to inherit from)?
How do I use the COpenGLView?
Could you please give me some pointers?

Hi,
for this case, VSTGUI might be overkill. You just have to create a custom IPlugView implementation, where you add either a HWND or an NSView to the parent view which is provided to you in the attached call.

Cheers,
Arne

Thank you for the answer. I agree that I would only use a very small part of VSTGUI.
But if it solves the window creation, opengl library loading, file open/save dialogs, and maybe some text edit controls on both Windows and OSX then I would still use VSTGUI rather than implementing these myself.
I started inheriting from VSTGUIEditor. I don’t have it working yet and still don’t understand how COpenGLView is meant to be used.
Could you please direct me to some examples?

After experimenting I have a test GUI inherited from VSTGUIEditor and a view inherited from COpenGLView. I can have mouse and keyboard events, and I can add views like CTextEdits. I noticed that CTextEdits are covered by the COpenGLView.
I would like to add text edits on top of the opengl view. Is it possible?
vstguiopengl01.png

no, you cannot place anything atop the OpenGL view in VSTGUI.

Cheers,
Arne

Is there a way to add a bool isContextCurrent() method to IPlatformOpenGLView?

I am working with frame buffer objects, too and I need to make sure context is current many times.
Performance would benefit if there was a way to avoid calling makeContextCurrent() when the context is already current.

It would be better if you organize your code so that you don’t need to call makeCurrentContext more than needed.
There are currently no plans to add any changes to the OpenGL stuff as it is deprecated on macOS.

Cheers,
Arne

Hello,
I’m trying to create something like a COpenGLView in google ANGLE so we have true cross-platform.
I’ve looked through all vst3sdk and couldn’t find any example on how to use copenglview.
Despite it being “old technology”, could you please share a simple working example so I can learn how I need to design the interface?
A simple triangle for shader would suffice 100%.

@Arne_Scheffler if you could share some simple copenglview demo code, that would be a great help!
@aabyssx or even what you showed in the image would do just fine!

class TestOpenGLView : public COpenGLView, public Animation::IAnimationTarget
{
public:
	TestOpenGLView (const CRect& size) : COpenGLView (size) {xRotation = yRotation = zRotation = 0.f;}

	bool attached (CView* parent)
	{
		if (COpenGLView::attached(parent))
		{
			updateViewPort ();
			remember ();
			addAnimation("XRotation", this, new Animation::RepeatTimingFunction (new Animation::LinearTimingFunction (4000), -1, false));
			remember ();
			addAnimation("YRotation", this, new Animation::RepeatTimingFunction (new Animation::LinearTimingFunction (6000), -1, false));
			remember ();
			addAnimation("ZRotation", this, new Animation::RepeatTimingFunction (new Animation::LinearTimingFunction (8000), -1, false));
			return true;
		}
		return false;
	}

	bool removed (CView* parent)
	{
		return COpenGLView::removed (parent);
	}
	
	void setViewSize (const CRect& rect, bool invalid = true)
	{
		COpenGLView::setViewSize (rect, invalid);
		updateViewPort ();
	}
	
	void parentSizeChanged ()
	{
		COpenGLView::parentSizeChanged ();
		updateViewPort ();
	}

	void updateViewPort ()
	{
		if (platformOpenGLView)
		{
			platformOpenGLView->lockContext ();
			platformOpenGLView->makeContextCurrent ();

			glEnable (GL_DEPTH_TEST);
			glEnable (GL_BLEND);
			glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

			CRect r (getViewSize ());
			glViewport (0, 0, r.getWidth (), r.getHeight ());

			glClearColor (0, 0, 0, 0);

			platformOpenGLView->unlockContext ();
		}
	}
	
	void drawOpenGL (const CRect& updateRect)
	{
		glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		
		glMatrixMode (GL_PROJECTION);
		glLoadIdentity ();
		glMatrixMode (GL_MODELVIEW);
		glLoadIdentity ();

		glScaled (0.5, 0.5, 0.2);
		glRotated (xRotation, 1, 0, 0);
		glRotated (yRotation, 0, 1, 0);
		glRotated (zRotation, 0, 0, 1);

		glBegin(GL_TRIANGLES); 

			glColor4f  (0.0f,0.0f,1.0f, 0.5f);
			glVertex3f ( 0.0f, 1.0f, 0.0f);
			glVertex3f (-1.0f,-1.0f, 1.0f);
			glVertex3f ( 1.0f,-1.0f, 1.0f);

			glColor4f  (1.0f,0.0f,0.0f, 0.5f);
			glVertex3f ( 0.0f, 1.0f, 0.0f);
			glVertex3f ( 1.0f,-1.0f, 1.0f);
			glVertex3f ( 1.0f,-1.0f, -1.0f);

			glColor4f  (0.0f,1.0f,0.0f, 0.5f);
			glVertex3f ( 0.0f, 1.0f, 0.0f);
			glVertex3f ( 1.0f,-1.0f, -1.0f);
			glVertex3f (-1.0f,-1.0f, -1.0f);

			glColor4f  (1.0f, 1.0f, 0.0f, 0.5f);
			glVertex3f ( 0.0f, 1.0f, 0.0f);
			glVertex3f (-1.0f,-1.0f,-1.0f);
			glVertex3f (-1.0f,-1.0f, 1.0f);

		glEnd();

		glBegin (GL_QUADS);
			glColor4f (0.5f, 0.5f, 0.5f, 0.9f);
			glVertex3f (-1.f, -1.f, 1.f);
			glVertex3f (1.f, -1.f, 1.f);
			glVertex3f (1.f, -1.f, -1.f);
			glVertex3f (-1.f, -1.f, -1.f);
		glEnd ();
   
		glFlush ();

		platformOpenGLView->swapBuffers ();
	}
protected:
	virtual void animationStart (CView* view, IdStringPtr name) {}
	virtual void animationTick (CView* view, IdStringPtr name, float pos)
	{
		if (strcmp (name, "XRotation") == 0)
			xRotation = pos * 360.f;
		else if (strcmp (name, "ZRotation") == 0)
			zRotation = pos * 360.f;
		else if (strcmp (name, "YRotation") == 0)
			yRotation = pos * 360.f;
		invalid ();
	}
	
	virtual void animationFinished (CView* view, IdStringPtr name, bool wasCanceled) {}

	float xRotation;
	float yRotation;
	float zRotation;
};

FINALLY, I’ve managed to make your example work.
I was a bit lost as for the necessary includes and how to get the platformOpenGLView.
I want to thank you very much @Arne_Scheffler for providing it.
I’ll leave the repo here so anyone looking for a COpenGLView example will be able to find it.

You can expect a fully working ANGLE view from me in 3-8 years approximately :smiley: