【问题标题】:GLUT Screen ResizeGLUT 屏幕调整大小
【发布时间】:2013-03-16 14:18:25
【问题描述】:

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

这就是我所做的

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

【问题讨论】:

    标签: c++ opengl glut


    【解决方案1】:
    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()s 覆盖全局 scr_pos_xscr_pos_y 变量。

    【讨论】:

    • 谢谢你工作得很好。我不知道我在做什么..我明白了。再次感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-20
    • 2018-11-12
    • 2013-11-28
    • 2011-08-12
    • 2017-01-19
    • 2016-04-20
    相关资源
    最近更新 更多