1

我正在尝试编写一个函数,使屏幕全尺寸和正常尺寸,更重要的是,当我将屏幕尺寸调整为正常尺寸时,它会回到我全尺寸之前的位置..我该怎么做.. .

这是我所做的

//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。我错过了什么?

4

1 回答 1

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_x,并scr_pos_y持续到该if块的末尾。它们覆盖全局。

删除int两个声明开头的 s 以便glutGet()s 覆盖全局 scr_pos_xscr_pos_y变量。

于 2013-03-16T06:18:25.323 回答