FlorianRhiem / pyGLFW

Python bindings for GLFW
MIT License
232 stars 36 forks source link

missing new hint "GLFW_MOUSE_PASSTHROUGH" in current version #53

Closed wis closed 2 years ago

wis commented 4 years ago

Hello, thank you for creating this awesome library.

it was added/released in glfw hours before the last release of pyGLFW!

I tried glfw.window_hint(0x0002000D, glfw.TRUE) instead of glfw.window_hint(glfw.MOUSE_PASSTHROUGH, glfw.TRUE) but found out the compiled library needs updating.

Traceback (most recent call last):
  File "./test-clickthrough.py", line 37, in <module>
    glfw.window_hint(0x0002000D, 1)
  File "glfw/__init__.py", line 1138, in window_hint
    _glfw.glfwWindowHint(hint, value)
  File "glfw/__init__.py", line 628, in errcheck
    _reraise(exc[1], exc[2])
  File "glfw/__init__.py", line 52, in _reraise
    raise exception.with_traceback(traceback)
  File "glfw/__init__.py", line 607, in callback_wrapper
    return func(*args, **kwargs)
  File "glfw/__init__.py", line 820, in _handle_glfw_errors
    raise GLFWError(message)
glfw.GLFWError: (65539) b'Invalid window hint 0x0002000D'

can you please release an update?

FlorianRhiem commented 4 years ago

Hey wis,

the library shipped with pyGLFW wheels is version 3.3.2, the latest release of GLFW. If you want to use features from the development version of GLFW, you will need to build the library yourself and either replace the one shipped with pyGLFW, install it in one of the default search paths, or set the PYGLFW_LIBRARY environment variable. Then you should be able to use the new window hint.

I try to add constants and function wrappers shortly after a GLFW release instead of doing it bit by bit as development of GLFW goes on. That way users can rely on the constants defined actually being valid, unless they are using their own GLFW library.

wis commented 4 years ago

Ok, thank you.

aSemy commented 3 years ago

I know this issue is closed and the flag won't be added until the 3.4 release, but it's a good solution for me at the moment and so I hacked together a solution. I wanted to write it up for anyone else who comes across this issue and would like to set the 3.4 dll up, but (like me) finds cmake an absolute nightmare.

Caveat: it's not working locally for me. I get this error from the ctypes.CDLL(...) call in library.py, no matter what I seem to do. But I HAVE had it working! And it works on a VM I created! I think it's something to do with Poetry? PyCharm? Or Windows 10 security? Or I installed Windows updates which screwed something up? Or caching? Or uninstalled Visual Studio Code? Or it's something with Python 3.9 and ctypes? I have no idea. I'll figure it out - I know it's something weird locally on my machine.

FileNotFoundError: Could not find module 'D:/Users/Yreh/Projects/python/proj/Overlay/glfw3.dll' (or one of its dependencies). Try using the full path with constructor syntax.


Anyway, enough about my problems. Here's how you (the search engine engine user who came across this ticket) can (hopefully) use the 3.4 glfw dll.

  1. Get 3.4 glfw3.dll https://github.com/aSemy/glfw/releases

    I forked glfw/glfw and set up a build job to do this, based off the .appveyor.yml in glfw/glfw. If you want to fork glfw/glfw yourself, and copy the .github/workflows/cmakesimple.yml I made - go ahead.

  2. Windows: You might need to right click on the downloaded archive and uncheck the security warning? I used 7zip to extract it.

  3. I found the pyGLFW folder virtualenvs\asdja-py3.9\Lib\site-packages\glfw and replaced the existing glfw3.dl with the downloaded one.

  4. I found the 'id code' for the GLFW_MOUSE_PASSTHROUGH by searching in the glfw/glfw project (it's in file include/GLFW/glfw3.h) - it turns out it's 0x0002000D

  5. I edited 2 pyGLFW files, in it's module folder.

    • __init__.py > insert this value
        FOCUS_ON_SHOW = 0x0002000C
        MOUSE_PASSTHROUGH = 0x0002000D # < add this line
        RED_BITS = 0x00021001
    
    • GLFW.py > Between 'FOCUS_ON_SHOW ' (line 530) and RED_BITS (line 531) I added...
    FOCUS_ON_SHOW as GLFW_FOCUS_ON_SHOW,
    MOUSE_PASSTHROUGH as GLFW_MOUSE_PASSTHROUGH, # < add this line 
    FORMAT_UNAVAILABLE as GLFW_FORMAT_UNAVAILABLE,
    
  6. I added a print statement after the import to check it was working.

    import glfw
    print(glfw.get_version())

output: (3, 4, 0)

Ta da!

Click here to have a look at an Example ```python import glfw print(glfw.get_version()) def main(): # Initialize the library if not glfw.init(): return glfw.window_hint(glfw.MOUSE_PASSTHROUGH, glfw.TRUE) glfw.window_hint(glfw.RESIZABLE, glfw.FALSE) glfw.window_hint(glfw.DECORATED, glfw.FALSE) glfw.window_hint(glfw.FLOATING, glfw.TRUE) # Create a windowed mode window and its OpenGL context window = glfw.create_window(640, 480, "Hello World", None, None) if not window: glfw.terminate() return glfw.set_window_opacity(window, 0.5) # Make the window's context current glfw.make_context_current(window) # Loop until the user closes the window while not glfw.window_should_close(window): # Render here, e.g. using pyOpenGL # Swap front and back buffers glfw.swap_buffers(window) # Poll for and process events glfw.poll_events() glfw.terminate() if __name__ == "__main__": main() ```

And check out the docs - they say that this new flag is "only supported for undecorated windows" https://www.glfw.org/docs/3.4/group__window.html#ga88981797d29800808ec242274ab5c03a

zedpoirier commented 3 years ago

This worked flawlessly for me! Thank you @aSemy !

ckcollab commented 2 years ago

Is it possible to release a "Beta" version of pyGLFW that you can only install if you explicitly say pip install pyGLFW==beta2.3.0 or some such?

FlorianRhiem commented 2 years ago

Something like that should be possible, yes. I'll look into it, though it might take a couple days.

ckcollab commented 2 years ago

@FlorianRhiem to be clear: very thankful you do any work on this at all! please take your time, appreciate what we have already.

FlorianRhiem commented 2 years ago

I've just released version 2.4.0, along with a helper package glfw_preview.

With this new version, if you:

the glfw package will include wrappers for unreleased functions and macros. There will still be a delay between them being introduced to the GLFW master and them being wrapped, as there's still manual work involved with that, but I've setup a CI script that should inform me of any unwrapped macros or functions every saturday morning, so the delay shouldn't be that long.

Please try it and let me know if there are any issues with the preview mechanism or with the newly-wrapped functions and macros.