← Back to team overview

kicad-developers team mailing list archive

MacOSX: Support for exporting files from 3Dview

 

This code adds support for exporting the 3D view to clipboard or file.
The normal procedure exports only a dark bitmap.

--
Marco

Index: 3d-viewer/3d_canvas.cpp
===================================================================
--- 3d-viewer/3d_canvas.cpp	(revision 2243)
+++ 3d-viewer/3d_canvas.cpp	(working copy)
@@ -12,6 +12,7 @@
 
#include "wx/dataobj.h"
#include "wx/clipbrd.h"
+#include <wx/wupdlock.h>
 
#include "gestfich.h"
 
@@ -579,13 +580,41 @@
Redraw( true );
 
wxSize image_size = GetClientSize();
+#ifndef __WXMAC__
wxClientDC dc( this );
wxBitmap bitmap( image_size.x, image_size.y );
wxMemoryDC memdc;
memdc.SelectObject( bitmap );
memdc.Blit( 0, 0, image_size.x, image_size.y, &dc, 0, 0 );
memdc.SelectObject( wxNullBitmap );
+#else
+ struct vieport_params
+ {
+ GLint originx;
+ GLint originy;
+ GLint x;
+ GLint y;
+ } viewport;
 
+ wxWindowUpdateLocker noUpdates(this);
+ glGetIntegerv( GL_VIEWPORT, (GLint*) &viewport );
+
+ unsigned char* pixelbuffer = (unsigned char*) malloc( viewport.x * viewport.y * 3 );
+ unsigned char* alphabuffer = (unsigned char*) malloc( viewport.x * viewport.y );
+ wxImage image(viewport.x, viewport.y);
+    
+ glPixelStorei(GL_PACK_ALIGNMENT, 1); 
+ glReadBuffer( GL_BACK_LEFT ); 
+ glReadPixels( viewport.originx, viewport.originy, viewport.x, viewport.y, GL_RGB, GL_UNSIGNED_BYTE, pixelbuffer );
+ glReadPixels( viewport.originx, viewport.originy, viewport.x, viewport.y, GL_ALPHA, GL_UNSIGNED_BYTE, alphabuffer );
+
+
+ image.SetData( pixelbuffer );
+ image.SetAlpha(alphabuffer );
+ image = image.Mirror(false);
+ wxBitmap bitmap( image );
+#endif
+
if( event.GetId() == ID_TOOL_SCREENCOPY_TOCLIBBOARD )
{
wxBitmapDataObject* dobjBmp = new wxBitmapDataObject;