Ich versuche gerade einen OpenGL Context zu erstellen, dazu verwende ich folgendes:
MakeCurrent und Blit sehen folgendermaßen aus:
Bei jeden neuen Frame rufe Ich MakeCurrent auf, und nach allen Draws dann Blit. Aber alles was ich erhalte ist ein Schwarzer Hintergrund, keiner der OpenGL Calls ist erfolgreich. Habe ich einen Fehler bei der Kontexterstellung gemacht? Eigentlich muss der Fehler ja hier liegen..
C#-Quellcode
- _windowHandle = windowHandle;
- Width = width;
- Height = height;
- _deviceContext = NativeMethods.GetDC(windowHandle);
- var pixelFormatDescriptor = new NativeMethods.PIXELFORMATDESCRIPTOR();
- pixelFormatDescriptor.Init();
- pixelFormatDescriptor.nVersion = 1;
- pixelFormatDescriptor.dwFlags = 37u;
- pixelFormatDescriptor.iPixelType = 0;
- pixelFormatDescriptor.cColorBits = (byte)bitDepth;
- pixelFormatDescriptor.cDepthBits = 16;
- pixelFormatDescriptor.cStencilBits = 8;
- pixelFormatDescriptor.iLayerType = 0;
- int iPixelFormat;
- if ((iPixelFormat = NativeMethods.ChoosePixelFormat(_deviceContext, pixelFormatDescriptor)) == 0)
- {
- throw new RenderDeviceException("Unable to initialize NativeRenderContext.");
- }
- if (NativeMethods.SetPixelFormat(_deviceContext, iPixelFormat, pixelFormatDescriptor) == 0)
- {
- throw new RenderDeviceException("Unable to initialize NativeRenderContext.");
- }
- _renderContext = NativeMethods.wglCreateContext(_deviceContext);
- MakeCurrent();
MakeCurrent und Blit sehen folgendermaßen aus:
C#-Quellcode
- /// <summary>
- /// Makes the render context the current context.
- /// </summary>
- public void MakeCurrent()
- {
- if (_renderContext != IntPtr.Zero)
- {
- NativeMethods.wglMakeCurrent(_deviceContext, _renderContext);
- }
- }
- /// <summary>
- /// Blit the rendered data to the supplied device context.
- /// </summary>
- /// <param name="hdc">The HDC.</param>
- public void Blit(IntPtr hdc)
- {
- if (_deviceContext != IntPtr.Zero || _windowHandle != IntPtr.Zero)
- {
- NativeMethods.SwapBuffers(_deviceContext);
- }
- }
Bei jeden neuen Frame rufe Ich MakeCurrent auf, und nach allen Draws dann Blit. Aber alles was ich erhalte ist ein Schwarzer Hintergrund, keiner der OpenGL Calls ist erfolgreich. Habe ich einen Fehler bei der Kontexterstellung gemacht? Eigentlich muss der Fehler ja hier liegen..