1Here are the rules to use OpenGL in your plug-in:
2
3- If your plug-in is going to use OSMesa to handle CPU rendering, you need to ensure you are not going to call regular OpenGL functions but the one provided by mesa. In that case, it's very simple, just:
4
5    #include <ofxsGLFunctions.h>
6
7and then in the code prefix every gl function call by either **GL_CPU** to use OSMesa or **GL_GPU** to use regular OpenGL, e.g:
8
9    GL_CPU::glBegin(GL_POINTS);
10    GL_CPU::glVertex2d(50., 50.);
11    GL_CPU::glEnd();
12
13If you have code that will be executed both in OSMesa code path and OpenGL code path, you can template your functions so that the same code is used:
14
15    template <typename GL>
16    void myCrossPlatformPoint()
17    {
18        GL::glBegin(GL_POINTS);
19        GL::glVertex2d(50., 50.);
20        GL::glEnd();
21    }
22
23Functions used by GL_CPU will be available only if HAVE_OSMESA is defined otherwise they will point to NULL.
24
25- If your plug-in is just going to use regular OpenGL for it's rendering or for interacts and does not need OSMesa at all, you may use directly
26
27    #include <glad.h>
28
29- Either way, you must include
30
31    #include <ofxsOGLUtilities.h>
32
33and you must initialize the OpenGL functions at least once using the function OFX::ofxsLoadOpenGLOnce(). To do so, an OpenGL context must be bound by the host application, so you can only do that in 2 different places:
34
35    * For overlay interacts, you can do it in the draw action
36    * For OpenGL render plug-ins, you can do it in the contextAttached function
37
38The function *ofxsLoadOpenGLOnce()* is thread-safe and will do the work only once.
39
40
41Note that in that case you don't need to prefix your gl calls by **GL_GPU** you will directly use the functions loaded by GLAD. Using the **GL_GPU** prefix would just require 1 function pointer dereference which is slower than calling the function directly.
42
43
44Warning: It is very important that you DO NOT mix environments with glad.h functions or ofxsGLFunctions.h or directly by including gl.h. Make sure that only one of them is included in your code.
45
46