Drawing to EMF file

Hi all

I need to save an OpenGL scene to a Windows Enhanced Metafile. I have managed to save to BMP and then to EMF but this won’t do the job as we need to have a scaleable image that can be opened in MS Word. Saving the OpenGL ‘commands’ to EMF works but Word doesn’t recognise OpenGL commands. I know how to do this with GDI but short of rewriting the project to use GDI this is as useful as an ashtray on a motorcycle. HELP!


P.S. Any form of ‘scaleable’ file for example SVG will do as well.

OpenGL doesn’t support EMF. And neither should you, for that matter. EMF is old and dead. Let it die.

Saving the OpenGL ‘commands’ to EMF works

How did you do that?

The only way I can think of is by using the (deprecated in 3.x) GL_FEEDBACK rendering mode, and then to parse the feedback buffer to issue necessary GDI calls as to draw the primitives into the EMF device context.

But texturing, if needed, will have to be done by yourself.

Google glRenderMode and glFeedbackBuffer.

But this almost equals the effort needed to implement your own renderer or rasterizer in GDI.

GL to postscript, pdf, svg, …

Hi guys, thanks for the replies:

>>OpenGL doesn’t support EMF. And neither should you, for that matter. EMF is old and dead. Let it die.

I appreciate the sentiment but I need a way to copy and paste an image into MS Word and have it act like a EMF. IE: with the ablity to resize the image without it distorting like a BMP or GIF would. Our users have older versions of Word and Excel so EMF though old may be the only option. BTW, what are the latest and greatest formats to use???

>> Google glRenderMode and glFeedbackBuffer.

Thanks AdrianPi, I’ll look into it. The texturing won’t be a problem as the view is of scientific data comprising of glLines and glQuads.

I’ve downloaded the PostScript code and will take a look at it.

If only the project deadline wasn’t last week :slight_smile:

Thanks again for the input

For extra credit, what does the first data field of a EMR_GLSRECORD represent? (heheh)

EMR_GLSRECORD: This record defines an enhanced metafile record generated by OpenGL functions, It contains data for OpenGL functions that scale automatically to the OpenGL viewport.

Mmmm… Interesting! :confused:

OK, but what is the first data field? How would you use it to play the metafile (provided it contains GL commands)?

Just stepping in, because of the challenge, I hazard a guess :

  • 4 bytes of the first data field is the address of the gl function (super dangerous by the way)
  • then the function parameters, but how to separate them ? maybe size first then data ?

Anyway I’d like to know the answer :slight_smile:

Good guess and mine as well ;-p

The first 4 bytes of what looks like glViewport are [113 1 5 0].

Well, we know it’s not a GLX opcode :slight_smile:

BTW, what are the latest and greatest formats to use???

To use to do what? There’s no format for passing GL rendering commands around. The closest you might get is something like SVG, but that’s specifically for 2D drawing.

  • 4 bytes of the first data field is the address of the gl function (super dangerous by the way)

EMFs actually put function pointers in their data? Man, these things really suck. Seriously, don’t use them. They’ll never work under Windows 7 (which likes to load functions to random locations to improve security), and certainly never on a 64-bit compile.

Nope, it’s an offset in the dll (if anyone cares).

To do what?

I did describe what I need but here goes again in more detail:

I’m drawing a graph of scientific data, basically a wave output that has areas marked in different colours; each marked area has a label associated with it. I need to be able to create a 2D meta file from OpenGL so that the customer can paste it into word. A bitmap is no good as resizing it causes distortion.

Here is an example close to what is needed:


We have used GDI in the past to do the drawing (replaced so we can draw 3D, rotatable, scalable graphs) and it was easy to get the EMF out of this. Perhaps 30 lines of code.

EMF files contain a list of function pointers and ‘vertex’ lists, programs like MS Word can then process the GDI commands so that when you resize it draws correctly. Something like SVG.

I need to be able to do this with Open GL but it is looking like more work that a rewrite in GDI+

Well, feel free to add what you discover to the Wiki. Perhaps it will help some other poor bastard someday. :slight_smile:


I don’t have the time currently but when I do I’ll get my code working to save the open gl scene to EMF and then play the EMF file back to open gl and put it on the Wiki.

Unfortunately at the moment I have to find a way out of the EMF and memory issues I have with Open GL.


What’s wrong with MyCreateEnhMetaFile() and CloseEnhMetaFile()?

You can write to that like a typical Windows hDC. You don’t need to anything about the internals of the emf file format to use it.

Hi Sammie

But isn’t my problem that MS Word (and many other aps) doesn’t know how to process the commands stored in the EMF file?