Click to See Complete Forum and Search --> : clipboard & opengl


chris b
June 5th, 1999, 10:34 AM
I want to copy some opengl rendered scene into the clipboard. I can't just BitBlt the image into memory DC and put DC's bitmap into clipboard, because if only, say, half of my window with rendered scene is visible on the screen I would get only half of the image in the clipboard - the other half is rubbish. I know I could just render the image into a new memory DC, but I'm having problems there. It requires creating another opengl rendering context, but wglCreateContext(memDC, hGLRC) returns NULL.
Does this mean that I can have only one rendering context, or am I missing something of importance there???
here's how I try to create another RC:


.....

HGLRC newRC;
CDC memDC;

newRC = wglCreateContext(memDC); //<- i get NULL here
wglMakeCurrent(memDC, newRC);

...




thanx in advance!

chris b

Josh Handley
June 7th, 1999, 09:23 AM
Are you creating an appropriate pixel format for the memDC before you create the rendering context?
You need to create a pixel format descriptor with the PFD_DRAW_TO_BITMAP flag set and then call ChoosePixelFormat and SetPixelFormat the same way do when you create your initial rendering context.

You also need to select a bitmap or something into the memDC so you have something to draw into. If you don't then the call to SetPixelFormat will fail.

There is an example of drawing OpenGL into a memory device context that then gets blitted to a printer device context here on CodeGuru in hte OpenGL section: http://www.codeguru.com/opengl/printpreview.shtml
Look in the OnBeginPrinting routine in the CGlView class.

If that doesn't help let me know - I have some code that does essentially the same thing but uses Chris Maunders CDIBSectionLite class to hide some of the ugliness of the device independent bitmap stuff.

Another option is to render your scene into an enhanced metafile and store that in the clipboard. For an example of that check out the OpenGL Superbible home page:
http://www.starstonesoftware.com/OpenGL/metafile.htm

Josh