PDA

View Full Version : Printing in logical units (e.g.1 Unit = 1 mm)



eymre
07-19-2003, 02:12 AM
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.

eymre
07-19-2003, 02:26 AM
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.

Overmind
07-19-2003, 03:29 AM
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
Overmind

jwatte
07-19-2003, 12:11 PM
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.