/*******************************************************************************
 * Copyright (c) 2018
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *******************************************************************************/
package go.graphics.swing.contextcreator;

import org.lwjgl.opengl.WGL;
import org.lwjgl.system.jawt.JAWTWin32DrawingSurfaceInfo;
import org.lwjgl.system.windows.GDI32;
import org.lwjgl.system.windows.PIXELFORMATDESCRIPTOR;

import go.graphics.swing.AreaContainer;

public class WGLContextCreator extends JAWTContextCreator {

    private JAWTWin32DrawingSurfaceInfo win32surfaceinfo;
    private long hwnd;
    private long hdc;
    private long context;
    private int pixel_format;

    public WGLContextCreator(AreaContainer ac) {
        super(ac);
    }


    @Override
    public void stop() {
        WGL.wglDeleteContext(context);
    }

    @Override
    protected void swapBuffers() {
        GDI32.SwapBuffers(hdc);
    }

    @Override
    protected void makeCurrent(boolean draw) {
        if(draw) {
            WGL.wglMakeCurrent(hdc, context);
        } else {
            WGL.wglMakeCurrent(0, 0);
        }
    }

    @Override
    protected void initContext() {
        hwnd = win32surfaceinfo.hwnd();
        hdc = win32surfaceinfo.hdc();


        PIXELFORMATDESCRIPTOR pfd = PIXELFORMATDESCRIPTOR.calloc();
        pfd.dwFlags(GDI32.PFD_DRAW_TO_WINDOW | GDI32.PFD_SUPPORT_OPENGL | GDI32.PFD_DOUBLEBUFFER);
        pfd.iPixelType(GDI32.PFD_TYPE_RGBA);
        pfd.cColorBits((byte) 32);

        pfd.cDepthBits((byte) 24);
        pfd.cStencilBits((byte) 1);

        pixel_format = GDI32.ChoosePixelFormat(hdc, pfd);
        GDI32.SetPixelFormat(hdc, pixel_format, pfd);

        pfd.free();

        context = WGL.wglCreateContext(hdc);
    }

    @Override
    protected void createNewSurfaceInfo() {
        win32surfaceinfo = JAWTWin32DrawingSurfaceInfo.create(surfaceinfo.platformInfo());
    }
}

@@ -2950,16 +2950,94 @@
 nfo());%0A
+        hwnd = win32surfaceinfo.hwnd();%0A        hdc = win32surfaceinfo.hdc();%0A
     %7D%0A%7D%0A

Fix NullPointerExceptions on Windows