2013-03-16 167 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

相關問題