本文整理汇总了C++中Viewpoint::viewport方法的典型用法代码示例。如果您正苦于以下问题:C++ Viewpoint::viewport方法的具体用法?C++ Viewpoint::viewport怎么用?C++ Viewpoint::viewport使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Viewpoint
的用法示例。
在下文中一共展示了Viewpoint::viewport方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onDraw
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);
}
示例2: onDraw
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();
}
示例3: onDraw
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);
}