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教程 - 重整子窗体的更多相关文章

  1. [译]GLUT教程(目录)

    http://www.lighthouse3d.com/tutorials/glut-tutorial/ GLUT是OpenGL Utility Toolkit的意思.作者Mark J. Kilgar ...

  2. [译]GLUT教程 - 创建和关闭子窗体

    Lighthouse3d.com >> GLUT Tutorial >> Subwindows >> Creating and Destroying Subwind ...

  3. [译]GLUT教程 - 渲染到子窗体

    Lighthouse3d.com >> GLUT Tutorial >> Subwindows >> Rendering to Subwindows 先回顾一下之前 ...

  4. [译]GLUT教程 - 游戏模式

    Lighthouse3d.com >> GLUT Tutorial >> Extras >> Game Mode 根据GLUT官网的说明,GLUT的游戏模式是为开启 ...

  5. [译]GLUT教程 - 整合代码7

    Lighthouse3d.com >> GLUT Tutorial >> Extras >> The Code So Far VII 以下是子窗体的最终版本代码. ...

  6. [译]GLUT教程 - 初始化

    Lighthouse3d.com >> GLUT Tutorial >> Basics >> Initialization 这一节开始从main函数入手.第一步是线 ...

  7. [译]GLUT教程 - 子菜单

    Lighthouse3d.com >> GLUT Tutorial >> Pop-up Menus >> Sub Menus 上一节我们介绍了如何创建普通菜单和如果 ...

  8. [译]GLUT教程 - 改变窗体大小

    Lighthouse3d.com >> GLUT Tutorial >> Basics >> Resizing the Window 上一章的例子创建了两个窗体,命 ...

  9. [译]GLUT教程 - glutPostRedisplay函数

    Lighthouse3d.com >> GLUT Tutorial >> Avoiding the Idle Func >> glutPostRedisplay 直 ...

随机推荐

  1. 「kuangbin带你飞」专题二十 斜率DP

    layout: post title: 「kuangbin带你飞」专题二十 斜率DP author: "luowentaoaa" catalog: true tags: mathj ...

  2. Codeforces 1025D Recovering BST

    这个题被wa成傻逼了.... ma[i][j]表示i,j能不能形成一条直接作为排序二叉树的边,n^3更新维护ma即可,按说应该是要爆复杂度的,数据玄学吧.. #include<iostream& ...

  3. POJ 3041 Asteroids (二分图匹配)

    [题目链接] http://poj.org/problem?id=3041 [题目大意] 一个棋盘上放着一些棋子 每次操作可以拿走一行上所有的棋子或者一列上所有的棋子 问几次操作可以拿完所有的棋子 [ ...

  4. ACM集训日志——day1——15.7.8

    UVA 11292 The Dragon of Loowater 题意 给n个头,m个骑士,骑士有能力值x,代表他可以砍掉一个直径不超过x的头,并且佣金为x,求要砍掉所有的头,需要的最少佣金是多少. ...

  5. springmvc使用StringHttpMessageConverter需要配置编码

    Spring controller 如下 @Controller public class SimpleController { @ResponseBody @RequestMapping(value ...

  6. Features (OCMock 2)

    This page describes the features present in OCMock 2.x, using the traditional syntax. All these feat ...

  7. ora01940 无法删除当前连接的用户

    我用system这个用户登录oracle,想删除掉一个自己创建的用户user,在网上找到的方法都是说先查找到该用户连接的会话select username,sid,serial# from v$ses ...

  8. Solr In Action 中文版 第一章(三)

    3.1              为什么选用Solr? 在本节中.我们希望能够提供一些关键信息来帮助于你推断Solr是否是贵公司技术方案的正确选择.我们先从Solr吸引软件架构师的方面说起. 3.1  ...

  9. RSA加密解密及数字签名Java实现

    http://my.oschina.net/jiangli0502/blog/171263

  10. 弄清java中的字节与字符

    问题 在java中,一个字符等于多少字节? 或者更详细的问:在java中,一个英文字符等于多少字节?一个中文字符等于多少字节? 答案 Java采用unicode来表示字符,java中的一个char是2 ...