使用cython的glfw 3+的python绑定
cyglfw3的Python项目详细描述
使用cython为GLFW 3+绑定python。
提供与C API匹配的API
差异
- 枚举已删除其“glfw”前缀。
- 函数已删除其“glfw”前缀。
- {Get | Set}用户指针不可访问,因为它对Python没有意义
- {get set}时间函数是可用的,但是python的时间模块应该优先使用。
C代码
#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; } glfwMakeContextCurrent(window); while (!glfwWindowShowClose(window)) { /* Render here */ /* Display the render buffer */ glfwSwapBuffers(window); /* Pump the message queue */ glfwPollEvents(); } /* Shutdown */ glfwTerminate(); return 0; }
Python代码
# 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()
前缀兼容代码
提供一个兼容层,使其与其他glfw3包装器1:1兼容。 通常,它们不会从常量中删除glfw前缀,也不会删除glfw前缀 从函数
要使用兼容性模块,请使用import cyglfw3.compatible as glfw:
# needed if you're running the OS-X system python try: from AppKit import NSApp, NSApplication except: pass import cyglfw3.compatible as glfw if not glfw.glfwInit(): exit() window = glfw.glfwCreateWindow(640, 480, 'Hello World') if not window: glfw.glfwTerminate() exit() glfw.glfwMakeContextCurrent(window) while not glfw.glfwWindowShouldClose(window): # Render here # Swap front and back buffers glfw.glfwSwapBuffers(window) # Poll for and process events glfw.glfwPollEvents() glfw.glfwTerminate()
安装
pip install cyglfw3
人工建筑
如果您在构建cyglfw3时遇到问题,请在github上提出问题。
指定包含路径时,请确保glfw目录是一个子目录 在那条路上。 例如:路径/usr/local/include/glfw将使用include/usr/local/include
lib路径应包含glfw库文件
OS-X/Linux
CyGLFW3支持OS-X Homebrew和MacPorts
Linux构建应该与任何包管理器一起工作
python setup.py build_ext -i
指定备用GLFW安装路径:
env CPATH=<include path> LIBRARY_PATH=<lib path> python setup.py build_ext -i
窗口
以下命令未经测试,请报告其成功或失败
set GLFW_ROOT=<path to include/GLFW/glfw3.h> python setup.py build_ext -i
如果您得到importorror:DLL load failed:找不到指定的过程。 请将lib-vc2012中的glfw3.dll放在安装路径中。
常见问题
- pyopengl报告opengl版本为none,而我的gl函数什么也不做!
您必须设置一个活动上下文,否则您的opengl调用将转到no where:
glfw.MakeContextCurrent(window)
这是glfw3设计的。
依赖关系
- Python2.7/3.4
- 赛顿
- GLFW 3号