OpenGL in wxPdfDocument  [SOLVED]

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

OpenGL in wxPdfDocument

Postby DerKleineNik » Tue Sep 13, 2011 7:27 am

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

Postby Auria » Tue Sep 13, 2011 9:16 pm

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: 828
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: OpenGL in wxPdfDocument  [SOLVED]

Postby utelle » Tue Sep 13, 2011 9:23 pm

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.php?f=1&t=9702&p=43973#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

Postby DerKleineNik » Thu Sep 15, 2011 12:04 pm

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


Return to “wxCode”

Who is online

Users browsing this forum: No registered users and 5 guests