Skip to main content

a Py++ library for GLFW

Project description

GLFW for Py++

a Py++ library for GLFW

Examples

Opening a window

With this library installed, the following Py++ code works to open a window. This is the typical example given in the docs for the glfw C++ and Python libraries.

from pypp_glfw import glfw, GLFWwindowPtr
from pypp_python import to_c_string, NULL


def glfw_test():
    if not glfw.init():
        raise Exception("Failed to initialize GLFW")

    window: GLFWwindowPtr = glfw.create_window(
        640, 480, to_c_string("Hello World"), NULL, NULL
    )
    if not window:
        glfw.terminate()
        raise Exception("Failed to create GLFW window")

    glfw.make_context_current(window)

    while not glfw.window_should_close(window):
        # Render here, e.g. using pyOpenGL

        glfw.swap_buffers(window)
        glfw.poll_events()

    glfw.terminate()


if __name__ == "__main__":
    glfw_test()

Opening a window and handling inputs

from pypp_glfw import glfw, GLFWwindowPtr
from pypp_python import to_c_string, NULL


def key_callback(
    _window: GLFWwindowPtr, key: int, _scancode: int, action: int, _mods: int
):
    if action == glfw.PRESS:
        print(f"Key {key} pressed")
    elif action == glfw.RELEASE:
        print(f"Key {key} released")


def mouse_button_callback(_window: GLFWwindowPtr, button: int, action: int, _mods: int):
    if action == glfw.PRESS:
        print(f"Mouse button {button} pressed")
    elif action == glfw.RELEASE:
        print(f"Mouse button {button} released")


def cursor_position_callback(_window: GLFWwindowPtr, xpos: float, ypos: float):
    print(f"Mouse moved to ({xpos}, {ypos})")


def glfw_test_2():
    if not glfw.init():
        raise Exception("Failed to initialize GLFW")

    window: GLFWwindowPtr = glfw.create_window(
        640, 480, to_c_string("Hello World"), NULL, NULL
    )
    if not window:
        glfw.terminate()
        raise Exception("Failed to create GLFW window")

    glfw.make_context_current(window)

    glfw.set_key_callback(window, key_callback)
    glfw.set_mouse_button_callback(window, mouse_button_callback)
    glfw.set_cursor_pos_callback(window, cursor_position_callback)

    while not glfw.window_should_close(window):
        # Render here, e.g. using pyOpenGL

        glfw.swap_buffers(window)
        glfw.poll_events()

    glfw.terminate()


if __name__ == "__main__":
    glfw_test_2()

API

For the API, refer to pyGLFW.

Supported GLFW attributes and functions

Only the attributes and functions which are shown in the above examples are tested. However, its very likely that others will work also, and you will most easily find out by trying them in your code.

When you find an attribute or function which does not work, it would be really helpful if you submit a feature request with title support for glfw.<some_name>. Thanks in advance for if you do that.

Bug reports

Report bugs to the Issues tab on this github repo using the bug label.

Feature requests

Submit feature requests to the Issues tab on this github repo using the feature request label.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypp_glfw-1.0.0a0.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pypp_glfw-1.0.0a0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file pypp_glfw-1.0.0a0.tar.gz.

File metadata

  • Download URL: pypp_glfw-1.0.0a0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pypp_glfw-1.0.0a0.tar.gz
Algorithm Hash digest
SHA256 da600103ddfb227525c8d28ef6f92ebde54951b456d0300b24136cfb76a48997
MD5 46cc84edaf308c014cf10c832fbf4a88
BLAKE2b-256 7ad3af6fe3dee69f430c0b9760d292a9eabf795c6c3457f5e3d439bb69bb1f87

See more details on using hashes here.

File details

Details for the file pypp_glfw-1.0.0a0-py3-none-any.whl.

File metadata

  • Download URL: pypp_glfw-1.0.0a0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pypp_glfw-1.0.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 1af72c4d9b5f1c0202b4f4fc46cc5b6ec7234f579b52201fc501514a6fdbee12
MD5 ea4e74c6b79843d24e827c7a35628b03
BLAKE2b-256 7e7e24cf675a2e10228ea6e963b3c59c3652bf590b8d807bb0b450d0634b838d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page