Hello, I'm using Solidworks 2016, the Solidworks C# addin template, and OpenTK.
I am having a problem when attempting to render anything programmatically with OpenGL in Solidworks. I have run into several conflicting statements regarding rendering what I want in the window.
Tony Van De Velde is attempting to use VBOs to render using the ModelView.BufferSwapNotify event handler. He initially is able to render using OpenGL's Immediate Mode, but finds that rendering VBOs needs to happen in the event handler so that it may be rendered after Solidworks Layer0 which is the part/assembly graphical output.
Source 2: Help me about OpenGL!
Lenny Yang is attempting to draw into SolidWorks using the OpenGL interface in Visual Basic. Several other questions are asked and answered regarding the context used to draw in. The answer by Artem Taturevych is vague regarding why we should ignore what the API documentation recommends using for drawing to the context.
I currently am getting visible OpenGL renderings when I draw using the following code:
|// in EventHandling.cs|
public class DocView
private GLControl glControl;
public DocView(SwAddin addin, IModelView mv, DocumentEventHandler doc)
glControl = new GLControl(); // Program does not work without this
public bool AttachEventHandlers()
mView.DestroyNotify2 += new DModelViewEvents_DestroyNotify2EventHandler(OnDestroy);
mView.RepaintNotify += new DModelViewEvents_RepaintNotifyEventHandler(OnRepaint);
mView.BufferSwapNotify += OnBufferSwapNotify;
public bool DetachEventHandlers()
mView.DestroyNotify2 -= new DModelViewEvents_DestroyNotify2EventHandler(OnDestroy);
mView.RepaintNotify -= new DModelViewEvents_RepaintNotifyEventHandler(OnRepaint);
mView.BufferSwapNotify -= OnBufferSwapNotify;
public int OnBufferSwapNotify()
Note the green highlighted lines. The program does not run without them. What they do is set an OpenGL context and then release the context. I'm not understanding what context I'm drawing into since the program does not run without first setting a custom context but then releasing it.
My question: Why does drawing to the context work like this? Which GL context should I aim to draw to?
I'm not sure what's going on but I am getting renderings with whatever shading was available prior to the event handler drawing. I want to know why this is possible and why I should be ignoring what the API documentation says since that doesn't seem to work when I try to mimic it.
Maybe I'm misunderstanding what I need to be rendering with the InitializeShading method? Should I draw the vertices prior to calling InitializeShading and then set the lighting/textures after?
Any help is appreciated.
Message was edited by: Daniel Mansour Reason: Cleaned formatting of code. Made question more specific.