0
有了OpenTK/OpenGL,我可以將Winforms全部用於繪製。 但是,如何在打印機上繪圖?如何打印OpenTK(OpenGL)或更改設備上下文?
我曾在ganttchart上使用這段代碼進行打印,但我不確定如何獲取設備上下文以進入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 handle, IWindowInfo window)
構造函數,但我不知道要放什麼東西了IWindowInfo。
的問題是,它不與不同文檔尺寸自動縮放。 – Jake 2013-03-25 11:27:46