From da926d550b1e2b3ebff194707d22c68ac3af7bc8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 17 Aug 2023 10:23:10 +0200 Subject: [PATCH] windows build compiling and starting --- CMakeLists.txt | 12 +- src/core/setup/windows/VRGlutEditor.cpp | 2 + .../windows/glut/VRGlutWinExtensions.cpp | 130 ++++++++++++++++++ 3 files changed, 138 insertions(+), 6 deletions(-) create mode 100644 src/core/setup/windows/glut/VRGlutWinExtensions.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e3bfb633f..e9d409594 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,7 +72,7 @@ if(WIN32) set(LIB_DIRS ${LIB_DIRS} "${DISK}:/usr/vcpkg/installed/x64-windows/lib") set(INCLUDE_DIRS ${INCLUDE_DIRS} "${DISK}:/usr/vcpkg/installed/x64-windows/include") set(INCLUDE_DIRS ${INCLUDE_DIRS} "${DISK}:/usr/include") - set(LINKER_FLAGS ${LINKER_FLAGS} wininet.lib dwmapi.lib) + set(LINKER_FLAGS ${LINKER_FLAGS} wininet.lib dwmapi.lib cairo.lib) endif() if(UNIX) @@ -623,7 +623,7 @@ FIND_PNG() FIND_JPG() FIND_GDAL() FIND_CGAL() -FIND_GTK() +FIND_IMGUI() FIND_CEF() FIND_OPENVR() FIND_OCE() @@ -823,9 +823,9 @@ target_sources(polyvr PRIVATE src/addons/Gui/VRGui.cpp) target_sources(polyvr PRIVATE src/core/gui/clipboard/clip.cpp) if(WIN32) target_sources(polyvr PRIVATE src/core/gui/clipboard/clip_win.cpp) -else +else() target_sources(polyvr PRIVATE src/core/gui/clipboard/clip_x11.cpp) -endif +endif() target_sources(polyvr PRIVATE src/core/gui/clipboard/image.cpp) target_sources(polyvr PRIVATE src/core/gui/imgui/VRImguiApps.cpp) target_sources(polyvr PRIVATE src/core/gui/imgui/VRImguiConsoles.cpp) @@ -1026,9 +1026,9 @@ target_sources(polyvr PRIVATE src/core/setup/windows/VRGlutEditor.cpp) if(WIN32) target_sources(polyvr PRIVATE src/core/setup/windows/glut/VRGlutWinExtensions.cpp) -else +else() target_sources(polyvr PRIVATE src/core/setup/windows/glut/VRGlutExtensions.cpp) -endif +endif() target_sources(polyvr PRIVATE src/core/setup/windows/VRGlutWindow.cpp) target_sources(polyvr PRIVATE src/core/setup/windows/VRViewManager.cpp) target_sources(polyvr PRIVATE src/core/setup/VRSetupManager.cpp) diff --git a/src/core/setup/windows/VRGlutEditor.cpp b/src/core/setup/windows/VRGlutEditor.cpp index 78cca55d2..5f50aa6d1 100644 --- a/src/core/setup/windows/VRGlutEditor.cpp +++ b/src/core/setup/windows/VRGlutEditor.cpp @@ -23,6 +23,7 @@ VRGlutEditor* getCurrentEditor() { return glutEditors[glutGetWindow()]; } +void onMainDisplay() { ; } void onMainReshape(int w, int h) { getCurrentEditor()->on_resize_window(w,h); } void onMainClose() { getCurrentEditor()->on_close_window(); } void onUIDisplay() { getCurrentEditor()->on_ui_display(); } @@ -64,6 +65,7 @@ VRGlutEditor::VRGlutEditor() { glutInitWindowSize(width, height); topWin = glutCreateWindow("PolyVR"); glutEditors[topWin] = this; + glutDisplayFunc( onMainDisplay ); glutReshapeFunc( onMainReshape ); glutCloseFunc( onMainClose ); diff --git a/src/core/setup/windows/glut/VRGlutWinExtensions.cpp b/src/core/setup/windows/glut/VRGlutWinExtensions.cpp new file mode 100644 index 000000000..748e7c2e6 --- /dev/null +++ b/src/core/setup/windows/glut/VRGlutWinExtensions.cpp @@ -0,0 +1,130 @@ +#include "VRGlutExtensions.h" +#include "core/gui/VRGuiManager.h" +#include "core/utils/system/VRSystem.h" +#include "core/objects/material/VRTexture.h" + +//#include +#include + +//Display* xdisplay = 0; +//XID xwindow = 0; +static bool doGrabShiftTab = true; +string backend; + +void initGlutExtensions() { + /*string XDG_SESSION_TYPE = getSystemVariable("XDG_SESSION_TYPE"); + string DISPLAY = getSystemVariable("DISPLAY"); + string WAYLAND_DISPLAY = getSystemVariable("WAYLAND_DISPLAY"); + + if (WAYLAND_DISPLAY != "" || XDG_SESSION_TYPE == "wayland") backend = "wayland"; + else if (DISPLAY != "" || XDG_SESSION_TYPE == "x11") backend = "x11"; + + // TODO: use backend variable to guard x11 calls + + xdisplay = glXGetCurrentDisplay(); + xwindow = glXGetCurrentDrawable();*/ +} + +void cleanupGlutExtensions() { + doGrabShiftTab = false; +} + +void set_win_icon_list(IconList& iconList) { + /*Atom net_wm_icon = XInternAtom(xdisplay, "_NET_WM_ICON", False); + Atom cardinal = XInternAtom(xdisplay, "CARDINAL", False); + + XChangeProperty (xdisplay, xwindow, net_wm_icon, cardinal, 32, PropModeReplace, (uint8_t*) iconList.data, iconList.size);*/ +} + + + + + + +Icon::Icon(int w, int h) : w(w), h(h) { + data = (uint64_t*)malloc ((w*h) * sizeof(uint64_t)); +} + +uint64_t* IconList::add(int w, int h) { + images.push_back(Icon(w,h)); + return images[images.size()-1].data; +} + +void IconList::compile() { + size = 0; + for (auto& img : images) size += img.w*img.h + 2; + if (data) free(data); + data = (uint64_t*)malloc (size * sizeof(uint64_t)); + + int k=0; + for (auto& img : images) { + data[k+0] = img.w; + data[k+1] = img.h; + for (int i=0; iread(path)) { + auto size = img->getSize(); + auto pixels = img->getPixels(true); + uint64_t* p = add(size[0], size[1]); + for (auto& pi : pixels) { + uint8_t r = pi[0] * 255.0; + uint8_t g = pi[1] * 255.0; + uint8_t b = pi[2] * 255.0; + uint8_t a = pi[3] * 255.0; + + *p++ = a << 24 | r << 16 | g << 8 | b ; + } + } else cout << "Warning! could not load icon " << path << endl; +} + +void IconList::addTest() { + int width = 32; + int height = 32; + uint64_t* p = add(width, height); + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + uint8_t r = x*255.0/(width-1); + uint8_t g = y*255.0/(height-1); + uint8_t b = 0; + uint8_t a = 255; + + *p++ = a << 24 | r << 16 | g << 8 | b ; + } + } +} + +void IconList::apply() { + compile(); + //if (backend == "x11") set_x11_icon_list(*this); + //else // TODO, implement wayland here +} + +void listenForKey(/*XID grab_window*/) { // TODO: add windows and wayland versions + /*Display* dpy = XOpenDisplay(0); + unsigned int modifiers1 = ShiftMask; + unsigned int modifiers2 = ShiftMask | Mod2Mask; + KeyCode keycode = XKeysymToKeycode(dpy, XK_Tab); + + XGrabKey(dpy, keycode, modifiers1, grab_window, False, GrabModeAsync, GrabModeAsync); + XGrabKey(dpy, keycode, modifiers2, grab_window, False, GrabModeAsync, GrabModeAsync); + XSelectInput(dpy, grab_window, KeyPressMask | KeyReleaseMask); + XEvent ev; + while(doGrabShiftTab) { + XNextEvent(dpy, &ev); + if (ev.type == KeyPress) uiSignal("shiftTab", {{"state","1"}}); + if (ev.type == KeyRelease) uiSignal("shiftTab", {{"state","0"}}); + } + XUngrabKey(dpy, keycode, modifiers1, grab_window); + XUngrabKey(dpy, keycode, modifiers2, grab_window); + XCloseDisplay(dpy);*/ +} + +void startGrabShiftTab() { + //static thread listener(listenForKey, xwindow); +}