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
OpenGL in wxPdfDocument Topic is solved
-
- Knows some wx things
- Posts: 29
- Joined: Fri Sep 09, 2011 9:59 am
Re: OpenGL in wxPdfDocument
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
-- Windows
Re: OpenGL in 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: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?
http://forums.wxwidgets.org/viewtopic.p ... 973#p43973
Regards,
Ulrich
-
- Knows some wx things
- Posts: 29
- Joined: Fri Sep 09, 2011 9:59 am
Re: OpenGL in wxPdfDocument
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
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