#include "GL/Context.h"


BEGIN_NAMESPACE


HDC glhdc;


HGLRC glWMCreate(HWND hwnd)
{ 
	glhdc = GetDC(hwnd);
	PIXELFORMATDESCRIPTOR pfd = {
		sizeof(PIXELFORMATDESCRIPTOR), 1,
		PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
		PFD_TYPE_RGBA, 24, 0
	};
	pfd.cDepthBits = 32;
	pfd.iLayerType = PFD_MAIN_PLANE;
	
	SetPixelFormat(glhdc, ChoosePixelFormat(glhdc, &pfd), &pfd);
	HGLRC hglrc = wglCreateContext(glhdc);
	if (hglrc)
		wglMakeCurrent(glhdc, hglrc);
	return hglrc;
}


void glWMDestroy(HWND hwnd)
{ 
	HGLRC hglrc = wglGetCurrentContext();
	if (hglrc) { 
		// if the thread has a current rendering context
		//HDC hdc = wglGetCurrentDC();
		wglMakeCurrent(NULL, NULL);
		ReleaseDC(hwnd, glhdc);
		wglDeleteContext(hglrc);
	}
}


END_NAMESPACE
