PDA

View Full Version : Drawing to EMF file



AntonHX
12-01-2009, 09:07 AM
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!

AH

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

Alfonse Reinheart
12-01-2009, 10:37 AM
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?

AdrianPi
12-01-2009, 10:57 AM
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.

ZbuffeR
12-01-2009, 12:51 PM
GL to postscript, pdf, svg, ...
http://www.geuz.org/gl2ps/

AntonHX
12-02-2009, 01:36 AM
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 :-)

Thanks again for the input
Anton.

Brolingstanz
12-02-2009, 08:38 AM
For extra credit, what does the first data field of a EMR_GLSRECORD represent? (heheh)

AntonHX
12-02-2009, 09:09 AM
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:

Brolingstanz
12-02-2009, 09:15 AM
OK, but what is the first data field? How would you use it to play the metafile (provided it contains GL commands)?

ZbuffeR
12-02-2009, 03:45 PM
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 :-)

Brolingstanz
12-02-2009, 04:04 PM
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 :-)

Alfonse Reinheart
12-02-2009, 04:27 PM
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.

Brolingstanz
12-02-2009, 09:11 PM
Nope, it's an offset in the dll (if anyone cares).

AntonHX
12-03-2009, 09:20 AM
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:

http://www.codeproject.com/KB/openGL/glexport.aspx#emf

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+

V-man
12-06-2009, 09:13 AM
Well, feel free to add what you discover to the Wiki. Perhaps it will help some other poor bastard someday. :)

AntonHX
12-07-2009, 03:28 AM
Hi

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.

A

sammie381
12-08-2009, 11:38 AM
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.

AntonHX
12-15-2009, 03:44 AM
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?