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函数.上一节说过,我们要定义一个回调来专门给主窗体重整窗体.这样已经足够了,因为用户默认只能更改主窗体.

在我们的示例中,投影和所有子窗体类似,我们将会定义一个函数来实现,并在每个子窗体调用它.

  1. int w,h, border=;
  2. ...
  3.  
  4. void setProjection(int w1, int h1)
  5. {
  6. float ratio;
  7. // Prevent a divide by zero, when window is too short
  8. // (you cant make a window of zero width).
  9. ratio = 1.0f * w1 / h1;
  10. // Reset the coordinate system before modifying
  11. glMatrixMode(GL_PROJECTION);
  12. glLoadIdentity();
  13.  
  14. // Set the viewport to be the entire window
  15. glViewport(, , w1, h1);
  16.  
  17. // Set the clipping volume
  18. gluPerspective(,ratio,0.1,);
  19. glMatrixMode(GL_MODELVIEW);
  20. }
  21.  
  22. void changeSize(int w1,int h1) {
  23.  
  24. if(h1 == )
  25. h1 = ;
  26.  
  27. // we're keeping these values cause we'll need them latter
  28. w = w1;
  29. h = h1;
  30.  
  31. // set subwindow 1 as the active window
  32. glutSetWindow(subWindow1);
  33. // resize and reposition the sub window
  34. glutPositionWindow(border,border);
  35. glutReshapeWindow(w-*border, h/ - border*/);
  36. setProjection(w-*border, h/ - border*/);
  37.  
  38. // set subwindow 2 as the active window
  39. glutSetWindow(subWindow2);
  40. // resize and reposition the sub window
  41. glutPositionWindow(border,(h+border)/);
  42. glutReshapeWindow(w/-border*/, h/ - border*/);
  43. setProjection(w/-border*/,h/ - border*/);
  44.  
  45. // set subwindow 3 as the active window
  46. glutSetWindow(subWindow3);
  47. // resize and reposition the sub window
  48. glutPositionWindow((w+border)/,(h+border)/);
  49. glutReshapeWindow(w/-border*/,h/ - border*/);
  50. setProjection(w/-border*/,h/ - border*/);
  51. }

[译]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. hdu6038

    hdu6038 分析 求函数 \(f\) 的构成方案,\(f\) 确定下来后,\(f\) 和 \(b\) 的值也是一一对应的了( \(f(i)=b_{f(a_i)}\) ),观察 \(a\) 数组,代 ...

  2. HttpClient 同时上传多个文件及参数, 同时利用 Web Api 接收

    using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient()) { client.BaseAddress = ...

  3. 内连接(INNER JOIN)

    内连接组合两张表,并且基于两张表中的关联关系来连接它们.使用内连接需要指定表中哪些字段组成关联关系,并且需要指定基于什么条件进行连接.内连接的语法如下: INNER JOIN table_name O ...

  4. luogu P1437 [HNOI2004]敲砖块

    三角形向右对齐后 你想打掉一个砖块,那么你必须打掉右上方的三角形,前缀和维护 若是第i列若是k个,那么它右边的那一列至少选了k-1个 f[i][j][k] 表示从后向前选到第 i 列第j个一共打了k次 ...

  5. xml文件生成与下载

    写在前面: 最近要做一个新的功能,点击按钮,可以根据数据生成对应的xml文件并保存.下面记录一下在做的过程的一些疑惑与问题(我就是太笨了,一些很简单的知识都不知道,不过通过这次跟蛋蛋的交流,解决了我的 ...

  6. 六. 异常处理8.throws子句

    如果一个方法可以导致一个异常但不处理它,它必须指定这种行为以使方法的调用者可以保护它们自己而不发生异常.做到这点你可以在方法声明中包含一个throws子句.一个 throws 子句列举了一个方法可能抛 ...

  7. gedit插件配置

    Ubuntu用户 sudo apt-get install gedit-plugins Fedora用户 yum install gedit-plugins 使用gEdit搭配terminal来写程序 ...

  8. C# Json格式字符串

    转自:http://www.cnblogs.com/unintersky/p/3884712.html 将Json字符串转化成格式化表示的方法: 字符串反序列化为对象-->对象再序列化为字符串 ...

  9. git -- 忽略某个文件

    1.修改 .gitignore 文件 在git中如果想忽略掉某个文件,不让这个文件提交到版本库中,可以使用修改 .gitignore 文件的方法.举例:.gitignore文件内容如下: # Andr ...

  10. python3.6使用pickle序列化class

    from library.connecter.database.mongo import Op_Mongo a = pickle.dumps(Op_Mongo) #序列化 b = pickle.loa ...