Printing display area to printer

We are designing a drafting type program and need to be able to print the DirectX display area.  Not only the current clipped region (or current visible camera area).

I was thinking about creating a hidden display area that is much larger and have my app draw to that device area and then printing it (since they may print on 11x17 paper), but was unsure about memory issues (since many of the laptop users have 32Mb graphics cards).

Essentially, I need to print the scanned in blueprint that they have updated with walls drawn in our app.

Any help would be greatly appreciated!



Answer this question

Printing display area to printer

  • Marc.

    at a guess, maybe you could render the whole thing offscreen

    then have each rendered to file

    sorry this is a pure guess but i thought its better than nothing


  • Dave Westhead

    If you wanted to draw something that big you'd definately blow your memory requierments in a hurry. Raster buffers take quite a bit of memory, plus you have to keep in mind that the video card also needs to create a depth buffer and possibly other supporting structures. Even if this fits next to your screen buffers, you may end up leaving insufficient memory for textures. A full-resolution render is almost certainly not an option, in my opinion.

    If you've got a full-shaded view, I'd go via this route:

    1. Use an orthographic projection (I assume you're already doing this since you mention that this is a drafting program).
    2. Find out what your final resolution needs to be (basically the dimensions of the page multiplied by your target dpi, possibly multiplied by some fudge factor) and split this into small rectangles.
    3. Create an off-screen render target as big as one of these rectangles. If you really need to conserve video memory you can reuse your screen buffers (if you're double-buffering, use the back buffer but don't Present it onto the screen while printing).
    4. For each rectangular region, set up the camera to render exactly that region and render the region. Then capture the resulting image into a GDI bitmap.
    5. Move the camera back to where it was when you started printing. If you created a new render target to do this then be sure to delete that too, unless you print very often, in which case cache it for future use.
    6. Spawn off another thread to do the actual printing from the bitmaps, and have it delete them as it's finished with them.

    This will render quickly, however it will print slowly as all of the data will be in high-res bitmap format. If all you're printing is a wireframe, then I'd recommend taking all of your geometry, transforming the vertices yourself in software, Z-sorting the lines (if you find that necessary) and then using this data to draw lines directly onto the printer's GDI DC, or GDI+ Graphics object (whichever you're using). This will allow the printer driver to send a much more compact command stream to the printer which will get it printing much faster and could make all the difference between a successful print and a backed up (and likely crashed) print server.

    I hope I've given you enough to get started.

    Phill


  • Printing display area to printer