Changeset 72997


Ignore:
Timestamp:
Jul 19, 2018, 7:18:06 AM (6 years ago)
Author:
hcho
Message:

nviz: offscreen rendering for Windows (Fix #2114)

Location:
grass/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • grass/trunk/include/nviz.h

    r72966 r72997  
    135135    HDC displayId;              /* display context */
    136136    HGLRC contextId;            /* rendering context */
    137     HBITMAP bitmapId;
    138137#endif
    139138    int width, height;
  • grass/trunk/lib/nviz/render.c

    r72970 r72997  
    5151    rwin->displayId = NULL;
    5252    rwin->contextId = NULL;
    53     rwin->bitmapId = NULL;
    5453#endif
    5554
     
    7877    wglDeleteContext(rwin->contextId);
    7978    DeleteDC(rwin->displayId);
    80     DeleteObject(rwin->bitmapId);
    8179#endif
    8280
     
    148146    aglCreatePBuffer(width, height, GL_TEXTURE_2D, GL_RGBA, 0, &(rwin->windowId));
    149147#elif defined(OPENGL_WINDOWS)
     148    WNDCLASS wc = {0};
     149    HWND hWnd;
    150150    PIXELFORMATDESCRIPTOR pfd = {
    151151        sizeof(PIXELFORMATDESCRIPTOR),  //  size of this pfd
    152152        1,                      /* version number           */
    153153        PFD_DRAW_TO_WINDOW |    /* support window           */
    154             PFD_SUPPORT_OPENGL |        /* support OpenGL           */
    155             PFD_DOUBLEBUFFER,   /* double buffered          */
     154        PFD_SUPPORT_OPENGL |    /* support OpenGL           */
     155        PFD_DOUBLEBUFFER,       /* double buffered          */
    156156        PFD_TYPE_RGBA,          /* RGBA type                */
    157157        24,                     /* 24-bit color depth       */
     
    170170    int iPixelFormat;
    171171
    172     rwin->displayId = CreateCompatibleDC(NULL);
     172    wc.lpfnWndProc = DefWindowProc;
     173    wc.lpszClassName = "nviz";
     174
     175    if (!RegisterClass(&wc)) {
     176        G_warning(_("Unable to register window class"));
     177        return -1;
     178    }
     179
     180    hWnd = CreateWindow(wc.lpszClassName, wc.lpszClassName, WS_POPUP,
     181            CW_USEDEFAULT, CW_USEDEFAULT, width, height,
     182            NULL, NULL, wc.hInstance, NULL);
     183
     184    if (!hWnd) {
     185        G_warning(_("Unable to create window"));
     186        return -1;
     187    }
     188
     189    rwin->displayId = GetDC(hWnd);
    173190    iPixelFormat = ChoosePixelFormat(rwin->displayId, &pfd);
    174191    SetPixelFormat(rwin->displayId, iPixelFormat, &pfd);
    175     rwin->bitmapId = CreateCompatibleBitmap(rwin->displayId, width, height);
    176     SelectObject(rwin->displayId, rwin->bitmapId);
    177192    rwin->contextId = wglCreateContext(rwin->displayId);
    178     /* TODO */
    179193#endif
    180194
Note: See TracChangeset for help on using the changeset viewer.