tags:

views:

87

answers:

2

Is it possible to resize an openGL window (or device context) created with wglCreateContext without disabling it? If so how? Right now I have a function which resizes the DC but the only way I could get it to work was to call DisableOpenGL and then re-enable. This causes any textures and other state changes to be lost. I would like to do this without the disable so that I do not have to go through the tedious task of recreating the openGL DC state.

HWND hWnd;
HDC hDC;
void View_setSizeWin32(int width, int height) {
    // resize the window
    LPRECT rec = malloc(sizeof(RECT));
    GetWindowRect(hWnd, rec);
    SetWindowPos(      
        hWnd, 
        HWND_TOP, 
        rec->left, 
        rec->top, 
        rec->left+width, 
        rec->left+height,
        SWP_NOMOVE
    );
    free(rec);

    // sad panda
     /*
    DisableOpenGL( hWnd, hDC, hRC );
    EnableOpenGL( hWnd, &hDC, &hRC );
     */

    //EDIT - instead do this....
    glViewport(0, 0, width, height); 

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity(); 
    glOrtho(-(width/2), width/2, -(height/2), height/2, -1.0, 1.0);

}
A: 

I'm pretty sure you don't have to delete the rendering context or the DC. However, you should deactivate it before resizing the window.

Also, you should probably only have a rendering context active while you are rendering.

MSN
+1  A: 

I think you've got to call glViewport again after the client area was resized.

Ben Voigt
Thanks a bunch. I was just looking in the wrong place.
Nick
you're very welcome
Ben Voigt