Printing 如何打印OpenTK(OpenGL)或更改设备上下文?

Printing 如何打印OpenTK(OpenGL)或更改设备上下文?,printing,opentk,Printing,Opentk,使用OpenTK/OpenGL,我可以很好地在Winforms上绘图。 但是我如何在打印机上绘图呢 我在一个应用程序上工作,并使用这段代码进行打印,但我不确定如何让设备上下文进入GLControl private void print_click(object sender, EventArgs e) { dialog.Document = new PrintDocument(); using (var dialog = new PrintDialog()) {

使用OpenTK/OpenGL,我可以很好地在Winforms上绘图。 但是我如何在打印机上绘图呢

我在一个应用程序上工作,并使用这段代码进行打印,但我不确定如何让设备上下文进入GLControl

private void print_click(object sender, EventArgs e)
{
    dialog.Document = new PrintDocument();
    using (var dialog = new PrintDialog())
    {
        if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            dialog.Document.BeginPrint += new System.Drawing.Printing.PrintEventHandler(Document_BeginPrint);
            dialog.Document.EndPrint += new System.Drawing.Printing.PrintEventHandler(Document_EndPrint);
            dialog.Document.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(Document_PrintPage);
            dialog.Document.Print();
        }
    }
}

void Document_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    // This code does not work!
    // something to do with e.Graphics.GetHdc() ???
    var nullWindow = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(IntPtr.Zero);
    // Exception of type 'OpenTK.Graphics.GraphicsContextException' was thrown.
    var printcontext = new OpenTK.Graphics.GraphicsContext(new ContextHandle(e.Graphics.GetHdc()), nullWindow);
    printcontext.MakeCurrent(nullWindow);
    // GL.Begin(...)
    // ...
    // GL.End()
    // printcontext.SwapBuffers()? Should be single-buffered?
}

void Document_EndPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{

}

void Document_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{

}

我还注意到了
OpenTK.Graphics.GraphicsContext(ContextHandle句柄,IWindowInfo窗口)
构造函数,但我不确定IWindowInfo应该放什么。

我刚刚考虑的一个解决方法是拍摄渲染图像的位图快照,像这里一样

问题在于,它不能根据不同的文档大小自动缩放。