1

Open GLで4つのビュー(LEFT / TOP / PERSPECTIVE / FRONT)を作成するにはどうすればよいですか?

私はこれを使用しました:

int main(int c,char ** argv)
{
    glutInit(&c,argv);
    glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH |GLUT_RGB );
    glutInitWindowSize(w,h);
    MainWin =glutCreateWindow("Teapot Window");
    glutDisplayFunc(display);

    LeftWin = glutCreateSubWindow(MainWin,0,0,s_window_w,s_window_h);
    glutDisplayFunc(displayLeft);
    glutReshapeFunc(reshapeLeft);

    TopWin = glutCreateSubWindow(MainWin,s_window_w+3,0,s_window_w,s_window_h);
    glutDisplayFunc(displayTop);
    glutReshapeFunc(reshapeTop);

    PerspectiveWin = glutCreateSubWindow(MainWin,0,s_window_h+3,s_window_w,s_window_h);
    glutDisplayFunc(displayPerspective);
    glutReshapeFunc(reshapePerspective);

    FrontWin = glutCreateSubWindow(MainWin,s_window_w+3,s_window_h+3,s_window_w,s_window_h);
    glutDisplayFunc(displayFront);
    glutReshapeFunc(reshapeFront);



    glutMainLoop();
    return 0;
}

それから私は上と左の投影を作りましたそしてこのように:

glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-0.5f,0.5f,-0.35f,0.35f,1,500);

フロントにもトップラインを使用すると、出力は次のようになります。 ここに画像の説明を入力してください

私のせいはどこですか?前もって感謝します

正面図が空で、透視図と左側面図が同じなのはなぜですか?透視投影のために私はglFrustumを使用していました....それで私は間違っていますか?3dsmaxやmayaなどの複数のビューの作成にご協力ください...以下は表示機能のコードです。

void displayLeft()
{
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0,0,-1,0,0,0,0,1,0);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0,GL_POSITION,light_pos);

    glShadeModel(GL_SMOOTH);
    glClearColor(0.2f,0.3f,0.4f,1);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glEnable(GL_COLOR_MATERIAL);
    glTranslatef(teapot_x,teapot_y,teapot_z);
    glRotatef(teapot_angle,0,1,0);
    glColor3f(0,1,0);
    glutSolidTeapot(0.2f);

    glPopMatrix();
    glFlush();
    glutSwapBuffers();
}
void displayTop()
{
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0,-1,0,0,0,0,0,0,-1);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0,GL_POSITION,light_pos);

    glShadeModel(GL_SMOOTH);
    glClearColor(0.2f,0.3f,0.4f,1);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glEnable(GL_COLOR_MATERIAL);
    glTranslatef(teapot_x,teapot_y,teapot_z);
    glRotatef(teapot_angle,0,1,0);
    glColor3f(0,1,0);
    glutSolidTeapot(0.2f);

    glPopMatrix();
    glFlush();
    glutSwapBuffers();
}
void displayFront()
{
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0,0,0,0,0,0,1,0,0);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0,GL_POSITION,light_pos);

    glShadeModel(GL_SMOOTH);
    glClearColor(0.2f,0.3f,0.4f,1);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glEnable(GL_COLOR_MATERIAL);
    glTranslatef(teapot_x,teapot_y,teapot_z);
    glRotatef(teapot_angle,0,1,0);
    glColor3f(0,1,0);
    glutSolidTeapot(0.2f);

    glPopMatrix();
    glFlush();
    glutSwapBuffers();
}
void displayPerspective()
{

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0,0,-1,0,0,0,0,1,0);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0,GL_POSITION,light_pos);

    glShadeModel(GL_SMOOTH);
    glClearColor(0.2f,0.3f,0.4f,1);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glEnable(GL_COLOR_MATERIAL);
    glTranslatef(teapot_x,teapot_y,teapot_z);
    glRotatef(0,0,1,0);
    glColor3f(0,1,0);
    glutSolidTeapot(0.2f);

    glPopMatrix();
    glFlush();
    glutSwapBuffers();
}
4

1 に答える 1

2

glViewportとを使用しglScissorて、ウィンドウのペインを切り取ります。次に、各ペインに対して通常どおりレンダリングを実行します。射影行列の設定は、実際には描画状態の操作であるため、形状変更ではなく、表示機能に属します。

表示機能は次のようになります

void ViewportScissor(int x, int y, int width, int height)
{
    glViewport(x, y, width, height);
    glScissor(x, y, width, height);
}

void display(void)
{

    int const win_width  = glutGet(GLUT_WINDOW_WIDTH);
    int const win_height = glutGet(GLUT_WINDOW_HEIGHT);

    glDisable(GL_SCISSOR);
    glClear(…);

    glEnable(GL_SCISSOR);

    ViewportScissor(0, 0, win_width/2, win_height/2);
    glMatrixMode(GL_PROJECTION);
    setup_frontview_projection();
    glMatrixMode(GL_MODELVIEW);
    setup_frontview();
    draw_scene();

    ViewportScissor(win_width/2, 0, win_width/2, win_height/2);
    glMatrixMode(GL_PROJECTION);
    setup_rightview_projection();
    glMatrixMode(GL_MODELVIEW);
    setup_rightview();
    draw_scene();

    ViewportScissor(0, win_height/2, win_width/2, win_height/2);
    glMatrixMode(GL_PROJECTION);
    setup_topview_projection();
    glMatrixMode(GL_MODELVIEW);
    setup_topview();
    draw_scene();

    ViewportScissor(win_width/2, win_height/2, win_width/2, win_height/2);
    glMatrixMode(GL_PROJECTION);
    setup_freecamview_projection();
    glMatrixMode(GL_MODELVIEW);
    setup_freecamview();
    draw_scene();

    glutSwapBuffers();

}

分割線/フレームの追加は、読者の演習として残されています。

于 2012-12-21T17:17:47.983 に答える