GLUT Tutorials 17:子窗口的reshape

博客转自:http://www.lighthouse3d.com/tutorials/glut-tutorial/subwindow-reshape/

The callback for the reshape function needs to do two things: it resizes the subwindows, and recomputes the projection matrices for each subwindow. In our case we’re not rendering any geometry in the main window, so we’ll skip recomputing the projection matrix for the main window.

First let’s introduce the functions to resize, and reposition the subwindows.

1void glutPositionWindow(int x, int y); 2void glutReshapeWindow(int width, int height); 3 4Parameters: 5x,y – the top left corner of the window 6width, height – the dimensions of the window in pixels

These two function act on the current window so first we must set a particular window as being the current window. In order to do this we need to have the window identifier at hand and call glutSetWindow. The syntax is as follows:

1void glutSetWindow(int windowIdentifier); 2 3Parameters: 4windowIdentifier – the value returned when the window is created.

If we need to know which window is the current window we can use GLUTs function glutGetWindow.

int glutGetWindow();

The return value of this function is the identifier of the current window.

Before we do any calls to position and resize the window we must set each subwindow as the current window. The following piece of code provides the reshape function, in our case the function is called changeSize. As mentioned in the PREVIOUS section we have defined a callback for reshaping the window only for the main window. This is enough because by default the user can only resize the main window.

Since, in our example, the projection is similar to all subwindows we are going to define a function for this purpose, and call it for each subwindow.

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

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

GLUT Tutorials 17:子窗口的reshape - HelloWorld