Sha256: 76de526931824334198853b86f30e04d4e911fbe9e63e3d210bbeec79360834d
Contents?: true
Size: 1.83 KB
Versions: 5
Compression:
Stored size: 1.83 KB
Contents
#include "opengl.h" #include "reflex/exception.h" namespace Reflex { OpenGLContext::OpenGLContext () { } OpenGLContext::~OpenGLContext () { fin(); } void OpenGLContext::init (HWND hwnd_) { if (!hwnd_) argument_error(__FILE__, __LINE__); if (*this) invalid_state_error(__FILE__, __LINE__); hwnd = hwnd_; hdc = GetDC(hwnd); if (!hdc) system_error(__FILE__, __LINE__); static const PIXELFORMATDESCRIPTOR PFD = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; int pf = ChoosePixelFormat(hdc, &PFD); if (pf == 0) system_error(__FILE__, __LINE__); if (!SetPixelFormat(hdc, pf, &PFD)) system_error(__FILE__, __LINE__); hrc = wglCreateContext(hdc); if (!hrc) system_error(__FILE__, __LINE__); make_current(); } void OpenGLContext::fin () { if (!*this) return; if (hrc) { if (hrc == wglGetCurrentContext()) { if (!wglMakeCurrent(NULL, NULL)) system_error(__FILE__, __LINE__); } if (!wglDeleteContext(hrc)) system_error(__FILE__, __LINE__); hrc = NULL; } if (hdc) { if (!ReleaseDC(hwnd, hdc)) system_error(__FILE__, __LINE__); hdc = NULL; } hwnd = NULL; } void OpenGLContext::make_current () { if (!*this) return; if (!wglMakeCurrent(hdc, hrc)) system_error(__FILE__, __LINE__); } void OpenGLContext::swap_buffers () { if (!*this) return; if (!SwapBuffers(hdc)) system_error(__FILE__, __LINE__); } bool OpenGLContext::is_active () const { return *this && hrc == wglGetCurrentContext(); } OpenGLContext::operator bool () const { return hwnd && hdc && hrc; } bool OpenGLContext::operator ! () const { return !operator bool(); } }// Reflex
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
reflexion-0.3.4 | src/win32/opengl.cpp |
reflexion-0.3.3 | src/win32/opengl.cpp |
reflexion-0.3.2 | src/win32/opengl.cpp |
reflexion-0.3.1 | src/win32/opengl.cpp |
reflexion-0.3 | src/win32/opengl.cpp |