* See also:
* - http://www.opengl.org/archives/resources/faq/technical/mswindows.htm
*/
-static __PFNWGLCHOOSEPIXELFORMAT pfnChoosePixelFormat = &ChoosePixelFormat;
-static __PFNWGLSETPIXELFORMAT pfnSetPixelFormat = &SetPixelFormat;
-static __PFNWGLSWAPBUFFERS pfnSwapBuffers = &SwapBuffers;
+static PFN_WGLCHOOSEPIXELFORMAT pfnChoosePixelFormat = &ChoosePixelFormat;
+static PFN_WGLSETPIXELFORMAT pfnSetPixelFormat = &SetPixelFormat;
+static PFN_WGLSWAPBUFFERS pfnSwapBuffers = &SwapBuffers;
static LRESULT CALLBACK
{
MINMAXINFO *pMMI;
switch (uMsg) {
+ case WM_KEYDOWN:
+ switch (wParam) {
+ case VK_ESCAPE:
+ PostMessage(hWnd, WM_CLOSE, 0, 0);
+ break;
+ }
+ break;
case WM_GETMINMAXINFO:
// Allow to create a window bigger than the desktop
pMMI = (MINMAXINFO *)lParam;
pMMI->ptMaxTrackSize.x = 60000;
pMMI->ptMaxTrackSize.y = 60000;
break;
+ case WM_CLOSE:
+ exit(0);
+ break;
default:
break;
}
PIXELFORMATDESCRIPTOR pfd;
int iPixelFormat;
- WglDrawable(const Visual *vis, int width, int height) :
- Drawable(vis, width, height)
+ WglDrawable(const Visual *vis, int width, int height, bool pbuffer) :
+ Drawable(vis, width, height, pbuffer)
{
static bool first = TRUE;
RECT rect;
return;
}
+ Drawable::resize(w, h);
+
RECT rClient, rWindow;
GetClientRect(hWnd, &rClient);
GetWindowRect(hWnd, &rWindow);
w += (rWindow.right - rWindow.left) - rClient.right;
h += (rWindow.bottom - rWindow.top) - rClient.bottom;
SetWindowPos(hWnd, NULL, rWindow.left, rWindow.top, w, h, SWP_NOMOVE);
-
- Drawable::resize(w, h);
}
void show(void) {
wglDeleteContext(hglrc);
}
}
+
+ bool
+ create(WglDrawable *wglDrawable) {
+ if (!hglrc) {
+ hglrc = wglCreateContext(wglDrawable->hDC);
+ if (!hglrc) {
+ std::cerr << "error: wglCreateContext failed\n";
+ exit(1);
+ return false;
+ }
+ if (shareContext) {
+ if (shareContext->create(wglDrawable)) {
+ BOOL bRet;
+ bRet = wglShareLists(shareContext->hglrc,
+ hglrc);
+ if (!bRet) {
+ std::cerr
+ << "warning: wglShareLists failed: "
+ << std::hex << GetLastError() << std::dec
+ << "\n";
+ }
+ }
+ }
+ }
+
+ return true;
+ }
+
};
libgl_filename = "OPENGL32";
}
- __libGlHandle = LoadLibraryA(libgl_filename);
- if (!__libGlHandle) {
+ _libGlHandle = LoadLibraryA(libgl_filename);
+ if (!_libGlHandle) {
std::cerr << "error: unable to open " << libgl_filename << "\n";
exit(1);
}
Visual *
createVisual(bool doubleBuffer, Profile profile) {
- if (profile != PROFILE_COMPAT) {
+ if (profile != PROFILE_COMPAT &&
+ profile != PROFILE_CORE &&
+ profile != PROFILE_ES2) {
return NULL;
}
}
Drawable *
-createDrawable(const Visual *visual, int width, int height)
+createDrawable(const Visual *visual, int width, int height, bool pbuffer)
{
- return new WglDrawable(visual, width, height);
+ return new WglDrawable(visual, width, height, pbuffer);
}
Context *
-createContext(const Visual *visual, Context *shareContext, Profile profile)
+createContext(const Visual *visual, Context *shareContext, Profile profile, bool debug)
{
- if (profile != PROFILE_COMPAT) {
+ if (profile != PROFILE_COMPAT &&
+ profile != PROFILE_CORE &&
+ profile != PROFILE_ES2) {
return NULL;
}
+ switch (profile) {
+ case PROFILE_CORE:
+ std::cerr << "warning: ignoring OpenGL core profile request\n";
+ break;
+ case PROFILE_ES2:
+ std::cerr << "warning: ignoring OpenGL ES 2.0 profile request\n";
+ break;
+ default:
+ break;
+ }
+
return new WglContext(visual, profile, static_cast<WglContext *>(shareContext));
}
WglDrawable *wglDrawable = static_cast<WglDrawable *>(drawable);
WglContext *wglContext = static_cast<WglContext *>(context);
- if (!wglContext->hglrc) {
- wglContext->hglrc = wglCreateContext(wglDrawable->hDC);
- if (!wglContext->hglrc) {
- std::cerr << "error: wglCreateContext failed\n";
- exit(1);
- return false;
- }
- if (wglContext->shareContext) {
- BOOL bRet;
- bRet = wglShareLists(wglContext->shareContext->hglrc,
- wglContext->hglrc);
- if (!bRet) {
- std::cerr << "warning: wglShareLists failed\n";
- }
- }
- }
+ wglContext->create(wglDrawable);
return wglMakeCurrent(wglDrawable->hDC, wglContext->hglrc);
}
bool
processEvents(void) {
- // TODO
+ MSG uMsg;
+ while (PeekMessage(&uMsg, NULL, 0, 0, PM_REMOVE)) {
+ if (uMsg.message == WM_QUIT) {
+ return false;
+ }
+
+ if (!TranslateAccelerator(uMsg.hwnd, NULL, &uMsg)) {
+ TranslateMessage(&uMsg);
+ DispatchMessage(&uMsg);
+ }
+ }
return true;
}