Printing in logical units (e.g.1 Unit = 1 mm)

We are trying to allow user to define how long does 1 OpenGL unit will be on print.
For example user will choose 1 OpenGL logical units to be shown as 1 mm on print.

I have seen nearly all the printing examples on web, including the most complex one that renders to a memory DC which has a limited size, then sends it to printer. The main problem is we can not set how long will a logical unit will be printed on paper.

First you have to find out in what resolution you are printing and how big the whole image will be on paper.

Lets assume you are printing a 10 cm by 10 cm image with 300 dpi.

300 dpi is 300 pixels per inch, that is about 118.1 pixels per cm (one inch is 2.54 cm), this gives us an image width and height of 1181 pixel. This value should be used at the viewport transformation.

If you like an orthogonal projection, the rest is easy. Just set up the projection with the width and height of the image in whatever unit you want. For example, when you call glOrtho(-50, 50, -50, 50, near, far), an OpenGL unit will be equal to a mm (the image width and height is 100 mm).

For a perspective projection things are a bit more complicated, because an OpenGL unit is not always equally sized, its size depends on the distance from the camera. You can calculate your values with a simple trigonometric calculation, assuming that the full image size is always 100 mm (in my example):

tan(fov/2) = imagesize / (2*camera distance)

As a simple example, at a fov of 90 (tan(45) = 1) and a distance of 50 OpenGL units from the camera, the the image size will be 100 OpenGL units, so at this distance one OpenGL unit equals one mm.

I hope this helps

This is entirely dependent on your printer driver API, rather than on OpenGL. Thus, I suggest you go look at the API for printing on whatever platform you’re using.