[訳]GLUTチュートリアル-サブフォームの再構築

6390 ワード

Lighthouse3d.com >> GLUT Tutorial >> Subwindows >> Reshape Subwindows
 
関数のコールバックを再構築するには、サブフォームのサイズを変更し、各サブフォームを投影する投影マトリクスを再計算する必要がある.我々の場合、メインフォームにジオメトリをレンダリングする必要はないので、投影マトリクスの再計算をスキップすることができます.
まず、サイズ変更と位置変更フォームの関数の原型を紹介する.
 
void glutPositionWindow(int x, int y);void glutReshapeWindow(int width, int height);
x,y-フォームの左上隅
width,heith-フォームのピクセル次元
 
ここでは2つの関数が現在のフォームに作用するので、現在のフォームとして特殊なフォームを設定する必要があります.そのため、フォームIDをglutSettings Windowsに転送します.プロトタイプは次のとおりです.
 
void glutSetWindow(int windowIdentifier);
WindowIdentifier-フォームの戻り値の作成
 
どのフォームが現在のフォーム(フォーカス)であるかを知る必要がある場合はglutGetWindow関数を使用します.
 
int glutGetWindow();
この関数の戻り値は、現在のフォーム(フォーカスを取得)のIDである.
フォームのサイズを変更する前に、各サブフォームを現在のフォームに設定する必要があります.次のコードはchangeSize関数を用いる再構成関数を提供する.前節で述べたように、メインウィンドウに体重を調整するためのコールバックを定義します.これで十分です.ユーザーはデフォルトでメインフォームしか変更できません.
我々の例では、投影はすべてのサブフォームと同様であり、各サブフォームで呼び出す関数を定義する.
int w,h, border=6;

...

 



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(0, 0, w1, h1);



    // Set the clipping volume

    gluPerspective(45,ratio,0.1,1000);

    glMatrixMode(GL_MODELVIEW);

}



void changeSize(int w1,int h1) {



    if(h1 == 0)

        h1 = 1;



    // 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-2*border, h/2 - border*3/2);

    setProjection(w-2*border, h/2 - border*3/2);



    // set subwindow 2 as the active window

    glutSetWindow(subWindow2);

    // resize and reposition the sub window

    glutPositionWindow(border,(h+border)/2);

    glutReshapeWindow(w/2-border*3/2, h/2 - border*3/2);

    setProjection(w/2-border*3/2,h/2 - border*3/2);



    // set subwindow 3 as the active window

    glutSetWindow(subWindow3);

    // resize and reposition the sub window

    glutPositionWindow((w+border)/2,(h+border)/2);

    glutReshapeWindow(w/2-border*3/2,h/2 - border*3/2);

    setProjection(w/2-border*3/2,h/2 - border*3/2);

}