[译]GLUT教程 - 重整子窗体
Lighthouse3d.com >> GLUT Tutorial >> Subwindows >> Reshape Subwindows
重整函数的回调需要处理两件事:修改子窗体的大小,重新计算投影每个子窗体的投影矩阵.在我们的情况中,我们不需要渲染任何几何图案到主窗体,所以我们可以跳过重新计算投影矩阵这一步.
先来介绍修改大小和重定位子窗体的函数原型.
void glutPositionWindow(int x, int y);
void glutReshapeWindow(int width, int height);
x, y - 窗体的左上角
width, heith - 窗体的像素维度
这里有两个函数可以作用到当前窗体,所以我们必须设置一个特殊的窗体来作为当前窗体.为了这个,我们要把窗体ID传入glutSetWindows.原型如下:
void glutSetWindow(int windowIdentifier);
windowIdentifier - 创建窗体的返回值
如果我们需要知道哪个窗体是当前窗体(获得焦点),我们可以用glutGetWindow函数.
int glutGetWindow();
该函数的返回值是当前窗体(获得焦点)的ID.
在定位和更改窗体大小之前,我们必须设置每个子窗体为当前窗体.下面代码提供了重整函数,用到changeSize函数.上一节说过,我们要定义一个回调来专门给主窗体重整窗体.这样已经足够了,因为用户默认只能更改主窗体.
在我们的示例中,投影和所有子窗体类似,我们将会定义一个函数来实现,并在每个子窗体调用它.
int w,h, border=;
... void setProjection(int w1, int h1)
{
float ratio;
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
ratio = 1.0f * w1 / h1;
// Reset the coordinate system before modifying
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // Set the viewport to be the entire window
glViewport(, , w1, h1); // Set the clipping volume
gluPerspective(,ratio,0.1,);
glMatrixMode(GL_MODELVIEW);
} void changeSize(int w1,int h1) { if(h1 == )
h1 = ; // we're keeping these values cause we'll need them latter
w = w1;
h = h1; // set subwindow 1 as the active window
glutSetWindow(subWindow1);
// resize and reposition the sub window
glutPositionWindow(border,border);
glutReshapeWindow(w-*border, h/ - border*/);
setProjection(w-*border, h/ - border*/); // set subwindow 2 as the active window
glutSetWindow(subWindow2);
// resize and reposition the sub window
glutPositionWindow(border,(h+border)/);
glutReshapeWindow(w/-border*/, h/ - border*/);
setProjection(w/-border*/,h/ - border*/); // set subwindow 3 as the active window
glutSetWindow(subWindow3);
// resize and reposition the sub window
glutPositionWindow((w+border)/,(h+border)/);
glutReshapeWindow(w/-border*/,h/ - border*/);
setProjection(w/-border*/,h/ - border*/);
}
[译]GLUT教程 - 重整子窗体的更多相关文章
- [译]GLUT教程(目录)
http://www.lighthouse3d.com/tutorials/glut-tutorial/ GLUT是OpenGL Utility Toolkit的意思.作者Mark J. Kilgar ...
- [译]GLUT教程 - 创建和关闭子窗体
Lighthouse3d.com >> GLUT Tutorial >> Subwindows >> Creating and Destroying Subwind ...
- [译]GLUT教程 - 渲染到子窗体
Lighthouse3d.com >> GLUT Tutorial >> Subwindows >> Rendering to Subwindows 先回顾一下之前 ...
- [译]GLUT教程 - 游戏模式
Lighthouse3d.com >> GLUT Tutorial >> Extras >> Game Mode 根据GLUT官网的说明,GLUT的游戏模式是为开启 ...
- [译]GLUT教程 - 整合代码7
Lighthouse3d.com >> GLUT Tutorial >> Extras >> The Code So Far VII 以下是子窗体的最终版本代码. ...
- [译]GLUT教程 - 初始化
Lighthouse3d.com >> GLUT Tutorial >> Basics >> Initialization 这一节开始从main函数入手.第一步是线 ...
- [译]GLUT教程 - 子菜单
Lighthouse3d.com >> GLUT Tutorial >> Pop-up Menus >> Sub Menus 上一节我们介绍了如何创建普通菜单和如果 ...
- [译]GLUT教程 - 改变窗体大小
Lighthouse3d.com >> GLUT Tutorial >> Basics >> Resizing the Window 上一章的例子创建了两个窗体,命 ...
- [译]GLUT教程 - glutPostRedisplay函数
Lighthouse3d.com >> GLUT Tutorial >> Avoiding the Idle Func >> glutPostRedisplay 直 ...
随机推荐
- Controlled Tournament(状态压缩DP)
Controlled Tournament 题意 n 名选手进行淘汰赛,R[i][j] = 1 表示 i 能胜过 j.要求通过安排淘汰赛使得,m 选手获得最终胜利,问使得比赛数最少的方案数. 分析 设 ...
- rsync + inotify 同步
1. 配置rysnc server:同步机,同步被同步机更新的文件,很多台vi /etc/rsyncd.conf uid=rootgid=rootuse chroot=nomax connection ...
- Java中使用HttpRequest调用RESTfull的DELETE方法接口提示:How to fix HTTP method DELETE doesn't support output
说明:无论是Spring框架还是Spring Boot的Feign形式的客户端,以下的解决方法都适用. 解决方法:直接升级JDK 1.8,这个问题是1.7的BUG. 参考: https://sales ...
- 自动化安装SQLSERVER和SQLSERVER补丁 转
2014-01-23 18:31 您还在用下一步下一步的方式安装SQLSERVER和SQLSERVER补丁吗? 介绍 假如你有50台服务器需要安装SQLSERVER,如果你用下一步下一步的方式,用远 ...
- Visio对象插入Word后周围空白过大
如图,空白很大,因为我在设计里选择纸张适应绘图,后发现直接复制粘贴到word就好了,没空白了.
- HashMap在高并发下引起的死循环
HashMap事实上并非线程安全的,在高并发的情况下,是非常可能发生死循环的,由此造成CPU 100%,这是非常可怕的.所以在多线程的情况下,用HashMap是非常不妥当的行为,应採用线程安全类Con ...
- 【mybatis】in查询+判断list查询条件是否进行in查询
mybatis中的in查询: 并且判断in查询的list是否为null或者list有值才进行In查询 <select id="find" parameterType=&quo ...
- 【XStream】xml和java实体的相互转化
1.pom.xml <!-- xstream xml和Java对象转化 --> <dependency> <groupId>xstream</groupId& ...
- 理解 VMWare的3种网络模型 z
在说到VMware的网络模型之前,先说一下VMware的几个虚拟设备: ■ VMnet0:这是VMware用于虚拟桥接网络下的虚拟交换机: ■ VMnet1:这是VMware用于虚拟Host-Only ...
- Python中的XMLRPC(Calendar)
XMLRPC服务器端代码,定义了三个方法名,getMonth获取所给月份的日历,getYear获取一年的日历,getDict测试返回字典的效果. xmlrpc_server.py: #!/usr/bi ...