[译]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 直 ...
随机推荐
- Python的扩展接口[0] -> VISA仪器控制
VISA仪器控制 / VISA Instrument Control 1 VISA简介 / VISA Introduction VISA(Virtual Instrument Software Arc ...
- Nginx配置文件分析
#user nobody; #启动进程数,即启动ngnix服务的个数,通常设置和cpu的数量相等 worker_processes 1; #全局错误日志及PID文件 #error_log logs/e ...
- 洛谷——P2067 Cytus-Holyknight
P2067 Cytus-Holyknight 题目背景 本人最初作 以此纪念伟大的ios.安卓.PSV平台音乐游戏<cytus> 后续将不断更新. -------------Chapter ...
- Static和Final修饰类属性变量及初始化
1.static修饰一个属性字段,那么这个属性字段将成为类本身的资源,public修饰为共有的,可以在类的外部通过test.a来访问此属性;在类内部任何地方可以使用.如果被修饰为private私有,那 ...
- POJ 2549:Subsets(哈希表)
[题目链接] http://poj.org/problem?id=2549 [题目大意] 给出一个数集,从中选择四个元素,使得a+b+c=d,最小化d [题解] 我们对a+b建立Hash_table, ...
- [POI2014]Little Bird
题目大意: $n(n\le10^6)$个点排成一排,每个点有一个高度$h_i$,现在要从$1$号点跳到$n$号点,从$i$号点出发跳到的点$j$满足$i<j\le i+k$,若$h_j\ge h ...
- yaffs和jffs2简单比较
转:http://blog.chinaunix.net/uid-27675161-id-3392636.html 相关知识引用<嵌入式 Linux 应用开发 完全手册> Nand F ...
- 设计模式之观察者模式(php实现)
github地址:https://github.com/ZQCard/design_pattern /** * 当对象间存在一对多关系时,则使用观察者模式(Observer Pattern). * 比 ...
- linux stdin(0)/ stdout(1) / stderr(2)
在shell中,每个进程都和三个系统文件相关联:标准输入stdin,标准输出stdout.标准错误stderr,三个系统文件的文件描述符分别为0,1.2.进程需要的输入来自stdin文件.进程的标准输 ...
- python核心编程学习记录之Web编程
cgi未完待续