// This required to get correct linking with Objective-C files extern "C" { #include "render_to_buffer.h" }; // We're probably didn't build libigl.a with LLVM so just use the headers only // version. #define IGL_HEADER_ONLY #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static int width,height; static Eigen::MatrixXd V,N; static Eigen::MatrixXi F; static Eigen::Vector3d Vmean, Vmax,Vmin; //static bool invert = false; static float background_color[4] = {0,0,0,1}; // Small viewports struct for keeping track of size and camera info #define NUM_VIEWPORTS 6 struct Viewport { int x,y,width,height; igl::Camera camera; Viewport(): x(0),y(0),width(0),height(0),camera(){}; Viewport( const int x, const int y, const int width, const int height, const igl::Camera & camera): x(x), y(y), width(width), height(height), camera(camera) { }; void reshape( const int x, const int y, const int width, const int height) { this->x = x; this->y = y; this->width = width; this->height = height; }; } viewports[NUM_VIEWPORTS]; // Red screen for errors void red(const int width, const int height, GLubyte * buffer) { for(int h = 0;h sx ? sy : sx); glScaled(s,s,s); glTranslated(-Vmean(0,0),-Vmean(1,0),-Vmean(2,0)); // Hack. Should really just figure out max scale so that full model fits on // screen with given perspective. //const double dz_off = (dz > 2.*dy && dz > 2.*dx ? dz/2. : 0); //glTranslated(0,0,-dz_off); } void pop_object() { glPopMatrix(); } void pop_scene() { glPopMatrix(); } void display() { using namespace std; using namespace igl; glClearColor( background_color[0], background_color[1], background_color[2], background_color[3]); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glDisable(GL_CULL_FACE); glCullFace(GL_BACK); // "Flash light" attached to camera lights(); // Draw for each viewport for(int vp = 0;vp > vV,vN,vTC; vector > vF,vFTC,vFN; if(ext == "obj") { // Convert extension to lower case if(!igl::readOBJ(filename,vV,vTC,vN,vF,vFTC,vFN)) { red(width,height,buffer); return false; } }else if(ext == "off") { // Convert extension to lower case if(!igl::readOFF(filename,vV,vF,vN)) { red(width,height,buffer); return false; } }else if(ext == "wrl") { // Convert extension to lower case if(!igl::readWRL(filename,vV,vF)) { red(width,height,buffer); return false; } }else { // Convert extension to lower case MatrixXi T; if(!igl::readMESH(filename,V,T,F)) { red(width,height,buffer); return false; } //if(F.size() > T.size() || F.size() == 0) { boundary_faces(T,F); } } if(vV.size() > 0) { if(!list_to_matrix(vV,V)) { red(width,height,buffer); return false; } triangulate(vF,F); } cout<<"IO: "<<(get_seconds()-ts)<<"s"<= 305 /* specify Z, stencil, accum sizes */ ctx = OSMesaCreateContextExt( OSMESA_RGBA, 32, 0, 0, NULL ); # else ctx = OSMesaCreateContext( OSMESA_RGBA, NULL ); # endif if (!ctx) { fprintf(stderr,"OSMesaCreateContext failed!\n"); red(width,height,buffer); return false; } /* Bind the buffer to the context and make it current */ if (!OSMesaMakeCurrent( ctx, buffer, GL_UNSIGNED_BYTE, width, height)) { fprintf(stderr,"OSMesaMakeCurrent failed!\n"); red(width,height,buffer); return false; } // Render init_viewports(); reshape(width,height); display(); cout<<"Display: "<<(get_seconds()-ts)<<"s"<