39 using namespace vlEGL;
46 void win32PrintError(LPTSTR lpszFunction)
50 DWORD dw = GetLastError();
53 FORMAT_MESSAGE_ALLOCATE_BUFFER |
54 FORMAT_MESSAGE_FROM_SYSTEM,
57 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
62 L
"%s failed with error %d: %s",
63 lpszFunction, dw, lpMsgBuf);
65 MessageBox(
NULL, szBuf, L
"Visualization Library Error", MB_OK);
73 static bool class_already_registered =
false;
74 if (!class_already_registered)
77 memset(&wc, 0,
sizeof(wc));
79 wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
80 wc.lpfnWndProc = (WNDPROC)EGLWindow::WindowProc;
83 wc.hInstance = GetModuleHandle(
NULL);
84 wc.hIcon = LoadIcon(
NULL, IDI_WINLOGO);
85 wc.hCursor = LoadCursor(
NULL, IDC_ARROW);
86 wc.hbrBackground =
NULL;
87 wc.lpszMenuName =
NULL;
88 wc.lpszClassName = EGLWindow::EGLWindowClassName;
90 if (!RegisterClass(&wc))
91 MessageBox(
NULL, L
"Class registration failed.", L
"Visualization Library Error", MB_OK);
93 class_already_registered =
true;
95 return class_already_registered;
99 const wchar_t* EGLWindow::EGLWindowClassName = L
"VisualizationLibraryWindowClass";
101 std::map< HWND, EGLWindow* > EGLWindow::mWinMap;
103 LONG WINAPI EGLWindow::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
105 EGLWindow* win = EGLWindow::getWindow(hWnd);
107 return (LONG)DefWindowProc(hWnd, uMsg, wParam, lParam);
114 LONG val = (LONG)DefWindowProc(hWnd, uMsg, wParam, lParam);
130 POINTS pt = MAKEPOINTS(lParam);
135 case WM_LBUTTONDBLCLK:
137 case WM_MBUTTONDBLCLK:
139 case WM_RBUTTONDBLCLK:
144 SetCapture(win->
hwnd());
146 if (uMsg == WM_LBUTTONDBLCLK || uMsg == WM_LBUTTONDOWN)
148 else if (uMsg == WM_MBUTTONDBLCLK || uMsg == WM_MBUTTONDOWN)
150 else if (uMsg == WM_RBUTTONDBLCLK || uMsg == WM_RBUTTONDOWN)
152 POINTS pt = MAKEPOINTS(lParam);
168 if (uMsg == WM_LBUTTONUP)
170 else if (uMsg == WM_MBUTTONUP)
172 else if (uMsg == WM_RBUTTONUP)
174 POINTS pt = MAKEPOINTS(lParam);
197 EGLWindow::mWinMap.erase(hWnd);
205 unsigned short unicode_out = 0;
214 unsigned short unicode_out = 0;
223 HDROP hDrop = (HDROP)wParam;
224 int count = DragQueryFile(hDrop, 0xFFFFFFFF, 0, 0);
225 const int char_count = 1024;
226 std::vector<String> files;
227 for(
int i=0; i<count; ++i)
229 wchar_t file_path[char_count];
230 memset(file_path, 0, char_count);
231 DragQueryFile(hDrop,i,file_path,char_count);
232 files.push_back(file_path);
247 return (LONG)DefWindowProc(hWnd, uMsg, wParam, lParam);
252 EGLWindow::EGLWindow()
261 mStyle = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
262 mExStyle = WS_EX_APPWINDOW | WS_EX_ACCEPTFILES;
263 mWindowClassName = EGLWindowClassName;
266 EGLWindow::~EGLWindow()
268 destroyEGLGLWindow();
273 destroyEGLGLWindow();
278 unsigned style = mStyle & ~(WS_CHILD|WS_OVERLAPPEDWINDOW);;
279 style |= parent?WS_CHILD:WS_OVERLAPPEDWINDOW;
281 mHWND = CreateWindowEx(
284 L
"Visualization Library's EGLWindow",
289 setWindowTitle(title);
295 EGLint attrib_list[] =
309 mEGL_Display = eglGetDisplay(GetDC(mHWND));
310 if ( mEGL_Display == EGL_NO_DISPLAY )
316 EGLint maj_version=0, min_version=0;
317 if ( !eglInitialize(mEGL_Display, &maj_version, &min_version) )
323 EGLint num_configs = 0;
324 if ( !eglGetConfigs(mEGL_Display,
NULL, 0, &num_configs) )
330 EGLConfig configurations[32] = {0};
331 if ( !eglChooseConfig(mEGL_Display, attrib_list, configurations, 32, &num_configs) )
337 for(
int i=0; i<num_configs; ++i)
339 printf(
"EGLConfig #%d:\n", i);
341 eglGetConfigAttrib( mEGL_Display, configurations[i], EGL_RED_SIZE, &value); printf(
"EGL_RED_SIZE = %d\n", value);
342 eglGetConfigAttrib( mEGL_Display, configurations[i], EGL_GREEN_SIZE, &value); printf(
"EGL_GREEN_SIZE = %d\n", value);
343 eglGetConfigAttrib( mEGL_Display, configurations[i], EGL_BLUE_SIZE, &value); printf(
"EGL_BLUE_SIZE = %d\n", value);
344 eglGetConfigAttrib( mEGL_Display, configurations[i], EGL_ALPHA_SIZE, &value); printf(
"EGL_ALPHA_SIZE = %d\n", value);
345 eglGetConfigAttrib( mEGL_Display, configurations[i], EGL_DEPTH_SIZE, &value); printf(
"EGL_DEPTH_SIZE = %d\n", value);
346 eglGetConfigAttrib( mEGL_Display, configurations[i], EGL_STENCIL_SIZE, &value); printf(
"EGL_STENCIL_SIZE = %d\n", value);
351 EGLConfig selected_config = configurations[0];
354 mEGL_Surface = eglCreateWindowSurface(mEGL_Display, selected_config, (EGLNativeWindowType)mHWND,
NULL);
355 if ( mEGL_Surface == EGL_NO_SURFACE )
361 mEGL_Context = eglCreateContext(mEGL_Display, selected_config, EGL_NO_CONTEXT, client_version );
362 if ( mEGL_Context == EGL_NO_CONTEXT )
368 if ( !eglMakeCurrent(mEGL_Display, mEGL_Surface, mEGL_Surface, mEGL_Context) )
373 if ( !initGLContext() )
377 mWinMap[mHWND] =
this;
380 eglSwapInterval(mEGL_Display, fmt.
vSync() ? 1 : 0);
386 setSize(width, height);
391 void EGLWindow::swapBuffers()
394 if ( !eglSwapBuffers(mEGL_Display, mEGL_Surface) && mEGL_Surface )
396 Log::error(
"EGLWindow::swapBuffers() failed!\n");
400 void EGLWindow::makeCurrent()
402 if ( !eglMakeCurrent(mEGL_Display, mEGL_Surface, mEGL_Surface, mEGL_Context) )
404 Log::error(
"EGLWindow::makeCurrent() failed!\n");
408 void EGLWindow::update()
411 PostMessage(hwnd(), WM_PAINT, 0, 0);
414 void EGLWindow::quitApplication()
419 void EGLWindow::setMouseVisible(
bool visible)
421 mMouseVisible = visible;
423 while(ShowCursor(TRUE ) < 0) {}
425 while(ShowCursor(FALSE) >= 0) {}
428 void EGLWindow::setPosition(
int x,
int y)
431 SetWindowPos(hwnd(), 0, x, y, 0, 0, SWP_NOSIZE );
434 void EGLWindow::setSize(
int w,
int h)
438 RECT windowRect = { 0, 0, w, h };
439 AdjustWindowRectEx(&windowRect, (DWORD)GetWindowLongPtr(hwnd(), GWL_STYLE), 0, (DWORD)GetWindowLongPtr(hwnd(), GWL_EXSTYLE) );
441 int cx = windowRect.right - windowRect.left;
442 int cy = windowRect.bottom - windowRect.top;
443 SetWindowPos(hwnd(), 0, 0, 0, cx, cy, SWP_NOMOVE );
447 void EGLWindow::setWindowSize(
int w,
int h)
453 SetWindowPos(hwnd(), 0, 0, 0, w, h, SWP_NOMOVE);
460 GetWindowRect(hwnd(), &r);
468 GetWindowRect(hwnd(), &r);
469 return vl::ivec2(r.right - r.left, r.bottom - r.top);
476 GetClientRect(hwnd(), &r);
477 return vl::ivec2(r.right - r.left, r.bottom - r.top);
480 void EGLWindow::setWindowTitle(
const String& title)
483 SetWindowText(hwnd(), (
wchar_t*)title.
ptr());
486 void EGLWindow::show()
489 ShowWindow(hwnd(), SW_SHOW);
492 void EGLWindow::hide()
495 ShowWindow(hwnd(), SW_HIDE);
498 void EGLWindow::getFocus()
504 void EGLWindow::setMousePosition(
int x,
int y)
509 ClientToScreen( hwnd(), &pt );
510 SetCursorPos(pt.x, pt.y);
516 std::map< HWND, EGLWindow* >::const_iterator it = mWinMap.find(hWnd);
517 if (it != mWinMap.end())
523 void EGLWindow::destroyEGLGLWindow()
527 bool destroy_win = mWinMap.find(mHWND) != mWinMap.end();
532 DestroyWindow(mHWND);
536 eglDestroyContext ( eglDisplay(), eglContext() ); mEGL_Context =
NULL;
537 eglDestroySurface ( eglDisplay(), eglSurface() ); mEGL_Surface =
NULL;
538 eglTerminate ( eglDisplay() ); mEGL_Display =
NULL;
545 std::map< HWND, EGLWindow* > wins = EGLWindow::winMap();
546 for( std::map< HWND, EGLWindow* >::iterator it = wins.begin();
560 if ( PeekMessage(&msg,
NULL, 0, 0, PM_REMOVE) )
562 if (msg.message != WM_QUIT)
564 TranslateMessage(&msg);
565 DispatchMessage(&msg);
574 while(!EGLWindow::winMap().empty())
576 MSG msg = {0,0,0,0,0,0,0};
578 if (msg.message == WM_QUIT)
579 return (
int)msg.wParam;
592 case VK_CLEAR: key_out =
Key_Clear;
break;
593 case VK_CONTROL: key_out =
Key_Ctrl;
break;
596 case VK_MENU: key_out =
Key_Alt;
break;
599 case VK_SHIFT: key_out =
Key_Shift;
break;
604 case VK_HOME: key_out =
Key_Home;
break;
605 case VK_END: key_out =
Key_End;
break;
606 case VK_PRINT: key_out =
Key_Print;
break;
607 case VK_PAUSE: key_out =
Key_Pause;
break;
610 case VK_LEFT: key_out =
Key_Left;
break;
611 case VK_RIGHT: key_out =
Key_Right;
break;
612 case VK_UP: key_out =
Key_Up;
break;
613 case VK_DOWN: key_out =
Key_Down;
break;
614 case VK_F1: key_out =
Key_F1;
break;
615 case VK_F2: key_out =
Key_F2;
break;
616 case VK_F3: key_out =
Key_F3;
break;
617 case VK_F4: key_out =
Key_F4;
break;
618 case VK_F5: key_out =
Key_F5;
break;
619 case VK_F6: key_out =
Key_F6;
break;
620 case VK_F7: key_out =
Key_F7;
break;
621 case VK_F8: key_out =
Key_F8;
break;
622 case VK_F9: key_out =
Key_F9;
break;
623 case VK_F10: key_out =
Key_F10;
break;
624 case VK_F11: key_out =
Key_F11;
break;
625 case VK_F12: key_out =
Key_F12;
break;
633 case L
'0': key_out =
Key_0;
break;
634 case L
'1': key_out =
Key_1;
break;
635 case L
'2': key_out =
Key_2;
break;
636 case L
'3': key_out =
Key_3;
break;
637 case L
'4': key_out =
Key_4;
break;
638 case L
'5': key_out =
Key_5;
break;
639 case L
'6': key_out =
Key_6;
break;
640 case L
'7': key_out =
Key_7;
break;
641 case L
'8': key_out =
Key_8;
break;
642 case L
'9': key_out =
Key_9;
break;
644 case L
'A': key_out =
Key_A;
break;
645 case L
'B': key_out =
Key_B;
break;
646 case L
'C': key_out =
Key_C;
break;
647 case L
'D': key_out =
Key_D;
break;
648 case L
'E': key_out =
Key_E;
break;
649 case L
'F': key_out =
Key_F;
break;
650 case L
'G': key_out =
Key_G;
break;
651 case L
'H': key_out =
Key_H;
break;
652 case L
'I': key_out =
Key_I;
break;
653 case L
'J': key_out =
Key_J;
break;
654 case L
'K': key_out =
Key_K;
break;
655 case L
'L': key_out =
Key_L;
break;
656 case L
'M': key_out =
Key_M;
break;
657 case L
'N': key_out =
Key_N;
break;
658 case L
'O': key_out =
Key_O;
break;
659 case L
'P': key_out =
Key_P;
break;
660 case L
'Q': key_out =
Key_Q;
break;
661 case L
'R': key_out =
Key_R;
break;
662 case L
'S': key_out =
Key_S;
break;
663 case L
'T': key_out =
Key_T;
break;
664 case L
'U': key_out =
Key_U;
break;
665 case L
'V': key_out =
Key_V;
break;
666 case L
'W': key_out =
Key_W;
break;
667 case L
'X': key_out =
Key_X;
break;
668 case L
'Y': key_out =
Key_Y;
break;
669 case L
'Z': key_out =
Key_Z;
break;
674 memset( mskeys, 0,
sizeof(BYTE)*256 );
675 WCHAR unicode[4] = { 0, 0 };
676 if ( ToUnicode( (UINT)wParam, (UINT)((lParam >> 16) & 0xFF), mskeys, unicode, 4, 0 ) == 1 )
678 unicode_out = unicode[0];
683 case L
'0': key_out =
Key_0;
break;
684 case L
'1': key_out =
Key_1;
break;
685 case L
'2': key_out =
Key_2;
break;
686 case L
'3': key_out =
Key_3;
break;
687 case L
'4': key_out =
Key_4;
break;
688 case L
'5': key_out =
Key_5;
break;
689 case L
'6': key_out =
Key_6;
break;
690 case L
'7': key_out =
Key_7;
break;
691 case L
'8': key_out =
Key_8;
break;
692 case L
'9': key_out =
Key_9;
break;
694 case L
'A': key_out =
Key_A;
break;
695 case L
'B': key_out =
Key_B;
break;
696 case L
'C': key_out =
Key_C;
break;
697 case L
'D': key_out =
Key_D;
break;
698 case L
'E': key_out =
Key_E;
break;
699 case L
'F': key_out =
Key_F;
break;
700 case L
'G': key_out =
Key_G;
break;
701 case L
'H': key_out =
Key_H;
break;
702 case L
'I': key_out =
Key_I;
break;
703 case L
'J': key_out =
Key_J;
break;
704 case L
'K': key_out =
Key_K;
break;
705 case L
'L': key_out =
Key_L;
break;
706 case L
'M': key_out =
Key_M;
break;
707 case L
'N': key_out =
Key_N;
break;
708 case L
'O': key_out =
Key_O;
break;
709 case L
'P': key_out =
Key_P;
break;
710 case L
'Q': key_out =
Key_Q;
break;
711 case L
'R': key_out =
Key_R;
break;
712 case L
'S': key_out =
Key_S;
break;
713 case L
'T': key_out =
Key_T;
break;
714 case L
'U': key_out =
Key_U;
break;
715 case L
'V': key_out =
Key_V;
break;
716 case L
'W': key_out =
Key_W;
break;
717 case L
'X': key_out =
Key_X;
break;
718 case L
'Y': key_out =
Key_Y;
break;
719 case L
'Z': key_out =
Key_Z;
break;
721 case L
'a': key_out =
Key_A;
break;
722 case L
'b': key_out =
Key_B;
break;
723 case L
'c': key_out =
Key_C;
break;
724 case L
'd': key_out =
Key_D;
break;
725 case L
'e': key_out =
Key_E;
break;
726 case L
'f': key_out =
Key_F;
break;
727 case L
'g': key_out =
Key_G;
break;
728 case L
'h': key_out =
Key_H;
break;
729 case L
'i': key_out =
Key_I;
break;
730 case L
'j': key_out =
Key_J;
break;
731 case L
'k': key_out =
Key_K;
break;
732 case L
'l': key_out =
Key_L;
break;
733 case L
'm': key_out =
Key_M;
break;
734 case L
'n': key_out =
Key_N;
break;
735 case L
'o': key_out =
Key_O;
break;
736 case L
'p': key_out =
Key_P;
break;
737 case L
'q': key_out =
Key_Q;
break;
738 case L
'r': key_out =
Key_R;
break;
739 case L
's': key_out =
Key_S;
break;
740 case L
't': key_out =
Key_T;
break;
741 case L
'u': key_out =
Key_U;
break;
742 case L
'v': key_out =
Key_V;
break;
743 case L
'w': key_out =
Key_W;
break;
744 case L
'x': key_out =
Key_X;
break;
745 case L
'y': key_out =
Key_Y;
break;
746 case L
'z': key_out =
Key_Z;
break;
750 case 9: key_out =
Key_Tab;
break;
756 case L
'#': key_out =
Key_Hash;
break;
763 case L
'+': key_out =
Key_Plus;
break;
770 case L
'<': key_out =
Key_Less;
break;
774 case L
'@': key_out =
Key_At;
break;
void dispatchKeyReleaseEvent(unsigned short unicode_ch, EKey key)
Dispatches the UIEventListener::keyReleaseEvent() notification to the subscribed UIEventListener obje...
Vector2< int > ivec2
A 2 components vector with int precision.
void setHeight(int height)
The height of a render target.
int stencilBufferBits() const
void dispatchMouseDownEvent(EMouseButton button, int x, int y)
Dispatches the UIEventListener::mouseDownEvent() notification to the subscribed UIEventListener objec...
VLEGL_EXPORT int messageLoop()
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
int multisampleSamples() const
const T_Scalar & r() const
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
const EGLSurface & eglSurface() const
void dispatchKeyPressEvent(unsigned short unicode_ch, EKey key)
Dispatches the UIEventListener::keyPressEvent() notification to the subscribed UIEventListener object...
void dispatchResizeEvent(int w, int h)
Dispatches the UIEventListener::resizeEvent() notification to the subscribed UIEventListener objects...
const wchar_t * ptr() const
Returns the 0-terminated utf16 string.
void setWidth(int width)
The width of a render target.
FramebufferObject * framebuffer()
The default render target (always returns leftFramebuffer()).
void destroyEGLGLWindow()
Destroys the window and the OpenGL rendering context.
Visualization Library main namespace.
VLEGL_EXPORT void peekMessage(MSG &msg)
const EGLContext & eglContext() const
const T_Scalar & g() const
bool continuousUpdate() const
If the OpenGL context is a widget this function returns whether its area is continuously updated at e...
void dispatchUpdateEvent()
Dispatches the UIEventListener::updateEvent() notification to the subscribed UIEventListener objects...
The OpenGLContextFormat class encapsulates the settings of an OpenGL rendering context.
const ivec4 & rgbaBits() const
void update()
If the OpenGLContext is a widget this function requests a redraw and generates an updateEvent()...
const T_Scalar & b() const
void dispatchMouseWheelEvent(int n)
Dispatches the UIEventListener::mouseWheelEvent() notification to the subscribed UIEventListener obje...
int contextClientVersion() const
Used by EGLWindow to initialize either GLES 1.x or GLES 2.x contexts.
VLEGL_EXPORT void translateKeyEvent(WPARAM wParam, LPARAM lParam, unsigned short &unicode_out, vl::EKey &key_out)
The experimental EGL bindings namespace.
void dispatchDestroyEvent()
Dispatches the UIEventListener::destroyEvent() notification to the subscribed UIEventListener(s), calls destroyAllOpenGLResources() and eraseAllEventListeners() This event must be issued just before the actual GL context is destroyed.
void dispatchFileDroppedEvent(const std::vector< String > &files)
Dispatches the UIEventListener::fileDroppedEvent() notification to the subscribed UIEventListener obj...
int depthBufferBits() const
The EGLWindow class is a EGLContext that can be used as a top or child window.
void dispatchMouseMoveEvent(int x, int y)
Dispatches the UIEventListener::mouseMoveEvent() notification to the subscribed UIEventListener objec...
const T_Scalar & a() const
void dispatchMouseUpEvent(EMouseButton button, int x, int y)
Dispatches the UIEventListener::mouseUpEvent() notification to the subscribed UIEventListener objects...
VLEGL_EXPORT void dispatchUpdate()