CocoaDev

Edit AllPages

Question: How do I print an NSOpenGLView ?

Answer: OpenGL is NOT device independent. OpenGL drawing always effects a pixel buffer/bitmap. There is no easy or straight forward way to translate OpenGL drawing into vector commands to a printer or any other non-pixel-buffer type of device.

There are several options:

1) Use OpenGL to draw into a bitmap of suitable size/resolution and just print the bitmap.

2) Convert OpenGL drawing commands into device independent drawing commands like PDF, Postscript, or Quartz 2D. However, the printed output will not look exactly like the screen version [no WYSIWYG]

3) Write your own drawing API that uses OpenGL for pixel buffer drawing and something else for all other devices.

4) Use someone else’s API that uses OpenGL for pixel buffer drawing and something else for all other devices.

I always say it like this:

I have never seen very satisfactory printed output from OpenGL particularly when alpha channels, lighting, fog, stencil buffers, etc. are used. It is hard to do better than a screen shot printed at an appropriate DPI. glReadPixels() can be used to get the pixels buffer contents from an NSOpenGLContext.