void onDraw(Graphics& g, const Viewpoint& v){ // Get the viewport dimensions, in pixels, for positioning the text float W = v.viewport().w; float H = v.viewport().h; // Setup our matrices for 2D pixel space g.pushMatrix(Graphics::PROJECTION); g.loadMatrix(Matrix4f::ortho2D(0, W, 0, H)); g.pushMatrix(Graphics::MODELVIEW); // Before rendering text, we must turn on blending g.blendAdd(); // Render text in the top-left corner g.loadIdentity(); g.translate(8, H - (font1.size() + 8)); g.currentColor(1,1,0,1); font1.render(g, "Top-left text"); // Render text in the bottom-left corner g.loadIdentity(); g.translate(8, 8); g.currentColor(1,0,1,1); font3.render(g, "Bottom-left text"); // Render text centered on the screen g.loadIdentity(); std::string str = "Centered text"; // Note that dimensions must be integers to avoid blurred text g.translate(int(W/2 - font2.width(str)/2), int(H/2 - font2.size()/2)); g.currentColor(0,1,1,1); font2.render(g, str); // Turn off blending g.blendOff(); g.popMatrix(); g.popMatrix(Graphics::PROJECTION); }
virtual void onDraw(Graphics& g, const Viewpoint& v){ Frustumd fr; v.lens().frustum(fr, v.worldTransform(), v.viewport().aspect()); // printf("ntl: %g %g %g\n", fr.ntl[0], fr.ntl[1], fr.ntl[2]); // printf("ftl: %g %g %g\n", fr.ftl[0], fr.ftl[1], fr.ftl[2]); Mesh& m = g.mesh(); m.reset(); m.primitive(g.LINES); m.vertex(-1,-1, -11); m.vertex( 1, 1, -12); for(int i=0; i<m.vertices().size(); ++i){ int r = fr.testPoint(m.vertices()[i]); m.color(HSV(r ? 0.3 : 0)); } g.lineWidth(10); g.antialiasing(g.NICEST); g.draw(); { // int r = fr.testPoint(Vec3d(0,0,15)); // printf("%d\n", r); } // draw rectangle across frustum diagonal m.reset(); m.color(Color(0.5)); m.vertex(fr.nbl); m.vertex(fr.fbr); m.vertex(fr.ntr); m.vertex(fr.ftl); m.primitive(g.LINE_LOOP); g.draw(); }
void onDraw(Graphics& g, const Viewpoint& vp){ // Switch to the projection matrix g.pushMatrix(Graphics::PROJECTION); // Set up 2D orthographic projection coordinates // The args to Matrix4::ortho2D are left, right, bottom, top float aspect = vp.viewport().aspect(); // width divided by height g.loadMatrix(Matrix4f::ortho2D(-aspect,aspect, -1,1)); // If you want units of pixels, use this instead: //g.loadMatrix(Matrix4f::ortho2D(0,vp.viewport().w, vp.viewport().h, 0)); // Switch to the modelview matrix g.pushMatrix(Graphics::MODELVIEW); g.loadIdentity(); g.draw(verts); g.popMatrix(); // Don't forget to restore original projection matrix g.popMatrix(Graphics::PROJECTION); }