今天我摆脱了对 OpenTK 的依赖;我的应用程序不再依赖 OpenTK 来创建 OpenGL 上下文。但是,在 Mesa 3D(OpenGL 的软件渲染实现)中运行时,我的代码不再能够正常运行;我的代码运行,但 FPS 大约为 0.001 FPS(相比之下,使用 OpenTK 的上下文创建大约为 16+FPS)并且通常绘制到 FBO 的内容显示在窗口上,因为它是由组成的。尽管在没有 Mesa 3D 的情况下运行我的代码会产生正常的性能(在 Windows 7 上),但我担心它运行良好可能只是巧合。glGetError
检查显示没有错误,这让我觉得我在创建上下文时可能做错了什么?
m_controlHandle = m_winForm.Handle; /* HWND */
m_controlDC = Win32.GetDC(m_controlHandle); /* HWND's DC*/
Win32.PixelFormatDescriptor pixelFormat = new Win32.PixelFormatDescriptor();
pixelFormat.Size = (short)Marshal.SizeOf(typeof(Win32.PixelFormatDescriptor));
pixelFormat.Version = 1;
pixelFormat.Flags =
Win32.PixelFormatDescriptorFlags.DRAW_TO_WINDOW |
Win32.PixelFormatDescriptorFlags.SUPPORT_OPENGL |
Win32.PixelFormatDescriptorFlags.DOUBLEBUFFER;
pixelFormat.PixelType = Win32.PixelType.RGBA;
pixelFormat.ColorBits = 32;
pixelFormat.DepthBits = 0; /* yes, I don't use a depth buffer; 2D sprite game */
pixelFormat.LayerType = Win32.PixelFormatLayerType.MAIN_PLANE;
int formatCode = Win32.ChoosePixelFormat(m_controlDC, ref pixelFormat);
if (formatCode == 0)
throw new Win32Exception(Marshal.GetLastWin32Error());
if (!Win32.SetPixelFormat(m_controlDC, formatCode, ref pixelFormat))
throw new Win32Exception(Marshal.GetLastWin32Error());
m_openGLContext = Win32.wglCreateContext(m_controlDC);
if (m_openGLContext == IntPtr.Zero)
throw new Win32Exception(Marshal.GetLastWin32Error());
if (!Win32.wglMakeCurrent(m_controlDC, m_openGLContext))
throw new Exception("Could not wglMakeCurrent.");
这个对吗?有什么建议可以追踪可能导致 Mesa3D 突然发疯的原因吗?