Skip to content

Commit

Permalink
windows build compiling and starting
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Aug 17, 2023
1 parent 71a8c5b commit da926d5
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 6 deletions.
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -623,7 +623,7 @@ FIND_PNG()
FIND_JPG()
FIND_GDAL()
FIND_CGAL()
FIND_GTK()
FIND_IMGUI()
FIND_CEF()
FIND_OPENVR()
FIND_OCE()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/core/setup/windows/VRGlutEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down Expand Up @@ -64,6 +65,7 @@ VRGlutEditor::VRGlutEditor() {
glutInitWindowSize(width, height);
topWin = glutCreateWindow("PolyVR");
glutEditors[topWin] = this;
glutDisplayFunc( onMainDisplay );
glutReshapeFunc( onMainReshape );
glutCloseFunc( onMainClose );

Expand Down
130 changes: 130 additions & 0 deletions src/core/setup/windows/glut/VRGlutWinExtensions.cpp
Original file line number Diff line number Diff line change
@@ -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 <GL/glx.h>
#include <thread>

//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; i<img.w*img.h; i++) data[k+i+2] = img.data[i];
k += img.w*img.h+2;
}
}


void IconList::load(string path) {
auto img = OSG::VRTexture::create();
if (img->read(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);
}

0 comments on commit da926d5

Please sign in to comment.