I'm getting a GraphicsContextMissingException. What is this and what does it mean? What exactly is a graphics context?
I have a data collection class which contains a form to visualize the data. As the data is collected it sends the data to its form which converts the data into color data and then is supposed to render it. But when I call the visualization form's update data and render command:
Public Sub render() GL.ColorPointer(3, ColorPointerType.Double, 0, colorArray) GlControl1.Invalidate() End Sub
I get the exception when setting the color pointer. I don't understand what's going on because the form with the glcontrol initializes just fine and the initialization routine contains a GL.colorPointer call. The data collection class initializes and displays the form without any issues but when the ColorPointer function is called again, I get "No context is current in the calling thread" The subroutine which collects the data (which is in the data collection class) and sends it to the visualization form is executed on a separate thread from the main program. Here's my paint subroutine:
Private Sub GlControl1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles GlControl1.Paint If Not loaded Then Return End If Dim rand As New Random() GL.Clear(ClearBufferMask.ColorBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadIdentity() GL.DrawArrays(BeginMode.Points, 0, imageHeight * imageWidth) GlControl1.SwapBuffers() End Sub
And here are my initialization subroutines:
Public Sub New(ByVal width As Double, ByVal height As Double, ByVal xmin As Double, ByVal ymin As Double, _ ByVal xstep As Double, ByVal ystep As Double) InitializeComponent() Me.imageHeight = height Me.imageWidth = width ... ... End Sub Private Sub ScanVisualizer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load loaded = True fillVertexArray() initializeColorArray() GL.ClearColor(Color.Black) GlControl1.VSync = True GL.VertexPointer(2, VertexPointerType.Double, 0, vertexArray) GL.ColorPointer(3, ColorPointerType.Double, 0, colorArray) GL.EnableClientState(EnableCap.VertexArray) GL.EnableClientState(EnableCap.ColorArray) SetupViewport() GL.Disable(EnableCap.DepthTest) End Sub Private Sub SetupViewport() Dim w = GlControl1.Width() Dim h = GlControl1.Height() GL.MatrixMode(MatrixMode.Projection) GL.LoadIdentity() GL.Ortho(0, imageWidth, imageHeight, 0, 0, 1) 'define clipping planes GL.Viewport(0, 0, w, h) 'Use all of the glControl painting area End Sub
(For those of you who put up with my previous question, yes I'm still using a bunch of points to display a 2d image because I decided to keep it this way because eventually, I'm going to turn this into a 3d image once I get the basic structure working)
I apologize for this question but I couldn't find any satisfactory explanation for what a graphics context is and what this exception means on the internet. Thanks for your help.