Sunil Shahi
Sunil Shahi

Reputation: 653

GLUT Screen Resize

I am trying to write a function that makes the screen full size and normal size and more Importantly while I resize the screen size to normal size it puts back on the position it was before I full sized it.. how can I do it...

Here Is what I have done

//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); 
    }
}

When I press 'f' I can see that the scr_pos_x and scr_pos_y are set up to the appropriate value but when I press 'x' those values somehow changes to 100 and 150. What am I missing??

Upvotes: 1

Views: 211

Answers (1)

genpfault
genpfault

Reputation: 52157

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();
}

Here you create two entirely new variables called scr_pos_x and scr_pos_y that last until the end of that if block. They override the global ones.

Drop the int at the beginning of the two declarations so that the glutGet()s overwrite the global scr_pos_x and scr_pos_y variables.

Upvotes: 3

Related Questions