#include #include #include "GLContext.h" GLContext::GLContext () { reset(); } GLContext::GLContext (HWND hWnd) { init (hWnd); } GLContext::~GLContext () { purge(); } void GLContext::init (HWND hWnd) { PIXELFORMATDESCRIPTOR pfd; // Description du Pixel Format int format; this->hWnd = hWnd; // Obtention du Handle de la fenetre hwnd hDC = GetDC (hWnd); // Obtention du device context (DC) // Configuration du Pixel format pour le DC ZeroMemory (&pfd, sizeof (pfd)); pfd.nSize = sizeof (pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; pfd.cDepthBits = 32; pfd.iLayerType = PFD_MAIN_PLANE; format = ChoosePixelFormat (hDC, &pfd); SetPixelFormat (hDC, format, &pfd); hRC = wglCreateContext (hDC); // Creation du context de rendu (RC) wglMakeCurrent (hDC, hRC); // Application du context de rendu actuel } void GLContext::purge () { if (hRC) { wglMakeCurrent (NULL, NULL); wglDeleteContext (hRC); } if (hWnd && hDC) { ReleaseDC (hWnd, hDC); } reset(); } void GLContext::reset () { hWnd = NULL; hDC = NULL; hRC = NULL; } HDC GLContext::getHDC () { return hDC; } HGLRC GLContext::getHGLRC () { return hRC; }