Skip to main content

Python bindings for GLFW 3+ using Cython

Project description

Python bindings for GLFW 3+ using Cython.

Provides an API which matches the C API.

Differences

  • Enumerations have dropped their “GLFW_” prefix.

  • Functions have dropped their “glfw” prefix.

  • {Get|Set}UserPointer is not accessible as it doesn’t make sense for Python.

  • The {Get|Set}Time functions are available but Python’s time module should be used in preference.

C Code

#include <GLFW/glfw3.h>
int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);

    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    glfwTerminate();
    return 0;
}

Python Code

# needed if you're running the OS-X system python
try:
    from AppKit import NSApp, NSApplication
except:
    pass

import cyglfw3 as glfw
if not glfw.Init():
    exit()

window = glfw.CreateWindow(640, 480, 'Hello World')
if not window:
    glfw.Terminate()
    exit()

glfw.MakeContextCurrent(window)
while not glfw.WindowShouldClose(window):
    # Render here

    # Swap front and back buffers
    glfw.SwapBuffers(window)

    # Poll for and process events
    glfw.PollEvents()

glfw.Terminate()

Installation

pip install cyglfw3

Manual Building

If you have trouble building CyGLFW3, please raise an issue on Github.

When specifying the include path, ensure that the GLFW directory is a sub-directory of that path. For example: the path /usr/local/include/GLFW would use include /usr/local/include

The lib path should contain the glfw library file.

OS-X / Linux

CyGLFW3 provides support for OS-X Homebrew and MacPorts.

Linux builds should work with any package manager.

python setup.py build_ext -i

Specifying an alternate GLFW installation path:

env CPATH=<include path> LIBRARY_PATH=<lib path> python setup.py build_ext -i

Windows

The following commands are untested, please report their success or failure.

set INCLUDE=%INCLUDE%;<path to headers>
set LIB=%LIB%;<path to lib>
python setup.py build_ext -i

Dependencies

  • Python 2.7

  • Cython

  • GLFW 3

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

cyglfw3-0.0.2.tar.gz (74.2 kB view details)

Uploaded Source

File details

Details for the file cyglfw3-0.0.2.tar.gz.

File metadata

  • Download URL: cyglfw3-0.0.2.tar.gz
  • Upload date:
  • Size: 74.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for cyglfw3-0.0.2.tar.gz
Algorithm Hash digest
SHA256 6c8a5061c777fd29827384fdd89ccae3673a132ebb0bf2807d9d6a7efb7116f7
MD5 dae04b7bf6b989929c50939b0235482f
BLAKE2b-256 1e6cc929cbe3345caa35038e45a78dc44c103f68ef155a4237671eeabcad816b

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