GLUT屏幕调整大小

时间:2013-03-16 04:47:49

标签: c++ opengl glut

我正在尝试编写一个使屏幕尺寸和正常尺寸更大的功能。更重要的是,当我将屏幕尺寸调整到正常尺寸时,它会重新放回到我完全调整尺寸之前的位置..我该怎么办?它...

这就是我所做的

//global Variables
int scr_pos_x = 100, scr_pos_y = 150;

//somewhere else in main method
glutInitWindowPosition(scr_pos_x, scr_pos_y);
....
glutKeyboardFunc(myKeyboard);

//myKeyBoardFunction
void myKeyboard(unsigned char key, int x, int y){
    if(key == 'f'){
        int scr_pos_x = glutGet((GLenum)GLUT_WINDOW_X);
        int scr_pos_y = glutGet((GLenum)GLUT_WINDOW_Y);
        cout << " while f press "<<scr_pos_x <<" "<<scr_pos_y << endl; // to check
        glutFullScreen();
    }else if(key=='x'){
        cout << " while x press "<<scr_pos_x <<" "<<scr_pos_y << endl; // to check
        glutPositionWindow(scr_pos_x, scr_pos_y);
        glutReshapeWindow(640, 480); 
    }
}

当我按'f'时,我可以看到scr_pos_x和scr_pos_y被设置为适当的值,但当我按'x'时,这些值会以某种方式变为100和150.我错过了什么?

1 个答案:

答案 0 :(得分:3)

if(key == 'f'){
    int scr_pos_x = glutGet((GLenum)GLUT_WINDOW_X);
    int scr_pos_y = glutGet((GLenum)GLUT_WINDOW_Y);
    cout << " while f press "<<scr_pos_x <<" "<<scr_pos_y << endl; // to check
    glutFullScreen();
}

在这里,您创建了两个名为scr_pos_xscr_pos_y全新变量,这些变量一直持续到if块结束。它们会覆盖全局的那些。

int放在两个声明的开头,以便glutGet()覆盖全局 scr_pos_xscr_pos_y变量。< / p>