17 #include <main/headers.h>
23 #include <libFreeWRL.h>
26 #include <ui/statusbar.h>
30 BOOL fwDisplayChange();
31 void fwCloseContext();
36 #include <GLES2/gl2.h>
39 #define ES_WINDOW_RGB 0
40 #define ES_WINDOW_ALPHA 1
42 #define ES_WINDOW_DEPTH 2
44 #define ES_WINDOW_STENCIL 4
46 #define ES_WINDOW_MULTISAMPLE 8
53 eglSwapBuffers((EGLDisplay)d->display,(EGLSurface)d->surface);
55 EGLBoolean fwCreateEGLContext ( EGLNativeWindowType hWnd, EGLDisplay* eglDisplay,
56 EGLContext* eglContext, EGLSurface* eglSurface,
67 EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE };
73 display = eglGetDisplay(dc);
75 if ( display == EGL_NO_DISPLAY ){
76 display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
79 if ( display == EGL_NO_DISPLAY )
81 printf(
"Ouch - EGL_NO_DISPLAY\n");
85 if ( !eglInitialize(display, &majorVersion, &minorVersion) )
88 int ierr = eglGetError();
89 sprintf(errbuf,
"%x",ierr);
98 printf(
"Ouch no eglInitialize %d %s\n",ierr,errbuf);
102 if ( !eglGetConfigs(display, NULL, 0, &numConfigs) )
104 printf(
"Ouch no eglGetConfigs\n");
109 if ( !eglChooseConfig(display, attribList, &config, 1, &numConfigs) )
115 surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType)hWnd, NULL);
116 if ( surface == EGL_NO_SURFACE )
122 context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs );
123 if ( context == EGL_NO_CONTEXT )
129 if ( !eglMakeCurrent(display, surface, surface, context) )
134 *eglDisplay = display;
135 *eglSurface = surface;
136 *eglContext = context;
142 EGLDisplay eglDisplay;
143 EGLContext eglContext;
144 EGLSurface eglSurface;
145 EGLNativeWindowType eglWindow;
146 GLuint flags = ES_WINDOW_RGB | ES_WINDOW_DEPTH | ES_WINDOW_STENCIL;
147 EGLint attribList[] =
152 EGL_ALPHA_SIZE, (flags & ES_WINDOW_ALPHA) ? 8 : EGL_DONT_CARE,
153 EGL_DEPTH_SIZE, (flags & ES_WINDOW_DEPTH) ? 24 : EGL_DONT_CARE,
154 EGL_STENCIL_SIZE, (flags & ES_WINDOW_STENCIL) ? 8 : EGL_DONT_CARE,
155 EGL_SAMPLE_BUFFERS, (flags & ES_WINDOW_MULTISAMPLE) ? 1 : 0,
171 eglWindow = (EGLNativeWindowType) d->winToEmbedInto;
172 if ( !fwCreateEGLContext (eglWindow,
178 printf(
"Ouch CreateEGLContext returns FALSE\n");
181 d->context = (
void*)eglContext;
182 d->display = (
void*)eglDisplay;
183 d->surface = (
void*)eglSurface;
187 BOOL fwDisplayChange(){
190 void fwCloseContext(){
199 #include <main/headers.h>
202 #include <internal.h>
213 SwapBuffers((HDC)d->display);
216 BOOL bSetupPixelFormat(HDC hdc)
219 PIXELFORMATDESCRIPTOR pfd, *ppfd;
224 memset(ppfd,0,
sizeof(PIXELFORMATDESCRIPTOR));
226 ppfd->nSize =
sizeof(PIXELFORMATDESCRIPTOR);
228 ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
229 if(gglobal()->display.shutterGlasses ==1)
230 ppfd->dwFlags |= PFD_STEREO;
231 ppfd->iLayerType = PFD_MAIN_PLANE;
232 ppfd->iPixelType = PFD_TYPE_RGBA;
233 ppfd->cColorBits = 24;
234 ppfd->cAlphaBits = 8;
235 ppfd->cDepthBits = 32;
237 ppfd->cStencilBits = 8;
238 ppfd->cAuxBuffers = 0;
239 ppfd->cAccumBits = 0;
242 if ( (pixelformat = ChoosePixelFormat(hdc, ppfd)) == 0 )
244 MessageBox(NULL,
"ChoosePixelFormat failed",
"Error", MB_OK);
250 DescribePixelFormat(hdc, pixelformat,
sizeof(PIXELFORMATDESCRIPTOR), ppfd);
255 if (SetPixelFormat(hdc, pixelformat, ppfd) == FALSE)
257 MessageBox(NULL,
"SetPixelFormat failed",
"Error", MB_OK);
267 hDC = (HDC)d->display;
268 hRC = (HGLRC)d->context;
269 wglMakeCurrent(hDC, hRC);
282 hWnd = (HWND)d->winToEmbedInto;
285 if (!bSetupPixelFormat(hDC))
286 printf(
"ouch - bSetupPixelFormat failed\n");
287 hRC = wglCreateContext(hDC);
294 if (wglMakeCurrent(hDC, hRC)) {
298 d->display = (
void*)hDC;
299 d->context = (
void*)hRC;
306 BOOL fwDisplayChange(){
315 ret = bSetupPixelFormat(ghDC);
321 ghRC = wglCreateContext(ghDC);
322 wglMakeCurrent(ghDC, ghRC);
327 void fwCloseContext(){
333 ghRC = wglGetCurrentContext();
335 wglDeleteContext(ghRC);
338 ReleaseDC(hWnd, ghDC);
340 #endif //ANGLEPROJECT
352 HWND fw_window32_hwnd(){
357 void fwl_do_keyPress(
const char kp,
int type);
361 #define VK_MINUS 0xBD
364 #define VK_SEMICOLON 0xBA
365 #endif // VK_SEMICOLON
367 #define VK_PERIOD 0xBE
370 #define VK_COMMA 0xBC
373 #define VK_QUOTE 0xDE
375 #ifndef VK_BACK_QUOTE
376 #define VK_BACK_QUOTE 0xC0
377 #endif // VK_BACK_QUOTE
379 #define VK_SLASH 0xBF
381 #ifndef VK_BACK_SLASH
382 #define VK_BACK_SLASH 0xDC
383 #endif // VK_BACK_SLASH
385 #define VK_EQUALS 0xBB
387 #ifndef VK_OPEN_BRACKET
388 #define VK_OPEN_BRACKET 0xDB
389 #endif // VK_OPEN_BRACKET
390 #ifndef VK_CLOSE_BRACKET
391 #define VK_CLOSE_BRACKET 0xDD
392 #endif // VK_CLOSE_BRACKET
394 #define VK_GR_LESS 0xE2
399 static int oldx = 0, oldy = 0;
404 static short gcWheelDelta = 0;
408 static bool m_fullscreen =
false;
409 static bool dualmonitor =
false;
410 static RECT smallrect;
411 void setLastCursor();
412 bool EnableFullscreen(
int w,
int h,
int bpp)
414 #if defined(ENABLEFULLSCREEN)
423 MONITORINFOEX monInfo;
426 DWORD style, exstyle;
434 hMonitor = MonitorFromWindow(ghWnd, MONITOR_DEFAULTTOPRIMARY);
435 memset(&monInfo, 0,
sizeof(MONITORINFOEX));
436 monInfo.cbSize =
sizeof(MONITORINFOEX);
437 GetMonitorInfo(hMonitor, (LPMONITORINFO)&monInfo);
441 memset(&dmode, 0,
sizeof(DEVMODE));
442 dmode.dmSize =
sizeof(DEVMODE);
444 for(i=0 ; EnumDisplaySettings(monInfo.szDevice, i, &dmode) && !foundMode ; ++i)
446 foundMode = (dmode.dmPelsWidth==(DWORD)w) &&
447 (dmode.dmPelsHeight==(DWORD)h) &&
448 (dmode.dmBitsPerPel==(DWORD)bpp);
450 ConsoleMessage(
"found w=%d h=%d bpp=%d\n",(
int)dmode.dmPelsWidth, (
int)dmode.dmPelsHeight, (
int)dmode.dmBitsPerPel);
452 if(!foundMode || debugit )
454 ConsoleMessage(
"error: suitable display mode for w=%d h=%d bpp=%d not found\n",w,h,bpp);
455 GetWindowRect(ghWnd, &smallrect);
456 ConsoleMessage(
"window rect l=%d t=%d r=%d b=%d\n",smallrect.top,smallrect.left,smallrect.right,smallrect.bottom);
459 dmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
469 GetWindowRect(ghWnd, &smallrect);
472 style = GetWindowLongPtr(ghWnd, GWL_STYLE);
473 exstyle = GetWindowLongPtr(ghWnd, GWL_EXSTYLE);
474 SetWindowLongPtr(ghWnd, GWL_STYLE, style & (~WS_OVERLAPPEDWINDOW));
475 SetWindowLongPtr(ghWnd, GWL_EXSTYLE, exstyle | WS_EX_APPWINDOW | WS_EX_TOPMOST);
481 ret = ChangeDisplaySettingsEx(monInfo.szDevice, &dmode, NULL, CDS_FULLSCREEN, NULL);
483 ret = ChangeDisplaySettings(&dmode, CDS_FULLSCREEN);
486 ok = (ret == DISP_CHANGE_SUCCESSFUL);
487 if(ok) m_fullscreen =
true;
497 GetMonitorInfo(hMonitor, (LPMONITORINFO)&monInfo);
502 SetWindowPos(ghWnd, NULL, monInfo.rcMonitor.left, monInfo.rcMonitor.top, (
int)w, (
int)h,
503 SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_NOOWNERZORDER | SWP_NOREPOSITION | SWP_NOZORDER);
509 else if(!m_fullscreen)
511 SetWindowLongPtr(ghWnd, GWL_STYLE, style);
512 SetWindowLongPtr(ghWnd, GWL_EXSTYLE, exstyle);
519 void DisableFullscreen()
521 #if defined(ENABLEFULLSCREEN)
526 MONITORINFOEX monInfo;
530 hMonitor = MonitorFromWindow(ghWnd, MONITOR_DEFAULTTOPRIMARY);
531 memset(&monInfo, 0,
sizeof(MONITORINFOEX));
532 monInfo.cbSize =
sizeof(MONITORINFOEX);
533 GetMonitorInfo(hMonitor, (LPMONITORINFO)&monInfo);
536 ChangeDisplaySettingsEx(monInfo.szDevice, NULL, NULL, 0, NULL);
539 m_fullscreen =
false;
542 style = GetWindowLongPtr(ghWnd, GWL_STYLE);
543 exstyle = GetWindowLongPtr(ghWnd, GWL_EXSTYLE);
544 SetWindowLongPtr(ghWnd, GWL_STYLE, style | WS_OVERLAPPEDWINDOW);
545 SetWindowLongPtr(ghWnd, GWL_EXSTYLE, exstyle & (~(WS_EX_APPWINDOW | WS_EX_TOPMOST)));
554 smallrect.right - smallrect.left,
555 smallrect.bottom - smallrect.top,
563 static HCURSOR hSensor, hArrow;
564 static HCURSOR cursor;
567 hSensor = LoadCursor(NULL,IDC_HAND);
568 hArrow = LoadCursor( NULL, IDC_ARROW );
570 void updateCursorStyle0(
int cstyle)
572 if(!hSensor) loadCursors();
575 SetCursor(hSensor);
break;
577 SetCursor(hArrow);
break;
579 SetCursor(NULL);
break;
585 #define PHOME_KEY VK_HOME //0x24
586 #define PPGDN_KEY VK_NEXT //0x22
587 #define PLEFT_KEY VK_LEFT //0x25
588 #define PEND_KEY VK_END //0x23
589 #define PUP_KEY VK_UP //0x26
590 #define PRIGHT_KEY VK_RIGHT //0x27
591 #define PPGUP_KEY VK_PRIOR //0x21
592 #define PDOWN_KEY VK_DOWN //0x28
593 #define PF1_KEY VK_F1 //0x70
594 #define PF2_KEY VK_F2 //0x71
595 #define PF3_KEY VK_F3 //0x72
596 #define PF4_KEY VK_F4 //0x73
597 #define PF5_KEY VK_F5 //0x74
598 #define PF6_KEY VK_F6 //0x75
599 #define PF7_KEY VK_F7 //0x76
600 #define PF8_KEY VK_F8 //0x77
601 #define PF9_KEY VK_F9 //0x78
602 #define PF10_KEY VK_F10 //0x79
603 #define PF11_KEY VK_F11 //0x7a
604 #define PF12_KEY VK_F12 //0x7b
605 #define PALT_KEY VK_MENU //0x12
606 #define PCTL_KEY VK_CONTROL //0x11
607 #define PSFT_KEY VK_SHIFT //0x10
608 #define PDEL_KEY VK_DELETE //0x2E //2E is DELETE
609 #define PRTN_KEY VK_RETURN //0x0D //13
610 #define PNUM0 VK_NUMPAD0
611 #define PNUM1 VK_NUMPAD1
612 #define PNUM2 VK_NUMPAD2
613 #define PNUM3 VK_NUMPAD3
614 #define PNUM4 VK_NUMPAD4
615 #define PNUM5 VK_NUMPAD5
616 #define PNUM6 VK_NUMPAD6
617 #define PNUM7 VK_NUMPAD7
618 #define PNUM8 VK_NUMPAD8
619 #define PNUM9 VK_NUMPAD9
620 #define PNUMDEC VK_DECIMAL
666 int platform2web3dActionKeyWIN32(
int platformKey)
671 if(platformKey >= PF1_KEY && platformKey <= PF12_KEY)
672 key = platformKey - PF1_KEY + F1_KEY;
677 key = HOME_KEY;
break;
679 key = END_KEY;
break;
681 key = PGDN_KEY;
break;
683 key = PGUP_KEY;
break;
687 key = DOWN_KEY;
break;
689 key = LEFT_KEY;
break;
691 key = RIGHT_KEY;
break;
693 key = DEL_KEY;
break;
695 key = ALT_KEY;
break;
697 key = CTL_KEY;
break;
699 key = SFT_KEY;
break;
728 void printbitssimple(
int n) {
731 i = 1<<(
sizeof(n) * 8 - 1);
739 if(j%8 == 0) printf(
" ");
742 void statusbar_set_window_size(
int width,
int height);
743 int statusbar_handle_mouse(
int mev,
int butnum,
int mouseX,
int mouseY);
744 int fwl_hwnd_to_windex(
void *hWnd);
745 void fwl_setScreenDim1(
int wi,
int he,
int itargetwindow);
746 LRESULT CALLBACK PopupWndProc(
760 static int altState = 0;
762 static int shiftState = 0;
768 windex = fwl_hwnd_to_windex(hWnd);
782 GetClientRect(hWnd, &rect);
791 fwl_setScreenDim1(rect.right, rect.bottom, windex);
794 case WM_DISPLAYCHANGE:
798 if(!fwDisplayChange())
807 fwl_doQuit(__FILE__,__LINE__);
817 ghDC = BeginPaint( hWnd, &ps );
819 EndPaint( hWnd, &ps );
853 if(msg==WM_KEYUP) updown = KEYUP;
855 if(lkeydata & 1 << 30)
875 keyraw = (int) wParam;
876 if(keyraw == VK_OEM_1) keyraw = (int)
';';
877 if(updown==KEYUP && keyraw == VK_DELETE)
878 fwl_do_rawKeyPress(DEL_KEY,KEYPRESS);
879 actionKey = platform2web3dActionKeyWIN32(keyraw);
881 fwl_do_rawKeyPress(actionKey,updown+10);
883 fwl_do_rawKeyPress(keyraw,updown);
955 keyraw = (int) wParam;
956 fwl_do_rawKeyPress(keyraw,KEYPRESS);
986 pz= MAKEPOINTS(lParam);
992 #ifndef WM_MOUSEWHEEL
993 #define WM_MOUSEWHEEL 0x020A
1003 if(!(wParam & (MK_SHIFT | MK_CONTROL))) {
1005 gcWheelDelta = (short) HIWORD(wParam);
1017 return( DefWindowProc( hWnd, msg, wParam, lParam ));
1024 cursorStyle = fwl_handle_mouse(mev, butnum, mouseX, mouseY, windex);
1025 updateCursorStyle0(cursorStyle);
1030 int doEventsWin32A()
1032 static int eventcount = 0;
1036 while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) == TRUE)
1038 if (GetMessage(&msg, NULL, 0, 0) )
1040 TranslateMessage(&msg);
1041 DispatchMessage(&msg);
1052 void fwMessageLoop(){
1056 void fv_setGeometry_from_cmdline(
const char *gstring)
1061 char *str = MALLOC(
void *,
sizeof(gstring)+1);
1062 strcpy(str,gstring);
1064 for(i=0;i<(int)strlen(gstring);i++)
1065 if(str[i] ==
'x' || str[i] ==
'X')
1071 sscanf(tok[0],
"%d",&w);
1072 sscanf(tok[1],
"%d",&h);
1081 void setWindowTitle()
1091 ghWnd = (
void*)((
freewrl_params_t *)(gglobal()->display.params))->winToEmbedInto;
1093 SetWindowText(ghWnd,getWindowTitle());
1099 int fv_open_display()
1105 static char *wgetpath = NULL;
1106 TCHAR szPath[MAX_PATH];
1107 static int wgetpathLoaded = 0;
1112 if( !GetModuleFileName( NULL, &szPath[1], MAX_PATH ) )
1114 printf(
"Cannot install service (%d)\n", GetLastError());
1119 wgetpath = &szPath[1];
1120 PathRemoveFileSpec(wgetpath);
1121 PathAppend(wgetpath,
"wget.exe");
1123 strcat(wgetpath,
"\"");
1137 HINSTANCE hInstance;
1139 static int wc_defined = 0;
1144 int nCmdShow = SW_SHOW;
1148 hInstance = (HANDLE)GetModuleHandle(NULL);
1180 wc.lpszClassName =
"FreeWrlAppClass";
1181 wc.lpfnWndProc = PopupWndProc;
1183 wc.style = CS_OWNDC;
1184 wc.hInstance = hInstance;
1185 wc.hIcon = LoadIcon(wc.hInstance,
"APPICON");
1187 wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
1190 wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
1191 wc.lpszMenuName = 0;
1195 RegisterClass( &wc );
1202 if (!d->fullscreen){
1206 wStyle = WS_VISIBLE | WS_POPUP | WS_BORDER | WS_SYSMENU | WS_CAPTION;
1207 wStyle |= WS_SIZEBOX;
1208 wStyle |= WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
1211 ghWnd = CreateWindowEx( WS_EX_APPWINDOW,
"FreeWrlAppClass",
"freeWRL",
1231 ShowWindow( ghWnd, SW_SHOW);
1236 UpdateWindow(ghWnd);
1240 LONG lStyle = GetWindowLong(ghWnd, GWL_STYLE);
1241 lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
1242 SetWindowLong(ghWnd, GWL_STYLE, lStyle);
1244 lExStyle = GetWindowLong(ghWnd, GWL_EXSTYLE);
1245 lExStyle &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE);
1246 SetWindowLong(ghWnd, GWL_EXSTYLE, lExStyle);
1248 SetWindowPos(ghWnd, HWND_TOP, d->xpos, d->ypos, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE);
1261 MessageBoxA(d->winToEmbedInto,
"You may now attach a debugger.1\n Press OK when you want to proceed.",
"dllfreeWRL plugin process(1)",MB_OK);
1263 if(!d->frontend_handles_display_thread){
1265 if( d->winToEmbedInto < 1)
1266 d->winToEmbedInto = (long)create_main_window0(d);
1268 if( d->winToEmbedInto )
1275 fv_create_and_bind_GLcontext(d);
1276 #ifndef ANGLEPROJECT
1279 wglShareLists((HGLRC) share->context,(HGLRC) d->context);