OpenGL in wxPdfDocument Topic is solved

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
DerKleineNik
Knows some wx things
Knows some wx things
Posts: 29
Joined: Fri Sep 09, 2011 9:59 am

OpenGL in wxPdfDocument

Post 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
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: OpenGL in wxPdfDocument

Post 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)
"Keyboard not detected. Press F1 to continue"
-- Windows
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: OpenGL in wxPdfDocument

Post 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
DerKleineNik
Knows some wx things
Knows some wx things
Posts: 29
Joined: Fri Sep 09, 2011 9:59 am

Re: OpenGL in wxPdfDocument

Post 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
Post Reply