17#include <main/headers.h>
23#include <libFreeWRL.h>
26#include <ui/statusbar.h>
30BOOL fwDisplayChange();
39#define ES_WINDOW_RGB 0
41#define ES_WINDOW_ALPHA 1
43#define ES_WINDOW_DEPTH 2
45#define ES_WINDOW_STENCIL 4
47#define ES_WINDOW_MULTISAMPLE 8
53 eglSwapBuffers((EGLDisplay)d->display,(EGLSurface)d->surface);
55EGLBoolean 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;
187BOOL fwDisplayChange(){
190void fwCloseContext(){
199#include <main/headers.h>
213 SwapBuffers((HDC)d->display);
216BOOL 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;
306BOOL fwDisplayChange(){
315 ret = bSetupPixelFormat(ghDC);
321 ghRC = wglCreateContext(ghDC);
322 wglMakeCurrent(ghDC, ghRC);
327void fwCloseContext(){
333 ghRC = wglGetCurrentContext();
335 wglDeleteContext(ghRC);
338 ReleaseDC(hWnd, ghDC);
352HWND fw_window32_hwnd(){
357void fwl_do_keyPress(
const char kp,
int type);
364#define VK_SEMICOLON 0xBA
367#define VK_PERIOD 0xBE
376#define VK_BACK_QUOTE 0xC0
382#define VK_BACK_SLASH 0xDC
385#define VK_EQUALS 0xBB
387#ifndef VK_OPEN_BRACKET
388#define VK_OPEN_BRACKET 0xDB
390#ifndef VK_CLOSE_BRACKET
391#define VK_CLOSE_BRACKET 0xDD
394#define VK_GR_LESS 0xE2
399static int oldx = 0, oldy = 0;
404static short gcWheelDelta = 0;
408static bool m_fullscreen =
false;
409static bool dualmonitor =
false;
410static RECT smallrect;
412bool 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);
519void 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,
563static HCURSOR hSensor, hArrow;
564static HCURSOR cursor;
567 hSensor = LoadCursor(NULL,IDC_HAND);
568 hArrow = LoadCursor( NULL, IDC_ARROW );
570void 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
586#define PPGDN_KEY VK_NEXT
587#define PLEFT_KEY VK_LEFT
588#define PEND_KEY VK_END
590#define PRIGHT_KEY VK_RIGHT
591#define PPGUP_KEY VK_PRIOR
592#define PDOWN_KEY VK_DOWN
602#define PF10_KEY VK_F10
603#define PF11_KEY VK_F11
604#define PF12_KEY VK_F12
605#define PALT_KEY VK_MENU
606#define PCTL_KEY VK_CONTROL
607#define PSFT_KEY VK_SHIFT
608#define PDEL_KEY VK_DELETE
609#define PRTN_KEY VK_RETURN
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
666int 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;
728void printbitssimple(
int n) {
731 i = 1<<(
sizeof(n) * 8 - 1);
739 if(j%8 == 0) printf(
" ");
743static HWND last_key_hWnd = NULL;
744static int clipboard_functions_registered = 0;
745static void win32_clipboard_copy(
char *str){
751 if (!OpenClipboard(last_key_hWnd))
765 hglbCopy = GlobalAlloc(GMEM_MOVEABLE,
766 (len + 1) *
sizeof(TCHAR));
767 if (hglbCopy == NULL)
775 lptstrCopy = GlobalLock(hglbCopy);
776 memcpy(lptstrCopy, str,
777 len *
sizeof(TCHAR));
778 lptstrCopy[len] = (TCHAR) 0;
779 GlobalUnlock(hglbCopy);
783 SetClipboardData(CF_TEXT, hglbCopy);
789static void win32_clipboard_paste() {
795 if (IsClipboardFormatAvailable(CF_TEXT)) {
796 if (OpenClipboard(last_key_hWnd)) {
797 hglb = GetClipboardData(CF_TEXT);
800 lptstr = GlobalLock(hglb);
803 int m, len = strlen(lptstr);
806 fwl_do_rawKeyPress(lptstr[m],KEYPRESS);
817void fwl_set_clipboard_copy(
void (*fn)(
char *));
818void fwl_set_clipboard_paste(
void (*fn));
820void statusbar_set_window_size(
int width,
int height);
821int statusbar_handle_mouse(
int mev,
int butnum,
int mouseX,
int mouseY);
822int fwl_hwnd_to_windex(
void *hWnd);
823void fwl_setScreenDim1(
int wi,
int he,
int itargetwindow);
824LRESULT CALLBACK PopupWndProc(
838static int altState = 0;
840static int shiftState = 0;
846 windex = fwl_hwnd_to_windex(hWnd);
847 last_key_hWnd = hWnd;
848 if(!clipboard_functions_registered){
849 fwl_set_clipboard_paste(win32_clipboard_paste);
850 fwl_set_clipboard_copy(win32_clipboard_copy);
851 clipboard_functions_registered = 1;
865 GetClientRect(hWnd, &rect);
874 fwl_setScreenDim1(rect.right, rect.bottom, windex);
877 case WM_DISPLAYCHANGE:
881 if(!fwDisplayChange())
890 fwl_doQuit(__FILE__,__LINE__);
900 ghDC = BeginPaint( hWnd, &ps );
902 EndPaint( hWnd, &ps );
936 if(msg==WM_KEYUP) updown = KEYUP;
938 if(lkeydata & 1 << 30)
958 keyraw = (int) wParam;
959 if(keyraw == VK_OEM_1) keyraw = (int)
';';
960 if(updown==KEYUP && keyraw == VK_DELETE)
961 fwl_do_rawKeyPress(DEL_KEY,KEYPRESS);
962 actionKey = platform2web3dActionKeyWIN32(keyraw);
964 fwl_do_rawKeyPress(actionKey,updown+10);
966 fwl_do_rawKeyPress(keyraw,updown);
1038 keyraw = (int) wParam;
1039 fwl_do_rawKeyPress(keyraw,KEYPRESS);
1042 case WM_LBUTTONDOWN:
1046 case WM_MBUTTONDOWN:
1050 case WM_RBUTTONDOWN:
1056 mev = ButtonRelease;
1060 mev = ButtonRelease;
1064 mev = ButtonRelease;
1069 pz= MAKEPOINTS(lParam);
1075#ifndef WM_MOUSEWHEEL
1076#define WM_MOUSEWHEEL 0x020A
1086 if(!(wParam & (MK_SHIFT | MK_CONTROL))) {
1088 gcWheelDelta = (short) HIWORD(wParam);
1100 return( DefWindowProc( hWnd, msg, wParam, lParam ));
1107 cursorStyle = fwl_handle_mouse(mev, butnum, mouseX, mouseY, windex);
1108 updateCursorStyle0(cursorStyle);
1115 static int eventcount = 0;
1119 while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) == TRUE)
1121 if (GetMessage(&msg, NULL, 0, 0) )
1123 TranslateMessage(&msg);
1124 DispatchMessage(&msg);
1135void fwMessageLoop(){
1139void fv_setGeometry_from_cmdline(
const char *gstring)
1144 char *str = MALLOC(
void *,
sizeof(gstring)+1);
1145 strcpy(str,gstring);
1147 for(i=0;i<(int)strlen(gstring);i++)
1148 if(str[i] ==
'x' || str[i] ==
'X')
1154 sscanf(tok[0],
"%d",&w);
1155 sscanf(tok[1],
"%d",&h);
1164void setWindowTitle()
1174 ghWnd = (
void*)((
freewrl_params_t *)(gglobal()->display.params))->winToEmbedInto;
1176 SetWindowText(ghWnd,getWindowTitle());
1182int fv_open_display()
1188static char *wgetpath = NULL;
1189TCHAR szPath[MAX_PATH];
1190static int wgetpathLoaded = 0;
1195 if( !GetModuleFileName( NULL, &szPath[1], MAX_PATH ) )
1197 printf(
"Cannot install service (%d)\n", GetLastError());
1202 wgetpath = &szPath[1];
1203 PathRemoveFileSpec(wgetpath);
1204 PathAppend(wgetpath,
"wget.exe");
1206 strcat(wgetpath,
"\"");
1220 HINSTANCE hInstance;
1222 static int wc_defined = 0;
1227 int nCmdShow = SW_SHOW;
1231 hInstance = (HANDLE)GetModuleHandle(NULL);
1263 wc.lpszClassName =
"FreeWrlAppClass";
1264 wc.lpfnWndProc = PopupWndProc;
1266 wc.style = CS_OWNDC;
1267 wc.hInstance = hInstance;
1268 wc.hIcon = LoadIcon(wc.hInstance,
"APPICON");
1270 wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
1273 wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
1274 wc.lpszMenuName = 0;
1278 RegisterClass( &wc );
1285 if (!d->fullscreen){
1289 wStyle = WS_VISIBLE | WS_POPUP | WS_BORDER | WS_SYSMENU | WS_CAPTION;
1290 wStyle |= WS_SIZEBOX;
1291 wStyle |= WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
1294 ghWnd = CreateWindowEx( WS_EX_APPWINDOW,
"FreeWrlAppClass",
"freeWRL",
1314 ShowWindow( ghWnd, SW_SHOW);
1319 UpdateWindow(ghWnd);
1323 LONG lStyle = GetWindowLong(ghWnd, GWL_STYLE);
1324 lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
1325 SetWindowLong(ghWnd, GWL_STYLE, lStyle);
1327 lExStyle = GetWindowLong(ghWnd, GWL_EXSTYLE);
1328 lExStyle &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE);
1329 SetWindowLong(ghWnd, GWL_EXSTYLE, lExStyle);
1331 SetWindowPos(ghWnd, HWND_TOP, d->xpos, d->ypos, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE);
1344 MessageBoxA(d->winToEmbedInto,
"You may now attach a debugger.1\n Press OK when you want to proceed.",
"dllfreeWRL plugin process(1)",MB_OK);
1346 if(!d->frontend_handles_display_thread){
1348 if( d->winToEmbedInto < 1)
1349 d->winToEmbedInto = (long)create_main_window0(d);
1351 if( d->winToEmbedInto )
1358 fv_create_and_bind_GLcontext(d);
1362 wglShareLists((HGLRC) share->context,(HGLRC) d->context);