2013-03-16 221 views
0

我想写一个功能,使屏幕的全尺寸和正常的大小,更重要的是,虽然我调整屏幕大小的正常大小,它放回的位置之前,我全尺寸它..如何我能做到这一点...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.我在想什么?

回答

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变量。

+0

谢谢你,工作得很好。我不知道我在做什么..我明白了。再次感谢 – 2013-03-16 18:33:47

相关问题