FreeWRL/FreeX3D  3.0.0
fwWindow32.c
1 /*
2 
3  FreeWRL support library.
4  FreeWRL main window : win32 code.
5 
6 */
7 /* #define WIN32_LEAN_AND_MEAN 1*/
8 
9 
10 
11 #include <config.h>
12 
13 #if defined(_MSC_VER)
14 
15 #include <system.h>
16 #include <display.h>
17 #include <main/headers.h>
18 #include <windows.h>
19 #include <shlwapi.h>
20 
21 #include <internal.h>
22 
23 #include <libFreeWRL.h>
24 #include <float.h>
25 #include "common.h"
26 #include <ui/statusbar.h>
27 
28 void fv_swapbuffers(freewrl_params_t * d);
29 bool fv_create_and_bind_GLcontext(freewrl_params_t * d);
30 BOOL fwDisplayChange();
31 void fwCloseContext();
32 
33 
34 #ifdef ANGLEPROJECT
35 //gles2 and egl
36 #include <GLES2/gl2.h>
37 #include <EGL/egl.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
48 
49 //static EGLDisplay eglDisplay;
50 //static EGLContext eglContext;
51 //static EGLSurface eglSurface;
52 void fv_swapbuffers(freewrl_params_t * d){
53  eglSwapBuffers((EGLDisplay)d->display,(EGLSurface)d->surface);
54 }
55 EGLBoolean fwCreateEGLContext ( EGLNativeWindowType hWnd, EGLDisplay* eglDisplay,
56  EGLContext* eglContext, EGLSurface* eglSurface,
57  EGLint attribList[])
58 {
59  EGLint numConfigs;
60  EGLint majorVersion;
61  EGLint minorVersion;
62  EGLDisplay display;
63  EGLContext context;
64  EGLSurface surface;
65  EGLConfig config;
66  HDC dc;
67  EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE };
68 
69  // Get Display
70  dc = GetDC(hWnd);
71  //printf("hWnd=%d\n",hWnd);
72  //printf("dc=%d\n",dc);
73  display = eglGetDisplay(dc); //GetDC(hWnd));
74 // printf("display=%d\n",display);
75  if ( display == EGL_NO_DISPLAY ){
76  display = eglGetDisplay(EGL_DEFAULT_DISPLAY); //win32 goes in here
77 // printf("display2=%d\n",display);
78  }
79  if ( display == EGL_NO_DISPLAY )
80  {
81  printf("Ouch - EGL_NO_DISPLAY\n");
82  return EGL_FALSE;
83  }
84  // Initialize EGL
85  if ( !eglInitialize(display, &majorVersion, &minorVersion) )
86  {
87  char errbuf[64];
88  int ierr = eglGetError();
89  sprintf(errbuf,"%x",ierr); //0x3001 EGL_NOT_INITIALIZED
90  //note to developer: 1) have you compiled fwlibEGL.lib/dll and fwlibGLES2.lib/dll with same/compatible compiler (egl calls glesv2 for renderer)
91  //2) do you have d3dcompiler_47+.dll in your .exe directory? (or d3dcompiler_46.dll, _43, installed to system32 via SetupDirect.exe?)
92  //3) are you using an angleproject hacked by dug9 in Renderer.cpp L.56 to do a LoadLibrary loop after the GetModuleHandleEx loop:
93  //if (!mD3dCompilerModule){
94  // //OK not preloaded. So lets try and load one
95  // for (size_t i = 0; i < ArraySize(d3dCompilerNames); ++i){
96  // if( mD3dCompilerModule = LoadLibrary(d3dCompilerNames[i])){
97  // break;
98  printf("Ouch no eglInitialize %d %s\n",ierr,errbuf);
99  return EGL_FALSE;
100  }
101  // Get configs
102  if ( !eglGetConfigs(display, NULL, 0, &numConfigs) )
103  {
104  printf("Ouch no eglGetConfigs\n");
105  return EGL_FALSE;
106  }
107 
108  // Choose config
109  if ( !eglChooseConfig(display, attribList, &config, 1, &numConfigs) )
110  {
111  return EGL_FALSE;
112  }
113 
114  // Create a surface
115  surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType)hWnd, NULL);
116  if ( surface == EGL_NO_SURFACE )
117  {
118  return EGL_FALSE;
119  }
120 
121  // Create a GL context
122  context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs );
123  if ( context == EGL_NO_CONTEXT )
124  {
125  return EGL_FALSE;
126  }
127 
128  // Make the context current
129  if ( !eglMakeCurrent(display, surface, surface, context) )
130  {
131  return EGL_FALSE;
132  }
133 
134  *eglDisplay = display;
135  *eglSurface = surface;
136  *eglContext = context;
137  return EGL_TRUE;
138 }
139 
140 bool fv_create_and_bind_GLcontext(freewrl_params_t * d){
141  //modified
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[] =
148  {
149  EGL_RED_SIZE, 8,
150  EGL_GREEN_SIZE, 8,
151  EGL_BLUE_SIZE, 8,
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,
156  EGL_NONE
157  };
158 
159  //if ( esContext == NULL )
160  //{
161  // return GL_FALSE;
162  //}
163 
164  //esContext->width = width;
165  //esContext->height = height;
166 
167  //if ( !WinCreate ( esContext, title) )
168  //{
169  // return GL_FALSE;
170  //}
171  eglWindow = (EGLNativeWindowType) d->winToEmbedInto;
172  if ( !fwCreateEGLContext (eglWindow, // d->winToEmbedInto,
173  &eglDisplay,
174  &eglContext,
175  &eglSurface,
176  attribList) )
177  {
178  printf("Ouch CreateEGLContext returns FALSE\n");
179  return GL_FALSE;
180  }
181  d->context = (void*)eglContext;
182  d->display = (void*)eglDisplay;
183  d->surface = (void*)eglSurface;
184  return GL_TRUE;
185 
186 }
187 BOOL fwDisplayChange(){
188  return GL_FALSE;
189 }
190 void fwCloseContext(){
191 }
192 void fv_change_GLcontext(freewrl_params_t* d){
193  return; //stub for ANLGEPROJECT, EGL/GLES2, mobile which don't change context but need to link
194 }
195 
196 #else //ANGLEPROJECT
197 //desktop GL and wgl functions
198 #include <display.h>
199 #include <main/headers.h>
200 #include <shlwapi.h>
201 
202 #include <internal.h>
203 
204 #include <float.h>
205 #include "common.h"
206 
207 
208 void fv_swapbuffers(freewrl_params_t * d)
209 {
210  //HDC ghDC;
211  //ghDC = wglGetCurrentDC();
212  //SwapBuffers(ghDC);
213  SwapBuffers((HDC)d->display);
214 }
215 
216 BOOL bSetupPixelFormat(HDC hdc)
217 {
218  /* http://msdn.microsoft.com/en-us/library/dd318284(VS.85).aspx */
219  PIXELFORMATDESCRIPTOR pfd, *ppfd;
220  int pixelformat;
221 
222  ppfd = &pfd;
223 
224  memset(ppfd,0,sizeof(PIXELFORMATDESCRIPTOR));
225 
226  ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
227  ppfd->nVersion = 1;
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; /* PFD_TYPE_COLORINDEX; */
233  ppfd->cColorBits = 24;
234  ppfd->cAlphaBits = 8;
235  ppfd->cDepthBits = 32;
236  //not using accum now, using color masks ppfd->cAccumBits = 64; /*need accum buffer for shader anaglyph - 8 bits per channel OK*/
237  ppfd->cStencilBits = 8;
238  ppfd->cAuxBuffers = 0;
239  ppfd->cAccumBits = 0;
240 
241  /* pixelformat = ChoosePixelFormat(hdc, ppfd); */
242  if ( (pixelformat = ChoosePixelFormat(hdc, ppfd)) == 0 )
243  {
244  MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
245  return FALSE;
246  }
247 
248  /* seems to fail stereo gracefully/quietly, allowing you to detect with glGetbooleanv(GL_STEREO,) in shared code
249  */
250  DescribePixelFormat(hdc, pixelformat, sizeof(PIXELFORMATDESCRIPTOR), ppfd);
251  //printf("Depth Bits = %d\n",(int)(ppfd->cDepthBits));
252  //if(gglobal()->display.shutterGlasses > 0)
253  // printf("got stereo? = %d\n",(int)(ppfd->dwFlags & PFD_STEREO));
254 
255  if (SetPixelFormat(hdc, pixelformat, ppfd) == FALSE)
256  {
257  MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);
258  return FALSE;
259  }
260 
261  return TRUE;
262 }
263 void fv_change_GLcontext(freewrl_params_t* d){
264  HDC hDC;
265  HGLRC hRC;
266  //HWND hWnd;
267  hDC = (HDC)d->display;
268  hRC = (HGLRC)d->context;
269  wglMakeCurrent(hDC, hRC);
270 }
271 
272 bool fv_create_and_bind_GLcontext(freewrl_params_t* d)
273 {
274 
275  HDC hDC;
276  HGLRC hRC;
277  HWND hWnd;
278 
279  /* create GL context */
280  //fwl_thread_dump();
281  //printf("starting createcontext32b\n");
282  hWnd = (HWND)d->winToEmbedInto;
283  hDC = GetDC(hWnd);
284  //printf("got hdc\n");
285  if (!bSetupPixelFormat(hDC))
286  printf("ouch - bSetupPixelFormat failed\n");
287  hRC = wglCreateContext(hDC);
288  //printf("created context\n");
289  /* bind GL context */
290 
291  //fwl_thread_dump();
292  //width = tg->display.screenWidth;
293  //height = tg->display.screenHeight;
294  if (wglMakeCurrent(hDC, hRC)) {
295  //GetClientRect(hWnd, &rect);
296  //gglobal()->display.screenWidth = rect.right; /*used in mainloop render_pre setup_projection*/
297  //gglobal()->display.screenHeight = rect.bottom;
298  d->display = (void*)hDC;
299  d->context = (void*)hRC;
300  d->surface = hWnd;
301  return TRUE;
302  }
303  return FALSE;
304 
305 }
306 BOOL fwDisplayChange(){
307  BOOL ret;
308  HWND hWnd;
309  HGLRC ghRC;
310  HDC ghDC;
311  ttglobal tg = gglobal();
312  hWnd = (HWND)((freewrl_params_t*)tg->display.params)->winToEmbedInto;
313 
314  ghDC = GetDC(hWnd);
315  ret = bSetupPixelFormat(ghDC);
316  //printf("WM_DISPLAYCHANGE happening now\n");
317 
318  /* ???? do we have to recreate an OpenGL context
319  when display mode changed ? */
320  if(ret){
321  ghRC = wglCreateContext(ghDC);
322  wglMakeCurrent(ghDC, ghRC);
323  }
324  return ret;
325 }
326 
327 void fwCloseContext(){
328  HWND hWnd;
329  HGLRC ghRC;
330  HDC ghDC;
331  ttglobal tg = gglobal();
332  hWnd = (HWND)((freewrl_params_t *)tg->display.params)->winToEmbedInto;
333  ghRC = wglGetCurrentContext();
334  if (ghRC)
335  wglDeleteContext(ghRC);
336  ghDC = GetDC(hWnd);
337  if (ghDC)
338  ReleaseDC(hWnd, ghDC);
339 }
340 #endif //ANGLEPROJECT
341 
342 
343 
344 //HWND ghWnd; /* on a hunch I made these static so they are once per program */
345 //HDC ghDC;
346 //HGLRC ghRC;
347 //
348 //HWND fw_window32_hwnd()
349 //{
350 // return ghWnd;
351 //}
352 HWND fw_window32_hwnd(){
353  ttglobal tg = (ttglobal)gglobal();
354  return (HWND)((freewrl_params_t *)tg->display.params)->winToEmbedInto;
355 }
356 
357 void fwl_do_keyPress(const char kp, int type);
358 
359 /* from Blender GHOST_SystemWin32.cpp: Key code values not found in winuser.h */
360 #ifndef VK_MINUS
361 #define VK_MINUS 0xBD
362 #endif // VK_MINUS
363 #ifndef VK_SEMICOLON
364 #define VK_SEMICOLON 0xBA
365 #endif // VK_SEMICOLON
366 #ifndef VK_PERIOD
367 #define VK_PERIOD 0xBE
368 #endif // VK_PERIOD
369 #ifndef VK_COMMA
370 #define VK_COMMA 0xBC
371 #endif // VK_COMMA
372 #ifndef VK_QUOTE
373 #define VK_QUOTE 0xDE
374 #endif // VK_QUOTE
375 #ifndef VK_BACK_QUOTE
376 #define VK_BACK_QUOTE 0xC0
377 #endif // VK_BACK_QUOTE
378 #ifndef VK_SLASH
379 #define VK_SLASH 0xBF
380 #endif // VK_SLASH
381 #ifndef VK_BACK_SLASH
382 #define VK_BACK_SLASH 0xDC
383 #endif // VK_BACK_SLASH
384 #ifndef VK_EQUALS
385 #define VK_EQUALS 0xBB
386 #endif // VK_EQUALS
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
393 #ifndef VK_GR_LESS
394 #define VK_GR_LESS 0xE2
395 #endif // VK_GR_LESS
396 
397 
398 
399 static int oldx = 0, oldy = 0;
400 //extern int shutterGlasses;
401 
402 int mouseX, mouseY;
403 
404 static short gcWheelDelta = 0;
405 
406 
407 
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)
413 {
414 #if defined(ENABLEFULLSCREEN)
415  /* adapted from http://www.gamedev.net/community/forums/topic.asp?topic_id=418397 */
416  /* normally I pass in bpp=32. If you set debugit=true below and do a run, you'll see the modes available */
417  /* CDS_FULLSCREEN
418  for dual-monitor the author warns to disable nVidia's nView (they hook
419  into changedisplaysettings but not changedisplaysettingsex)
420  one idea: don't do the ex on single monitors - set dualmonitor=false above.
421  Find out the name of the device this window - is on (this is for multi-monitor setups)
422  */
423  MONITORINFOEX monInfo;
424  LONG ret;
425  bool ok;
426  DWORD style, exstyle;
427  bool debugit;
428  DEVMODE dmode;
429  bool foundMode;
430  int i;
431  HWND ghWnd;
432  HMONITOR hMonitor;
433  //wglGetCurrent
434  hMonitor = MonitorFromWindow(ghWnd, MONITOR_DEFAULTTOPRIMARY);
435  memset(&monInfo, 0, sizeof(MONITORINFOEX));
436  monInfo.cbSize = sizeof(MONITORINFOEX);
437  GetMonitorInfo(hMonitor, (LPMONITORINFO)&monInfo);
438 
439  /* Find the requested device mode */
440  foundMode = false;
441  memset(&dmode, 0, sizeof(DEVMODE));
442  dmode.dmSize = sizeof(DEVMODE);
443  debugit = false;
444  for(i=0 ; EnumDisplaySettings(monInfo.szDevice, i, &dmode) && !foundMode ; ++i)
445  {
446  foundMode = (dmode.dmPelsWidth==(DWORD)w) &&
447  (dmode.dmPelsHeight==(DWORD)h) &&
448  (dmode.dmBitsPerPel==(DWORD)bpp);
449  if(debugit)
450  ConsoleMessage("found w=%d h=%d bpp=%d\n",(int)dmode.dmPelsWidth, (int)dmode.dmPelsHeight, (int)dmode.dmBitsPerPel);
451  }
452  if(!foundMode || debugit )
453  {
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);
457  return false;
458  }
459  dmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
460 
461  /* If we're switching from a windowed mode to this fullscreen
462  mode, save some information about the window so that it can
463  be restored when switching back to windowed mode
464  */
465  style=0, exstyle=0;
466  if(!m_fullscreen)
467  {
468  /* Save the current window position/size */
469  GetWindowRect(ghWnd, &smallrect);
470 
471  /* Save the window style and set it for fullscreen mode */
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);
476  }
477 
478  // Attempt to change the resolution
479  if(dualmonitor)
480  {
481  ret = ChangeDisplaySettingsEx(monInfo.szDevice, &dmode, NULL, CDS_FULLSCREEN, NULL);
482  }else{
483  ret = ChangeDisplaySettings(&dmode, CDS_FULLSCREEN);
484  }
485  //LONG ret = ChangeDisplaySettings(&dmode, CDS_FULLSCREEN);
486  ok = (ret == DISP_CHANGE_SUCCESSFUL);
487  if(ok) m_fullscreen = true;
488 
489  /* If all was good resize & reposition the window
490  to match the new resolution on the correct monitor
491  */
492  if(ok)
493  {
494  /* We need to call GetMonitorInfo() again becase
495  // details may have changed with the resolution
496  */
497  GetMonitorInfo(hMonitor, (LPMONITORINFO)&monInfo);
498 
499  /* Set the window's size and position so
500  // that it covers the entire screen
501  */
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);
504  }
505 
506  /* If the attempt failed and we weren't already
507  // in fullscreen mode, restore the window styles
508  */
509  else if(!m_fullscreen)
510  {
511  SetWindowLongPtr(ghWnd, GWL_STYLE, style);
512  SetWindowLongPtr(ghWnd, GWL_EXSTYLE, exstyle);
513  }
514  return ok;
515 #endif
516  return FALSE;
517 }
518 
519 void DisableFullscreen()
520 {
521 #if defined(ENABLEFULLSCREEN)
522  if(m_fullscreen) {
523 
524  /* Find out the name of the device this window
525  is on (this is for multi-monitor setups) */
526  MONITORINFOEX monInfo;
527  DWORD style,exstyle;
528  HMONITOR hMonitor;
529  HWND ghWnd;
530  hMonitor = MonitorFromWindow(ghWnd, MONITOR_DEFAULTTOPRIMARY);
531  memset(&monInfo, 0, sizeof(MONITORINFOEX));
532  monInfo.cbSize = sizeof(MONITORINFOEX);
533  GetMonitorInfo(hMonitor, (LPMONITORINFO)&monInfo);
534 
535  /* Restore the display resolution */
536  ChangeDisplaySettingsEx(monInfo.szDevice, NULL, NULL, 0, NULL);
537  /*ChangeDisplaySettings(NULL, 0);*/
538 
539  m_fullscreen = false;
540 
541  /* Restore the window styles */
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)));
546 
547  /* Restore the window size/position */
548  /*SetPosition(m_windowedX, m_windowedY);*/
549  /* SetSize(m_windowedWidth, m_windowedHeight); */
550  SetWindowPos(ghWnd , /* handle to window */
551  HWND_TOPMOST, /* placement-order handle */
552  smallrect.left, /* horizontal position */
553  smallrect.top, /* vertical position */
554  smallrect.right - smallrect.left, /* width */
555  smallrect.bottom - smallrect.top, /* height */
556  SWP_SHOWWINDOW /* window-positioning options); */
557  );
558  }
559 #endif
560 }
561 
562 
563 static HCURSOR hSensor, hArrow;
564 static HCURSOR cursor;
565 void loadCursors()
566 {
567  hSensor = LoadCursor(NULL,IDC_HAND); /* prepare sensor_cursor */
568  hArrow = LoadCursor( NULL, IDC_ARROW );
569 }
570 void updateCursorStyle0(int cstyle)
571 {
572  if(!hSensor) loadCursors();
573  switch(cstyle){
574  case SCURSE:
575  SetCursor(hSensor); break;
576  case ACURSE:
577  SetCursor(hArrow); break;
578  case NCURSE:
579  SetCursor(NULL); break;
580  default:
581  SetCursor(hArrow);
582  }
583 }
584 /* values from WinUser.h */
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
621 
622 /* from http://www.web3d.org/x3d/specifications/ISO-IEC-19775-1.2-X3D-AbstractSpecification/index.html
623 section 21.4.1
624 Key Value
625 Home 13
626 End 14
627 PGUP 15
628 PGDN 16
629 UP 17
630 DOWN 18
631 LEFT 19
632 RIGHT 20
633 F1-F12 1 to 12
634 ALT,CTRL,SHIFT true/false
635 */
636 //#define F1_KEY 1
637 //#define F2_KEY 2
638 //#define F3_KEY 3
639 //#define F4_KEY 4
640 //#define F5_KEY 5
641 //#define F6_KEY 6
642 //#define F7_KEY 7
643 //#define F8_KEY 8
644 //#define F9_KEY 9
645 //#define F10_KEY 10
646 //#define F11_KEY 11
647 //#define F12_KEY 12
648 //#define HOME_KEY 13
649 //#define END_KEY 14
650 //#define PGUP_KEY 15
651 //#define PGDN_KEY 16
652 //#define UP_KEY 17
653 //#define DOWN_KEY 18
654 //#define LEFT_KEY 19
655 //#define RIGHT_KEY 20
656 //#define ALT_KEY 30 /* not available on OSX */
657 //#define CTL_KEY 31 /* not available on OSX */
658 //#define SFT_KEY 32 /* not available on OSX */
659 //#define DEL_KEY 0XFFFF /* problem: I'm insterting this back into the translated char stream so 0xffff too high to clash with a latin? */
660 //#define RTN_KEY 13 //what about 10 newline?
661 
662 #define KEYPRESS 1
663 #define KEYDOWN 2
664 #define KEYUP 3
665 
666 int platform2web3dActionKeyWIN32(int platformKey)
667 {
668  int key;
669 
670  key = 0; //platformKey;
671  if(platformKey >= PF1_KEY && platformKey <= PF12_KEY)
672  key = platformKey - PF1_KEY + F1_KEY;
673  else
674  switch(platformKey)
675  {
676  case PHOME_KEY:
677  key = HOME_KEY; break;
678  case PEND_KEY:
679  key = END_KEY; break;
680  case PPGDN_KEY:
681  key = PGDN_KEY; break;
682  case PPGUP_KEY:
683  key = PGUP_KEY; break;
684  case PUP_KEY:
685  key = UP_KEY; break;
686  case PDOWN_KEY:
687  key = DOWN_KEY; break;
688  case PLEFT_KEY:
689  key = LEFT_KEY; break;
690  case PRIGHT_KEY:
691  key = RIGHT_KEY; break;
692  case PDEL_KEY:
693  key = DEL_KEY; break;
694  case PALT_KEY:
695  key = ALT_KEY; break;
696  case PCTL_KEY:
697  key = CTL_KEY; break;
698  case PSFT_KEY:
699  key = SFT_KEY; break;
700  case PNUM0:
701  key = NUM0; break;
702  case PNUM1:
703  key = NUM1; break;
704  case PNUM2:
705  key = NUM2; break;
706  case PNUM3:
707  key = NUM3; break;
708  case PNUM4:
709  key = NUM4; break;
710  case PNUM5:
711  key = NUM5; break;
712  case PNUM6:
713  key = NUM6; break;
714  case PNUM7:
715  key = NUM7; break;
716  case PNUM8:
717  key = NUM8; break;
718  case PNUM9:
719  key = NUM9; break;
720  case PNUMDEC:
721  key = NUMDEC; break;
722  default:
723  key = 0;
724  }
725  return key;
726 }
727 /* Print n as a binary number - scraped from www */
728 void printbitssimple(int n) {
729  unsigned int i,j;
730  j=0;
731  i = 1<<(sizeof(n) * 8 - 1);
732  while (i > 0) {
733  if (n & i)
734  printf("1");
735  else
736  printf("0");
737  i >>= 1;
738  j++;
739  if(j%8 == 0) printf(" ");
740  }
741 }
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(
747  HWND hWnd,
748  UINT msg,
749  WPARAM wParam,
750  LPARAM lParam )
751 {
752  PAINTSTRUCT ps;
753  LONG lRet = 1;
754  RECT rect;
755  int keyraw;
756  int mev;
757  int butnum;
758  int updown;
759  int actionKey;
760 static int altState = 0;
761  int lkeydata;
762 static int shiftState = 0;
763  HDC ghDC;
764  int windex;
765 
766  mev = 0;
767  butnum = 0;
768  windex = fwl_hwnd_to_windex(hWnd); //sets it if doesn't exist
769 
770  //ghWnd = hWnd;
771  switch( msg ) {
772 
773  case WM_CREATE:
774  //printf("wm_create\n");
775  //fv_create_GLcontext();
776  //fv_bind_GLcontext();
777  //((*LPCREATESTRUCT)lParam)->lpCreateParams;
778 // fv_create_and_bind_GLcontext(hWnd);
779  break;
780 
781  case WM_SIZE:
782  GetClientRect(hWnd, &rect);
783  //gglobal()->display.screenWidth = rect.right; /*used in mainloop render_pre setup_projection*/
784  //gglobal()->display.screenHeight = rect.bottom;
785  //resize_GL(rect.right, rect.bottom);
786 //#ifdef STATUSBAR_HUD
787 // statusbar_set_window_size(rect.right, rect.bottom);
788 //#else
789 // fwl_setScreenDim(rect.right, rect.bottom);
790 //#endif
791  fwl_setScreenDim1(rect.right, rect.bottom, windex);
792  break;
793 
794  case WM_DISPLAYCHANGE:
795  /*triggred when the display mode is changed ie changedisplaysettings window <> fullscreen
796  or how about if you drag a window onto a second monitor?
797  */
798  if(!fwDisplayChange())
799  PostQuitMessage(0);
800  //GetClientRect(hWnd, &rect);
801 
802  break;
803 
804  case WM_CLOSE:
805  //fwCloseContext();
806  //DestroyWindow (hWnd);
807  fwl_doQuit(__FILE__,__LINE__);
808  break;
809 
810 
811 /**************************************************************\
812  * WM_PAINT: *
813 \**************************************************************/
814 
815  case WM_PAINT:
816 
817  ghDC = BeginPaint( hWnd, &ps );
818  /*TextOut( ghDC, 10, 10, "Hello, Windows!", 13 ); */
819  EndPaint( hWnd, &ps );
820  break;
821 
822 /**************************************************************\
823  * WM_COMMAND: *
824 \**************************************************************/
825 
826  case WM_COMMAND:
827  /*
828  switch( wParam ) {
829  case IDM_ABOUT:
830  DialogBox( ghInstance, "AboutDlg", hWnd, (DLGPROC)
831  AboutDlgProc );
832  break;
833  }
834  */
835  break;
836 
837 /**************************************************************\
838  * WM_DESTROY: PostQuitMessage() is called *
839 \**************************************************************/
840 
841  case WM_DESTROY:
842  fwCloseContext();
843 
844  PostQuitMessage (0);
845  break;
846 
847  case WM_KEYDOWN:
848  case WM_KEYUP:
849  /* raw keystrokes with UP and DOWN separate,
850  used for fly navigation and KeySensor node */
851  lkeydata = lParam;
852  updown = KEYDOWN; //KeyPress;
853  if(msg==WM_KEYUP) updown = KEYUP; //KeyRelease;
854  if(updown==KeyPress)
855  if(lkeydata & 1 << 30)
856  break; //ignor - its an auto-repeat
857  //altDown = lkeydata & 1 << 29; //alt key is pressed while the current key is pressed
858  /*
859  printf("KF_ALTDOWN");
860  printbitssimple((int)KF_ALTDOWN);
861  printf("\n");
862  printf("lkeydata ");
863  printbitssimple(lkeydata);
864  printf(" %d %o %x \n",lkeydata,lkeydata,lkeydata);
865  */
866  /*
867  printbitssimple(wParam); printf("\n");
868  //altDown = lkeydata & KF_ALTDOWN;
869  //#define KF_ALTDOWN 0x2000
870  if(altState && !altDown) fwl_do_rawKeyPress(ALT_KEY,KEYUP + 10);
871  if(!altState && altDown) fwl_do_rawKeyPress(ALT_KEY,KEYDOWN + 10);
872  altState = altDown;
873  */
874  //kp = (char)wParam;
875  keyraw = (int) wParam;
876  if(keyraw == VK_OEM_1) keyraw = (int)';'; //US
877  if(updown==KEYUP && keyraw == VK_DELETE)
878  fwl_do_rawKeyPress(DEL_KEY,KEYPRESS);
879  actionKey = platform2web3dActionKeyWIN32(keyraw);
880  if(actionKey)
881  fwl_do_rawKeyPress(actionKey,updown+10);
882  else
883  fwl_do_rawKeyPress(keyraw,updown);
884 
885  //if(kp >= 'A' && kp <= 'Z' && shiftState ==0 ) kp = (char)tolower(wParam); //the F1 - F12 are small case ie y=121=F1
886  //printf(" wParam %d %x\n",wParam, wParam);
887  //x3d specs http://www.web3d.org/x3d/specifications/ISO-IEC-19775-1.2-X3D-AbstractSpecification/index.html
888  //section 21.4.1 has a table of KeySensor ActionKey values which we must map to at some point
889  // http://msdn.microsoft.com/en-us/library/ms646268(VS.85).aspx windows keyboard messages
890  //switch (wParam)
891  //{
892  // //case VK_LEFT: -- translation to web3d moved to platform2web3dActionKey(int platformKey)
893  // // kp = 'j';//19;
894  // // break;
895  // //case VK_RIGHT:
896  // // kp = 'l';//20;
897  // // break;
898  // //case VK_UP:
899  // // kp = 'p';//17;
900  // // break;
901  // //case VK_DOWN:
902  // // kp = ';';//18;
903  // // break;
904  // //case -70:
905  // // kp = ';';
906  // // break;
907  // //case VK_SHIFT: //0x10
908  // // if(updown==KeyPress) shiftState = 1;
909  // // if(updown==KeyRelease) shiftState = 0;
910  // //case VK_CONTROL: //0x11
911  // //case VK_MENU: //ALT 0x12 - doesn't work like this: it alters the next key pressed
912  // // break;
913  // /*
914  // case VK_OPEN_BRACKET:
915  // printf("[");
916  // // width, height, bpp of monitor
917  // EnableFullscreen(1680,1050,32);
918  // break;
919  // case VK_CLOSE_BRACKET:
920  // printf("]");
921  // DisableFullscreen();
922  // break;
923  // */
924  // case VK_OEM_1:
925  // kp = ';'; //could be : or ; but tolower won't lowercase it, but returns same character if it can't
926  // break;
927  // default:
928  // ///* we aren't using WCHAR so we will translate things like shift-/ to ? */
929  // //{
930  // // /* http://msdn.microsoft.com/en-us/library/ms646267(VS.85).aspx shows where to get the scan code */
931  // // int k2; int i2; unsigned short k3;
932  // // UINT scancode;
933  // // //scancode = ((lParam << 8)>>8)>>16;
934  // // scancode = lParam >>16;
935  // // k2 = MapVirtualKeyEx(scancode,MAPVK_VSC_TO_VK,GetKeyboardLayout(0));
936  // // k2 = MapVirtualKeyEx(k2,MAPVK_VK_TO_CHAR,NULL);
937  // // if(k2) kp = k2;
938  // // k3 = 0;
939  // // i2 = ToAsciiEx(wParam,scancode,NULL,&k3,0,GetKeyboardLayout(0));
940  // // if(i2>0)
941  // // kp = k3;
942  // //}
943  // break;
944  //}
945  //fwl_do_rawKeyPressWIN32(keyraw, updown);
946  break;
947 
948  case WM_CHAR:
949  /* fully translated char, with any SHIFT applied, and not a modifier key itself.
950  used for keyboard commands to freewrl -except fly navigation-
951  and web3d StringSensor node.
952  */
953  //kp = (char)wParam;
954  //fwl_do_keyPress(kp,KeyChar);
955  keyraw = (int) wParam;
956  fwl_do_rawKeyPress(keyraw,KEYPRESS);
957  break;
958  /* Mouse events, processed */
959  case WM_LBUTTONDOWN:
960  butnum = 1;
961  mev = ButtonPress;
962  break;
963  case WM_MBUTTONDOWN:
964  butnum = 2;
965  mev = ButtonPress;
966  break;
967  case WM_RBUTTONDOWN:
968  butnum = 3;
969  mev = ButtonPress;
970  break;
971  case WM_LBUTTONUP:
972  butnum = 1;
973  mev = ButtonRelease;
974  break;
975  case WM_MBUTTONUP:
976  butnum = 2;
977  mev = ButtonRelease;
978  break;
979  case WM_RBUTTONUP:
980  butnum = 3;
981  mev = ButtonRelease;
982  break;
983  case WM_MOUSEMOVE:
984  {
985  POINTS pz;
986  pz= MAKEPOINTS(lParam);
987  mouseX = pz.x;
988  mouseY = pz.y;
989  }
990  mev = MotionNotify;
991  break;
992 #ifndef WM_MOUSEWHEEL
993 #define WM_MOUSEWHEEL 0x020A
994 #endif
995  case WM_MOUSEWHEEL:
996  /* The WM_MOUSEWHEEL message is sent to the focus window
997  * when the mouse wheel is rotated. The DefWindowProc
998  * function propagates the message to the window's parent.
999  * There should be no internal forwarding of the message,
1000  * since DefWindowProc propagates it up the parent chain
1001  * until it finds a window that processes it.
1002  */
1003  if(!(wParam & (MK_SHIFT | MK_CONTROL))) {
1004  /* gcWheelDelta -= (short) HIWORD(wParam); windows snippet */
1005  gcWheelDelta = (short) HIWORD(wParam);
1006  mev = MotionNotify;
1007  break;
1008  }
1009 
1010  /* falls through to default ? */
1011 
1012 /**************************************************************\
1013  * Let the default window proc handle all other messages *
1014 \**************************************************************/
1015 
1016  default:
1017  return( DefWindowProc( hWnd, msg, wParam, lParam ));
1018  }
1019  if(mev)
1020  {
1021  /*void fwl_handle_aqua(const int mev, const unsigned int button, int x, int y);*/
1022  /* butnum=1 left butnum=3 right (butnum=2 middle, not used by freewrl) */
1023  int cursorStyle;
1024  cursorStyle = fwl_handle_mouse(mev, butnum, mouseX, mouseY, windex); /* ,gcWheelDelta); */
1025  updateCursorStyle0(cursorStyle);
1026  }
1027  return 0;
1028 }
1029 
1030 int doEventsWin32A()
1031 {
1032  static int eventcount = 0;
1033  MSG msg;
1034  do
1035  {
1036  while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) == TRUE)
1037  {
1038  if (GetMessage(&msg, NULL, 0, 0) )
1039  {
1040  TranslateMessage(&msg);
1041  DispatchMessage(&msg);
1042  } else {
1043  return TRUE;
1044  }
1045 
1046  }
1047  eventcount++;
1048  }while(0); /*eventcount < 1000);*/
1049  eventcount = 0;
1050  return FALSE;
1051 }
1052 void fwMessageLoop(){
1053  doEventsWin32A();
1054 }
1055 
1056 void fv_setGeometry_from_cmdline(const char *gstring)
1057 {
1058  int w,h,i;
1059  char *tok[2];
1060  freewrl_params_t *params;
1061  char *str = MALLOC(void *, sizeof(gstring)+1);
1062  strcpy(str,gstring);
1063  tok[0] = str;
1064  for(i=0;i<(int)strlen(gstring);i++)
1065  if(str[i] == 'x' || str[i] == 'X')
1066  {
1067  str[i] = '\0';
1068  tok[1] = &str[i+1];
1069  break;
1070  }
1071  sscanf(tok[0],"%d",&w);
1072  sscanf(tok[1],"%d",&h);
1073  params = (freewrl_params_t *)gglobal()->display.params;
1074  params->width = w;
1075  params->height = h;
1076  FREE(str);
1077 
1078 }
1079 /*======== "VIRTUAL FUNCTIONS" ==============*/
1080 
1081 void setWindowTitle() //char *window_title)
1082 {
1083  //XStoreName(Xdpy, Xwin, window_title);
1084  //XSetIconName(Xdpy, Xwin, window_title);
1085  //http://msdn.microsoft.com/en-us/library/ms633546(VS.85).aspx
1086  //SetWindowText(
1087  // __in HWND hWnd,
1088  // __in_opt LPCTSTR lpString);
1089  HWND ghWnd;
1090  //SetWindowText(ghWnd,fwl_getWindowTitle());
1091  ghWnd = (void*)((freewrl_params_t *)(gglobal()->display.params))->winToEmbedInto;
1092  if(ghWnd)
1093  SetWindowText(ghWnd,getWindowTitle()); //window_title);
1094 }
1095 
1099 int fv_open_display()
1100 {
1101  /* nothing to do */
1102  return TRUE;
1103 }
1104 
1105 static char *wgetpath = NULL;
1106 TCHAR szPath[MAX_PATH];
1107 static int wgetpathLoaded = 0;
1108 char *getWgetPath()
1109 {
1110  if(!wgetpathLoaded)
1111  {
1112  if( !GetModuleFileName( NULL, &szPath[1], MAX_PATH ) )
1113  {
1114  printf("Cannot install service (%d)\n", GetLastError());
1115  return 0;
1116  }
1117  else
1118  {
1119  wgetpath = &szPath[1];
1120  PathRemoveFileSpec(wgetpath);
1121  PathAppend(wgetpath,"wget.exe");
1122  // c:\program files\ breaks up in the space so we "" around the path
1123  strcat(wgetpath,"\"");
1124  wgetpath = szPath;
1125  wgetpath[0] = '"';
1126  }
1127  }
1128  wgetpathLoaded = 1;
1129  return wgetpath;
1130 }
1131 
1135 HWND create_main_window0(freewrl_params_t * d) //int argc, char *argv[])
1136 {
1137  HINSTANCE hInstance;
1138  WNDCLASS wc;
1139  static int wc_defined = 0;
1140  DWORD wStyle = 0;
1141  HWND ghWnd;
1142  //RECT rect;
1143  int width, height;
1144  int nCmdShow = SW_SHOW;
1145 
1146  //printf("starting createWindow32\n");
1147  /* I suspect hInstance should be get() and passed in from the console program not get() in the dll, but .lib maybe ok */
1148  hInstance = (HANDLE)GetModuleHandle(NULL);
1149  //printf("hInstance=%p\n",hInstance);
1150  //gglobal()->display.window_title = "FreeWRL";
1151  //d->window_title = "FreeWRL";
1152 
1153 /* Blender Ghost
1154  WNDCLASS wc;
1155  wc.style= CS_HREDRAW | CS_VREDRAW;
1156  wc.lpfnWndProc= s_wndProc;
1157  wc.cbClsExtra= 0;
1158  wc.cbWndExtra= 0;
1159  wc.hInstance= ::GetModuleHandle(0);
1160  wc.hIcon = ::LoadIcon(wc.hInstance, "APPICON");
1161 
1162  if (!wc.hIcon) {
1163  ::LoadIcon(NULL, IDI_APPLICATION);
1164  }
1165  wc.hCursor = ::LoadCursor(0, IDC_ARROW);
1166  wc.hbrBackground= (HBRUSH)::GetStockObject(BLACK_BRUSH);
1167  wc.lpszMenuName = 0;
1168  wc.lpszClassName= GHOST_WindowWin32::getWindowClassName();
1169 
1170  // Use RegisterClassEx for setting small icon
1171  if (::RegisterClass(&wc) == 0) {
1172  success = GHOST_kFailure;
1173  }
1174 */
1175  //hSensor = LoadCursor(NULL,IDC_HAND); /* prepare sensor_cursor */
1176  //hArrow = LoadCursor( NULL, IDC_ARROW );
1177  //loadCursors();
1178 
1179  if(!wc_defined){
1180  wc.lpszClassName = "FreeWrlAppClass";
1181  wc.lpfnWndProc = PopupWndProc; //MainWndProc;
1182  //wc.style = CS_VREDRAW | CS_HREDRAW; /* 0 CS_OWNDC | */
1183  wc.style = CS_OWNDC;
1184  wc.hInstance = hInstance;
1185  wc.hIcon = LoadIcon(wc.hInstance, "APPICON");
1186  if (!wc.hIcon) {
1187  wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
1188  }
1189  wc.hCursor = NULL; //hArrow;
1190  wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
1191  wc.lpszMenuName = 0; /* "GenericAppMenu"; */
1192  wc.cbClsExtra = 0;
1193  wc.cbWndExtra = 0;
1194 
1195  RegisterClass( &wc );
1196  wc_defined = TRUE;
1197  }
1198  //width = gglobal()->display.width + 8; //windows gui eats 4 on each side
1199  //height = gglobal()->display.height + 34; // and 26 for the menu bar
1200  width = d->width;
1201  height = d->height;
1202  if (!d->fullscreen){
1203  width += 8; //windows gui eats 4 on each side
1204  height += 34; // and 26 for the menu bar
1205  }
1206  wStyle = WS_VISIBLE | WS_POPUP | WS_BORDER | WS_SYSMENU | WS_CAPTION;
1207  wStyle |= WS_SIZEBOX; //makes it resizable
1208  wStyle |= WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
1209  //wStyle |= WS_EX_ACCEPTFILES; //drag & drop target (but needs OLE32.dll etc https://msdn.microsoft.com/en-us/library/windows/desktop/bb776905(v=vs.85).aspx
1210 
1211  ghWnd = CreateWindowEx( WS_EX_APPWINDOW, "FreeWrlAppClass", "freeWRL",
1212  /* ghWnd = CreateWindow( "GenericAppClass", "Generic Application", */
1213  wStyle, //WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
1214  CW_USEDEFAULT,
1215  CW_USEDEFAULT,
1216  width,
1217  height,
1218  NULL,
1219  NULL,
1220  hInstance,
1221  (void*)gglobal()); //NULL);
1222  /* make sure window was created */
1223 
1224  if (!ghWnd)
1225  return NULL;
1226 
1227  //printf("made a window\n");
1228 
1229  //GetClientRect(ghWnd, &rect);
1230 
1231  ShowWindow( ghWnd, SW_SHOW); /* SW_SHOWNORMAL); /*nCmdShow );*/
1232  //printf("showed window\n");
1233  //d->winToEmbedInto = (long int)ghWnd;
1234 
1235 
1236  UpdateWindow(ghWnd);
1237  if (d->fullscreen){
1238  //stefan borderless, title-less
1239  LONG lExStyle;
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);
1243 
1244  lExStyle = GetWindowLong(ghWnd, GWL_EXSTYLE);
1245  lExStyle &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE);
1246  SetWindowLong(ghWnd, GWL_EXSTYLE, lExStyle);
1247 
1248  SetWindowPos(ghWnd, HWND_TOP, d->xpos, d->ypos, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE);
1249  }
1250  //printf("updated window - leaving createwindow\n");
1251  //setWindowTitle00();
1252  //ShowCursor(0); //turns off hArrow, hHand cursors
1253  setArrowCursor();
1254  return ghWnd;
1255 }
1256 
1257 int fv_create_main_window2(freewrl_params_t * d, freewrl_params_t *share) //int argc, char *argv[])
1258 {
1259  loadCursors();
1260 #ifdef _DEBUG
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);
1262 #endif
1263  if(!d->frontend_handles_display_thread){
1264  //printf("wintoembedinto 1=%d\n",d->winToEmbedInto);
1265  if( d->winToEmbedInto < 1) //INT_ID_UNDEFINED) sometimes 0 or -1
1266  d->winToEmbedInto = (long)create_main_window0(d); //argc, argv);
1267  //printf("wintoembedinto 2=%d\n",d->winToEmbedInto);
1268  if( d->winToEmbedInto )
1269  {
1270  //HWND hWnd;
1272  //hWnd = (HWND)d->winToEmbedInto;
1273  //fv_create_GLcontext();
1274  //fv_bind_GLcontext();
1275  fv_create_and_bind_GLcontext(d);
1276 #ifndef ANGLEPROJECT
1277  //remember, ANGLEPROJECT emulates GLES2 over directX, and lacks some desktop wgl functions like wglShareLists
1278  if(share)
1279  wglShareLists((HGLRC) share->context,(HGLRC) d->context);
1280 #endif
1281  return TRUE;
1282  }
1283  return FALSE;
1284  }
1285  return TRUE;
1286 }
1287 
1288 #endif /* _MSC_VER */
Initialization.
Definition: libFreeWRL.h:71
Definition: Viewer.h:174