Page 1 of 1

OpenGL in wxPdfDocument

Posted: Tue Sep 13, 2011 7:27 am
by DerKleineNik
I managed using the wxPdfDocument using the wxPdfDC and normal GDI commands.
But in my actual Project there are some OpenGL Graphics too.
Is it possible to print some GLCanvas to the PDF using wxPdfDocument?

Regards, DerKleineNik

Re: OpenGL in wxPdfDocument

Posted: Tue Sep 13, 2011 9:16 pm
by Auria
You can use OpenGL functions to retrieve the contents of the main buffer, then make a wxImage out of that (I don't have a code example for this though)

Re: OpenGL in wxPdfDocument

Posted: Tue Sep 13, 2011 9:23 pm
by utelle
DerKleineNik wrote:I managed using the wxPdfDocument using the wxPdfDC and normal GDI commands.
But in my actual Project there are some OpenGL Graphics too.
Is it possible to print some GLCanvas to the PDF using wxPdfDocument?
Well, it depends on what exactly you need. To my knowledge there is no direct way to redirect OpenGL commands to a wxDC class, but you could possibly copy the bitmap of the wxWidgets window to which you directed the OpenGL calls into a wxImage which could then be printed to PDF with the Image method of wxPdfDocument. Certainly not ideal, since you won't get scalable vector graphics into your PDF document, but at least better than nothing. The following link might give an idea how to do it:

http://forums.wxwidgets.org/viewtopic.p ... 973#p43973

Regards,

Ulrich

Re: OpenGL in wxPdfDocument

Posted: Thu Sep 15, 2011 12:04 pm
by DerKleineNik
Thanks for the hints!

It worked like this:

here goes the GL drawing

SwapBuffers();

if(DoPrint)
{
glReadBuffer(GL_BACK);
glFinish();
glPixelStorei(GL_PACK_ALIGNMENT, 3);
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
glPixelStorei(GL_PACK_SKIP_ROWS, 0);
glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
unsigned char * glBitmapData = new unsigned char [3 * breite * hoehe];
glReadPixels((GLint)0, (GLint)0, (GLint)breite, (GLint)hoehe, GL_RGB, GL_BYTE, glBitmapData);
img = wxImage(breite, hoehe, glBitmapData, true);

DoPrint=false;
}

For those who need that too: it only works if the window in which the OpenGl is displayed is in front (focussed) and not overlapped by other windows!

Thanks fpr your replies!

Regards, DerKleineNik