FreeWRL / FreeX3D 4.3.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
28void fv_swapbuffers(freewrl_params_t * d);
29bool fv_create_and_bind_GLcontext(freewrl_params_t * d);
30BOOL fwDisplayChange();
31void 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
41#define ES_WINDOW_ALPHA 1
43#define ES_WINDOW_DEPTH 2
45#define ES_WINDOW_STENCIL 4
47#define ES_WINDOW_MULTISAMPLE 8
48
49//static EGLDisplay eglDisplay;
50//static EGLContext eglContext;
51//static EGLSurface eglSurface;
52void fv_swapbuffers(freewrl_params_t * d){
53 eglSwapBuffers((EGLDisplay)d->display,(EGLSurface)d->surface);
54}
55EGLBoolean 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
140bool 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}
187BOOL fwDisplayChange(){
188 return GL_FALSE;
189}
190void fwCloseContext(){
191}
192void 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
208void fv_swapbuffers(freewrl_params_t * d)
209{
210 //HDC ghDC;
211 //ghDC = wglGetCurrentDC();
212 //SwapBuffers(ghDC);
213 SwapBuffers((HDC)d->display);
214}
215
216BOOL 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}
263void 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
272bool 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}
306BOOL 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
327void 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//}
352HWND fw_window32_hwnd(){
353 ttglobal tg = (ttglobal)gglobal();
354 return (HWND)((freewrl_params_t *)tg->display.params)->winToEmbedInto;
355}
356
357void 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
399static int oldx = 0, oldy = 0;
400//extern int shutterGlasses;
401
402int mouseX, mouseY;
403
404static short gcWheelDelta = 0;
405
406
407
408static bool m_fullscreen = false;
409static bool dualmonitor = false;
410static RECT smallrect;
411void setLastCursor();
412bool 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
519void 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
563static HCURSOR hSensor, hArrow;
564static HCURSOR cursor;
565void loadCursors()
566{
567 hSensor = LoadCursor(NULL,IDC_HAND); /* prepare sensor_cursor */
568 hArrow = LoadCursor( NULL, IDC_ARROW );
569}
570void 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
623section 21.4.1
624Key Value
625Home 13
626End 14
627PGUP 15
628PGDN 16
629UP 17
630DOWN 18
631LEFT 19
632RIGHT 20
633F1-F12 1 to 12
634ALT,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
666int 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 */
728void 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
743static HWND last_key_hWnd = NULL;
744static int clipboard_functions_registered = 0;
745static void win32_clipboard_copy(char *str){
746 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms649016(v=vs.85).aspx
747
748 int len;
749 LPTSTR lptstrCopy;
750 HGLOBAL hglbCopy;
751 if (!OpenClipboard(last_key_hWnd))
752 return;
753 EmptyClipboard();
754
755 // If text is selected, copy it using the CF_TEXT format.
756 len = strlen(str);
757
758 if (!len) // zero length
759 {
760 CloseClipboard(); // selection
761 return;
762 }
763
764
765 hglbCopy = GlobalAlloc(GMEM_MOVEABLE,
766 (len + 1) * sizeof(TCHAR));
767 if (hglbCopy == NULL)
768 {
769 CloseClipboard();
770 return;
771 }
772
773 // Lock the handle and copy the text to the buffer.
774
775 lptstrCopy = GlobalLock(hglbCopy);
776 memcpy(lptstrCopy, str,
777 len * sizeof(TCHAR));
778 lptstrCopy[len] = (TCHAR) 0; // null character
779 GlobalUnlock(hglbCopy);
780
781 // Place the handle on the clipboard.
782
783 SetClipboardData(CF_TEXT, hglbCopy);
784 CloseClipboard();
785
786
787
788}
789static void win32_clipboard_paste() {
790 //CTRL-V == 22 == clipboard paste in win32
791 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms649016(v=vs.85).aspx
792 HGLOBAL hglb;
793 LPTSTR lptstr;
794 //paste
795 if (IsClipboardFormatAvailable(CF_TEXT)) {
796 if (OpenClipboard(last_key_hWnd)) {
797 hglb = GetClipboardData(CF_TEXT);
798 if (hglb != NULL)
799 {
800 lptstr = GlobalLock(hglb);
801 if (lptstr != NULL)
802 {
803 int m, len = strlen(lptstr);
804 for(m=0;m<len;m++)
805 if(lptstr[m] != 22) //prevent infinite recusion
806 fwl_do_rawKeyPress(lptstr[m],KEYPRESS);
807 GlobalUnlock(hglb);
808 }
809 }
810 CloseClipboard();
811 }
812 }
813}
814
815
816
817void fwl_set_clipboard_copy( void (*fn)(char *));
818void fwl_set_clipboard_paste( void (*fn));
819
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(
825 HWND hWnd,
826 UINT msg,
827 WPARAM wParam,
828 LPARAM lParam )
829{
830 PAINTSTRUCT ps;
831 LONG lRet = 1;
832 RECT rect;
833 int keyraw;
834 int mev;
835 int butnum;
836 int updown;
837 int actionKey;
838static int altState = 0;
839 int lkeydata;
840static int shiftState = 0;
841 HDC ghDC;
842 int windex;
843
844 mev = 0;
845 butnum = 0;
846 windex = fwl_hwnd_to_windex(hWnd); //sets it if doesn't exist
847 last_key_hWnd = hWnd; //for clpboard funcs above
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;
852 }
853 //ghWnd = hWnd;
854 switch( msg ) {
855
856 case WM_CREATE:
857 //printf("wm_create\n");
858 //fv_create_GLcontext();
859 //fv_bind_GLcontext();
860 //((*LPCREATESTRUCT)lParam)->lpCreateParams;
861// fv_create_and_bind_GLcontext(hWnd);
862 break;
863
864 case WM_SIZE:
865 GetClientRect(hWnd, &rect);
866 //gglobal()->display.screenWidth = rect.right; /*used in mainloop render_pre setup_projection*/
867 //gglobal()->display.screenHeight = rect.bottom;
868 //resize_GL(rect.right, rect.bottom);
869//#ifdef STATUSBAR_HUD
870// statusbar_set_window_size(rect.right, rect.bottom);
871//#else
872// fwl_setScreenDim(rect.right, rect.bottom);
873//#endif
874 fwl_setScreenDim1(rect.right, rect.bottom, windex);
875 break;
876
877 case WM_DISPLAYCHANGE:
878 /*triggred when the display mode is changed ie changedisplaysettings window <> fullscreen
879 or how about if you drag a window onto a second monitor?
880 */
881 if(!fwDisplayChange())
882 PostQuitMessage(0);
883 //GetClientRect(hWnd, &rect);
884
885 break;
886
887 case WM_CLOSE:
888 //fwCloseContext();
889 //DestroyWindow (hWnd);
890 fwl_doQuit(__FILE__,__LINE__);
891 break;
892
893
894/**************************************************************\
895 * WM_PAINT: *
896\**************************************************************/
897
898 case WM_PAINT:
899
900 ghDC = BeginPaint( hWnd, &ps );
901 /*TextOut( ghDC, 10, 10, "Hello, Windows!", 13 ); */
902 EndPaint( hWnd, &ps );
903 break;
904
905/**************************************************************\
906 * WM_COMMAND: *
907\**************************************************************/
908
909 case WM_COMMAND:
910 /*
911 switch( wParam ) {
912 case IDM_ABOUT:
913 DialogBox( ghInstance, "AboutDlg", hWnd, (DLGPROC)
914 AboutDlgProc );
915 break;
916 }
917 */
918 break;
919
920/**************************************************************\
921 * WM_DESTROY: PostQuitMessage() is called *
922\**************************************************************/
923
924 case WM_DESTROY:
925 fwCloseContext();
926
927 PostQuitMessage (0);
928 break;
929
930 case WM_KEYDOWN:
931 case WM_KEYUP:
932 /* raw keystrokes with UP and DOWN separate,
933 used for fly navigation and KeySensor node */
934 lkeydata = lParam;
935 updown = KEYDOWN; //KeyPress;
936 if(msg==WM_KEYUP) updown = KEYUP; //KeyRelease;
937 if(updown==KeyPress)
938 if(lkeydata & 1 << 30)
939 break; //ignor - its an auto-repeat
940 //altDown = lkeydata & 1 << 29; //alt key is pressed while the current key is pressed
941 /*
942 printf("KF_ALTDOWN");
943 printbitssimple((int)KF_ALTDOWN);
944 printf("\n");
945 printf("lkeydata ");
946 printbitssimple(lkeydata);
947 printf(" %d %o %x \n",lkeydata,lkeydata,lkeydata);
948 */
949 /*
950 printbitssimple(wParam); printf("\n");
951 //altDown = lkeydata & KF_ALTDOWN;
952 //#define KF_ALTDOWN 0x2000
953 if(altState && !altDown) fwl_do_rawKeyPress(ALT_KEY,KEYUP + 10);
954 if(!altState && altDown) fwl_do_rawKeyPress(ALT_KEY,KEYDOWN + 10);
955 altState = altDown;
956 */
957 //kp = (char)wParam;
958 keyraw = (int) wParam;
959 if(keyraw == VK_OEM_1) keyraw = (int)';'; //US
960 if(updown==KEYUP && keyraw == VK_DELETE)
961 fwl_do_rawKeyPress(DEL_KEY,KEYPRESS);
962 actionKey = platform2web3dActionKeyWIN32(keyraw);
963 if(actionKey)
964 fwl_do_rawKeyPress(actionKey,updown+10);
965 else
966 fwl_do_rawKeyPress(keyraw,updown);
967
968 //if(kp >= 'A' && kp <= 'Z' && shiftState ==0 ) kp = (char)tolower(wParam); //the F1 - F12 are small case ie y=121=F1
969 //printf(" wParam %d %x\n",wParam, wParam);
970 //x3d specs http://www.web3d.org/x3d/specifications/ISO-IEC-19775-1.2-X3D-AbstractSpecification/index.html
971 //section 21.4.1 has a table of KeySensor ActionKey values which we must map to at some point
972 // http://msdn.microsoft.com/en-us/library/ms646268(VS.85).aspx windows keyboard messages
973 //switch (wParam)
974 //{
975 // //case VK_LEFT: -- translation to web3d moved to platform2web3dActionKey(int platformKey)
976 // // kp = 'j';//19;
977 // // break;
978 // //case VK_RIGHT:
979 // // kp = 'l';//20;
980 // // break;
981 // //case VK_UP:
982 // // kp = 'p';//17;
983 // // break;
984 // //case VK_DOWN:
985 // // kp = ';';//18;
986 // // break;
987 // //case -70:
988 // // kp = ';';
989 // // break;
990 // //case VK_SHIFT: //0x10
991 // // if(updown==KeyPress) shiftState = 1;
992 // // if(updown==KeyRelease) shiftState = 0;
993 // //case VK_CONTROL: //0x11
994 // //case VK_MENU: //ALT 0x12 - doesn't work like this: it alters the next key pressed
995 // // break;
996 // /*
997 // case VK_OPEN_BRACKET:
998 // printf("[");
999 // // width, height, bpp of monitor
1000 // EnableFullscreen(1680,1050,32);
1001 // break;
1002 // case VK_CLOSE_BRACKET:
1003 // printf("]");
1004 // DisableFullscreen();
1005 // break;
1006 // */
1007 // case VK_OEM_1:
1008 // kp = ';'; //could be : or ; but tolower won't lowercase it, but returns same character if it can't
1009 // break;
1010 // default:
1011 // ///* we aren't using WCHAR so we will translate things like shift-/ to ? */
1012 // //{
1013 // // /* http://msdn.microsoft.com/en-us/library/ms646267(VS.85).aspx shows where to get the scan code */
1014 // // int k2; int i2; unsigned short k3;
1015 // // UINT scancode;
1016 // // //scancode = ((lParam << 8)>>8)>>16;
1017 // // scancode = lParam >>16;
1018 // // k2 = MapVirtualKeyEx(scancode,MAPVK_VSC_TO_VK,GetKeyboardLayout(0));
1019 // // k2 = MapVirtualKeyEx(k2,MAPVK_VK_TO_CHAR,NULL);
1020 // // if(k2) kp = k2;
1021 // // k3 = 0;
1022 // // i2 = ToAsciiEx(wParam,scancode,NULL,&k3,0,GetKeyboardLayout(0));
1023 // // if(i2>0)
1024 // // kp = k3;
1025 // //}
1026 // break;
1027 //}
1028 //fwl_do_rawKeyPressWIN32(keyraw, updown);
1029 break;
1030
1031 case WM_CHAR:
1032 /* fully translated char, with any SHIFT applied, and not a modifier key itself.
1033 used for keyboard commands to freewrl -except fly navigation-
1034 and web3d StringSensor node.
1035 */
1036 //kp = (char)wParam;
1037 //fwl_do_keyPress(kp,KeyChar);
1038 keyraw = (int) wParam;
1039 fwl_do_rawKeyPress(keyraw,KEYPRESS);
1040 break;
1041 /* Mouse events, processed */
1042 case WM_LBUTTONDOWN:
1043 butnum = 1;
1044 mev = ButtonPress;
1045 break;
1046 case WM_MBUTTONDOWN:
1047 butnum = 2;
1048 mev = ButtonPress;
1049 break;
1050 case WM_RBUTTONDOWN:
1051 butnum = 3;
1052 mev = ButtonPress;
1053 break;
1054 case WM_LBUTTONUP:
1055 butnum = 1;
1056 mev = ButtonRelease;
1057 break;
1058 case WM_MBUTTONUP:
1059 butnum = 2;
1060 mev = ButtonRelease;
1061 break;
1062 case WM_RBUTTONUP:
1063 butnum = 3;
1064 mev = ButtonRelease;
1065 break;
1066 case WM_MOUSEMOVE:
1067 {
1068 POINTS pz;
1069 pz= MAKEPOINTS(lParam);
1070 mouseX = pz.x;
1071 mouseY = pz.y;
1072 }
1073 mev = MotionNotify;
1074 break;
1075#ifndef WM_MOUSEWHEEL
1076#define WM_MOUSEWHEEL 0x020A
1077#endif
1078 case WM_MOUSEWHEEL:
1079 /* The WM_MOUSEWHEEL message is sent to the focus window
1080 * when the mouse wheel is rotated. The DefWindowProc
1081 * function propagates the message to the window's parent.
1082 * There should be no internal forwarding of the message,
1083 * since DefWindowProc propagates it up the parent chain
1084 * until it finds a window that processes it.
1085 */
1086 if(!(wParam & (MK_SHIFT | MK_CONTROL))) {
1087 /* gcWheelDelta -= (short) HIWORD(wParam); windows snippet */
1088 gcWheelDelta = (short) HIWORD(wParam);
1089 mev = MotionNotify;
1090 break;
1091 }
1092
1093 /* falls through to default ? */
1094
1095/**************************************************************\
1096 * Let the default window proc handle all other messages *
1097\**************************************************************/
1098
1099 default:
1100 return( DefWindowProc( hWnd, msg, wParam, lParam ));
1101 }
1102 if(mev)
1103 {
1104 /*void fwl_handle_aqua(const int mev, const unsigned int button, int x, int y);*/
1105 /* butnum=1 left butnum=3 right (butnum=2 middle, not used by freewrl) */
1106 int cursorStyle;
1107 cursorStyle = fwl_handle_mouse(mev, butnum, mouseX, mouseY, windex); /* ,gcWheelDelta); */
1108 updateCursorStyle0(cursorStyle);
1109 }
1110 return 0;
1111}
1112
1113int doEventsWin32A()
1114{
1115 static int eventcount = 0;
1116 MSG msg;
1117 do
1118 {
1119 while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) == TRUE)
1120 {
1121 if (GetMessage(&msg, NULL, 0, 0) )
1122 {
1123 TranslateMessage(&msg);
1124 DispatchMessage(&msg);
1125 } else {
1126 return TRUE;
1127 }
1128
1129 }
1130 eventcount++;
1131 }while(0); /*eventcount < 1000);*/
1132 eventcount = 0;
1133 return FALSE;
1134}
1135void fwMessageLoop(){
1136 doEventsWin32A();
1137}
1138
1139void fv_setGeometry_from_cmdline(const char *gstring)
1140{
1141 int w,h,i;
1142 char *tok[2];
1143 freewrl_params_t *params;
1144 char *str = MALLOC(void *, sizeof(gstring)+1);
1145 strcpy(str,gstring);
1146 tok[0] = str;
1147 for(i=0;i<(int)strlen(gstring);i++)
1148 if(str[i] == 'x' || str[i] == 'X')
1149 {
1150 str[i] = '\0';
1151 tok[1] = &str[i+1];
1152 break;
1153 }
1154 sscanf(tok[0],"%d",&w);
1155 sscanf(tok[1],"%d",&h);
1156 params = (freewrl_params_t *)gglobal()->display.params;
1157 params->width = w;
1158 params->height = h;
1159 FREE(str);
1160
1161}
1162/*======== "VIRTUAL FUNCTIONS" ==============*/
1163
1164void setWindowTitle() //char *window_title)
1165{
1166 //XStoreName(Xdpy, Xwin, window_title);
1167 //XSetIconName(Xdpy, Xwin, window_title);
1168 //http://msdn.microsoft.com/en-us/library/ms633546(VS.85).aspx
1169 //SetWindowText(
1170 // __in HWND hWnd,
1171 // __in_opt LPCTSTR lpString);
1172 HWND ghWnd;
1173 //SetWindowText(ghWnd,fwl_getWindowTitle());
1174 ghWnd = (void*)((freewrl_params_t *)(gglobal()->display.params))->winToEmbedInto;
1175 if(ghWnd)
1176 SetWindowText(ghWnd,getWindowTitle()); //window_title);
1177}
1178
1182int fv_open_display()
1183{
1184 /* nothing to do */
1185 return TRUE;
1186}
1187
1188static char *wgetpath = NULL;
1189TCHAR szPath[MAX_PATH];
1190static int wgetpathLoaded = 0;
1191char *getWgetPath()
1192{
1193 if(!wgetpathLoaded)
1194 {
1195 if( !GetModuleFileName( NULL, &szPath[1], MAX_PATH ) )
1196 {
1197 printf("Cannot install service (%d)\n", GetLastError());
1198 return 0;
1199 }
1200 else
1201 {
1202 wgetpath = &szPath[1];
1203 PathRemoveFileSpec(wgetpath);
1204 PathAppend(wgetpath,"wget.exe");
1205 // c:\program files\ breaks up in the space so we "" around the path
1206 strcat(wgetpath,"\"");
1207 wgetpath = szPath;
1208 wgetpath[0] = '"';
1209 }
1210 }
1211 wgetpathLoaded = 1;
1212 return wgetpath;
1213}
1214
1218HWND create_main_window0(freewrl_params_t * d) //int argc, char *argv[])
1219{
1220 HINSTANCE hInstance;
1221 WNDCLASS wc;
1222 static int wc_defined = 0;
1223 DWORD wStyle = 0;
1224 HWND ghWnd;
1225 //RECT rect;
1226 int width, height;
1227 int nCmdShow = SW_SHOW;
1228
1229 //printf("starting createWindow32\n");
1230 /* I suspect hInstance should be get() and passed in from the console program not get() in the dll, but .lib maybe ok */
1231 hInstance = (HANDLE)GetModuleHandle(NULL);
1232 //printf("hInstance=%p\n",hInstance);
1233 //gglobal()->display.window_title = "FreeWRL";
1234 //d->window_title = "FreeWRL";
1235
1236/* Blender Ghost
1237 WNDCLASS wc;
1238 wc.style= CS_HREDRAW | CS_VREDRAW;
1239 wc.lpfnWndProc= s_wndProc;
1240 wc.cbClsExtra= 0;
1241 wc.cbWndExtra= 0;
1242 wc.hInstance= ::GetModuleHandle(0);
1243 wc.hIcon = ::LoadIcon(wc.hInstance, "APPICON");
1244
1245 if (!wc.hIcon) {
1246 ::LoadIcon(NULL, IDI_APPLICATION);
1247 }
1248 wc.hCursor = ::LoadCursor(0, IDC_ARROW);
1249 wc.hbrBackground= (HBRUSH)::GetStockObject(BLACK_BRUSH);
1250 wc.lpszMenuName = 0;
1251 wc.lpszClassName= GHOST_WindowWin32::getWindowClassName();
1252
1253 // Use RegisterClassEx for setting small icon
1254 if (::RegisterClass(&wc) == 0) {
1255 success = GHOST_kFailure;
1256 }
1257*/
1258 //hSensor = LoadCursor(NULL,IDC_HAND); /* prepare sensor_cursor */
1259 //hArrow = LoadCursor( NULL, IDC_ARROW );
1260 //loadCursors();
1261
1262 if(!wc_defined){
1263 wc.lpszClassName = "FreeWrlAppClass";
1264 wc.lpfnWndProc = PopupWndProc; //MainWndProc;
1265 //wc.style = CS_VREDRAW | CS_HREDRAW; /* 0 CS_OWNDC | */
1266 wc.style = CS_OWNDC;
1267 wc.hInstance = hInstance;
1268 wc.hIcon = LoadIcon(wc.hInstance, "APPICON");
1269 if (!wc.hIcon) {
1270 wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
1271 }
1272 wc.hCursor = NULL; //hArrow;
1273 wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
1274 wc.lpszMenuName = 0; /* "GenericAppMenu"; */
1275 wc.cbClsExtra = 0;
1276 wc.cbWndExtra = 0;
1277
1278 RegisterClass( &wc );
1279 wc_defined = TRUE;
1280 }
1281 //width = gglobal()->display.width + 8; //windows gui eats 4 on each side
1282 //height = gglobal()->display.height + 34; // and 26 for the menu bar
1283 width = d->width;
1284 height = d->height;
1285 if (!d->fullscreen){
1286 width += 8; //windows gui eats 4 on each side
1287 height += 34; // and 26 for the menu bar
1288 }
1289 wStyle = WS_VISIBLE | WS_POPUP | WS_BORDER | WS_SYSMENU | WS_CAPTION;
1290 wStyle |= WS_SIZEBOX; //makes it resizable
1291 wStyle |= WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
1292 //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
1293
1294 ghWnd = CreateWindowEx( WS_EX_APPWINDOW, "FreeWrlAppClass", "freeWRL",
1295 /* ghWnd = CreateWindow( "GenericAppClass", "Generic Application", */
1296 wStyle, //WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
1297 CW_USEDEFAULT,
1298 CW_USEDEFAULT,
1299 width,
1300 height,
1301 NULL,
1302 NULL,
1303 hInstance,
1304 (void*)gglobal()); //NULL);
1305 /* make sure window was created */
1306
1307 if (!ghWnd)
1308 return NULL;
1309
1310 //printf("made a window\n");
1311
1312 //GetClientRect(ghWnd, &rect);
1313
1314 ShowWindow( ghWnd, SW_SHOW); /* SW_SHOWNORMAL); /*nCmdShow );*/
1315 //printf("showed window\n");
1316 //d->winToEmbedInto = (long int)ghWnd;
1317
1318
1319 UpdateWindow(ghWnd);
1320 if (d->fullscreen){
1321 //stefan borderless, title-less
1322 LONG lExStyle;
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);
1326
1327 lExStyle = GetWindowLong(ghWnd, GWL_EXSTYLE);
1328 lExStyle &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE);
1329 SetWindowLong(ghWnd, GWL_EXSTYLE, lExStyle);
1330
1331 SetWindowPos(ghWnd, HWND_TOP, d->xpos, d->ypos, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE);
1332 }
1333 //printf("updated window - leaving createwindow\n");
1334 //setWindowTitle00();
1335 //ShowCursor(0); //turns off hArrow, hHand cursors
1336 setArrowCursor();
1337 return ghWnd;
1338}
1339
1340int fv_create_main_window2(freewrl_params_t * d, freewrl_params_t *share) //int argc, char *argv[])
1341{
1342 loadCursors();
1343#ifdef _DEBUG
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);
1345#endif
1346 if(!d->frontend_handles_display_thread){
1347 //printf("wintoembedinto 1=%d\n",d->winToEmbedInto);
1348 if( d->winToEmbedInto < 1) //INT_ID_UNDEFINED) sometimes 0 or -1
1349 d->winToEmbedInto = (long)create_main_window0(d); //argc, argv);
1350 //printf("wintoembedinto 2=%d\n",d->winToEmbedInto);
1351 if( d->winToEmbedInto )
1352 {
1353 //HWND hWnd;
1355 //hWnd = (HWND)d->winToEmbedInto;
1356 //fv_create_GLcontext();
1357 //fv_bind_GLcontext();
1358 fv_create_and_bind_GLcontext(d);
1359#ifndef ANGLEPROJECT
1360 //remember, ANGLEPROJECT emulates GLES2 over directX, and lacks some desktop wgl functions like wglShareLists
1361 if(share)
1362 wglShareLists((HGLRC) share->context,(HGLRC) d->context);
1363#endif
1364 return TRUE;
1365 }
1366 return FALSE;
1367 }
1368 return TRUE;
1369}
1370
1371#endif /* _MSC_VER */
Initialization.
Definition libFreeWRL.h:72
Definition Viewer.h:139