Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main():
# start GLFW
if not glfw.init():
return -1
# setup GLFW window options
glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 2)
glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 1)
# open the window
window = glfw.create_window(800, 600, "Oculus Test", None, None)
if not window:
glfw.terminate()
# always call this before setting up render layers
glfw.make_context_current(window)
# load textures from file
def setup_module():
import glfw
glfw.init()
def create_window_glfw(width, height, name, instance_handle):
import glfw
glfw.init()
# todo: depends on what backend is used, I guess?
if BACKEND in ("CTYPES", "FFI"):
# Create Window
glfw.window_hint(glfw.CLIENT_API, glfw.NO_API)
glfw.window_hint(glfw.RESIZABLE, False)
window = glfw.create_window(width, height, name, None, None)
# todo: how to get the window handle for glfw?
# This would have been nice ... but glfw.get_win32_window does not exist
# https://github.com/gfx-rs/wgpu/blob/master/examples/triangle/main.c#L167
# hwnd = glfw.glfwGetWin32Window(window)
# HINSTANCE hinstance = GetModuleHandle(NULL);
# surface = wgpu_create_surface_from_windows_hwnd(hinstance, hwnd);
else:
glfw.window_hint(glfw.RESIZABLE, False)
from psychopy import logging, event, prefs
from psychopy.tools.attributetools import attributeSetter
from .gamma import createLinearRamp
from .. import globalVars
from ._base import BaseBackend
from PIL import Image
# on mac Standalone app check for packaged libglfw dylib
if prefs.paths['libs']:
_possLibPaths = glob.glob(os.path.join(self.paths['libs'], 'libglfw*'))
if _possLibPaths:
os.environ['PYGLFW_LIBRARY'] = _possLibPaths[0]
import glfw
# initialize the GLFW library on import
if not glfw.init():
raise RuntimeError("Failed to initialize GLFW. Check if GLFW "
"has been correctly installed or use a "
"different backend. Exiting.")
atexit.register(glfw.terminate)
import pyglet
pyglet.options['debug_gl'] = False
GL = pyglet.gl
retinaContext = None # it will be set to an actual context if needed
# generate and cache standard cursors
_CURSORS_ = {
'arrow': glfw.create_standard_cursor(glfw.ARROW_CURSOR),
'ibeam': glfw.create_standard_cursor(glfw.IBEAM_CURSOR),
'crosshair': glfw.create_standard_cursor(glfw.CROSSHAIR_CURSOR),
def opengl_init():
global window
# Initialize the library
if not glfw.init():
print("Failed to initialize GLFW\n",file=sys.stderr)
return False
# Open Window and create its OpenGL context
window = glfw.create_window(1024, 768, "Tutorial 05", None, None) #(in the accompanying source code this variable will be global)
glfw.window_hint(glfw.SAMPLES, 4)
glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, GL_TRUE)
glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
if not window:
print("Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n",file=sys.stderr)
glfw.terminate()
return False
def opengl_init():
global window
# Initialize the library
if not glfw.init():
print("Failed to initialize GLFW\n",file=sys.stderr)
return False
# Open Window and create its OpenGL context
window = glfw.create_window(1024, 768, "Tutorial 08", None, None) #(in the accompanying source code this variable will be global)
glfw.window_hint(glfw.SAMPLES, 4)
glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, GL_TRUE)
glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
if not window:
print("Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n",file=sys.stderr)
glfw.terminate()
return False
def __initWindow(self):
glfw.init()
glfw.window_hint(glfw.CLIENT_API, glfw.NO_API)
glfw.window_hint(glfw.RESIZABLE, False)
self.__window = glfw.create_window(WIDTH, HEIGHT, "Vulkan", None, None)
Import the viz from triangle.py and run it in a glfw window.
The glfw library can be installed using ``pip install glfw``.
"""
import math
from time import perf_counter
import glfw
from wgpu.gui.glfw import update_glfw_canvasses, WgpuCanvas
import wgpu.backends.rs # noqa: F401, Select Rust backend
# Import the function that we must call to run the visualization
from triangle import main
glfw.init()
canvas = WgpuCanvas(title="wgpu triangle with GLFW")
main(canvas)
def simple_event_loop():
""" A real simple event loop, but it keeps the CPU busy. """
while update_glfw_canvasses():
glfw.poll_events()
def better_event_loop(max_fps=100):
""" A simple event loop that schedules draws. """
td = 1 / max_fps
while update_glfw_canvasses():
# Determine next time to draw
now = perf_counter()
def start_slicing_stl(stl_filename, layer_thickness, slice_save_path):
glfw.init()
glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
if platform.system() == 'Darwin': # for Mac OS
glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, GL_TRUE)
window = glfw.create_window(SCR_WIDTH, SCR_HEIGHT, 'STL Slicer', None, None)
glfw.make_context_current(window)
glfw.set_framebuffer_size_callback(window, framebuffer_size_callback)
glfw.set_input_mode(window, glfw.CURSOR, glfw.CURSOR_NORMAL)
loadMesh(stl_filename)
glBindVertexArray(params.maskVAO)
slicer_folder = os.path.dirname(os.path.abspath(__file__))
sliceShader = OurShaderProgram(os.path.join(slicer_folder, 'shaders', 'slice.vert'),
def start_slicing_stl(stl_filename, layer_thickness, slice_save_path):
glfw.init()
glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
if platform.system() == 'Darwin': # for Mac OS
glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, GL_TRUE)
window = glfw.create_window(SCR_WIDTH, SCR_HEIGHT, 'STL Slicer', None, None)
glfw.make_context_current(window)
glfw.set_framebuffer_size_callback(window, framebuffer_size_callback)
glfw.set_input_mode(window, glfw.CURSOR, glfw.CURSOR_NORMAL)
loadMesh(stl_filename)
glBindVertexArray(params.maskVAO)
sliceShader = OurShaderProgram('shaders/slice.vert', 'shaders/slice.frag')
prepareSlice()