def showglfwInfo(self): ctx_major = glfw.glfwGetWindowAttrib(self.glfw_window, glfw.GLFW_CONTEXT_VERSION_MAJOR) ctx_minor = glfw.glfwGetWindowAttrib(self.glfw_window, glfw.GLFW_CONTEXT_VERSION_MINOR) forward_compat = glfw.glfwGetWindowAttrib(self.glfw_window, glfw.GLFW_OPENGL_FORWARD_COMPAT) print "Created Window for OpenGL version %d.%d " % ( ctx_major, ctx_major ) if ( ctx_major >=3 and forward_compat): print "Context is forward compatible, you can't use OpenGL 2.x commands" fwidth,fheight = glfw.glfwGetFramebufferSize(self.glfw_window) width, height = glfw.glfwGetWindowSize(self.glfw_window) print "Framebuffer size %dx%d Window size %dx%d " % (fwidth,fheight, width,height)
def __bgprocess(self): self.bgVisibility = glfw.glfwGetWindowAttrib(self.backgroundWindow, glfw.GLFW_VISIBLE) if not self.bgActive: if self.bgVisibility: #glfw.glfwHideWindow(self.backgroundWindow) pass return if not self.bgVisibility: mx, my = glfw.glfwGetWindowPos(self.glfwWindow) glfw.glfwSetWindowPos(self.backgroundWindow, mx + 128, mx + 128)
def on_resize(window, w, h): nonlocal window_size nonlocal content_scale is_minimized = bool( glfw.glfwGetWindowAttrib(window, glfw.GLFW_ICONIFIED)) if is_minimized: return # Always clear buffers on resize to make sure that there are no overlapping # artifacts from previous frames. gl_utils.glClear(gl_utils.GL_COLOR_BUFFER_BIT) gl_utils.glClearColor(0, 0, 0, 1) active_window = glfw.glfwGetCurrentContext() glfw.glfwMakeContextCurrent(window) content_scale = glfw.get_content_scale(window) framebuffer_scale = glfw.get_framebuffer_scale(window) g_pool.gui.scale = content_scale window_size = w, h g_pool.camera_render_size = w - int( icon_bar_width * g_pool.gui.scale), h g_pool.gui.update_window(w, h) g_pool.gui.collect_menus() for g in g_pool.graphs: g.scale = content_scale g.adjust_window_size(w, h) adjust_gl_view(w, h) glfw.glfwMakeContextCurrent(active_window) # Minimum window size required, otherwise parts of the UI can cause openGL # issues with permanent effects. Depends on the content scale, which can # potentially be dynamically modified, so we re-adjust the size limits every # time here. min_size = int(2 * icon_bar_width * g_pool.gui.scale / framebuffer_scale) glfw.glfwSetWindowSizeLimits(window, min_size, min_size, glfw.GLFW_DONT_CARE, glfw.GLFW_DONT_CARE) # Needed, to update the window buffer while resizing consume_events_and_render_buffer()
def is_window_visible(window): visible = glfw.glfwGetWindowAttrib(window, glfw.GLFW_VISIBLE) iconified = glfw.glfwGetWindowAttrib(window, glfw.GLFW_ICONIFIED) return visible and not iconified
def __init__(self): # Initialize glfw if not glfw.glfwInit(): print (" Error : glfw failed to initialize") sys.exit (glfw.EXIT_FAILURE) ceguiGL3Renderer = True if ceguiGL3Renderer: glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MAJOR, 3) glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MINOR, 2) glfw.glfwWindowHint(glfw.GLFW_OPENGL_FORWARD_COMPAT, PyGL.GL_TRUE) glfw.glfwWindowHint(glfw.GLFW_OPENGL_PROFILE, glfw.GLFW_OPENGL_CORE_PROFILE) else: glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MAJOR, 2) glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MINOR, 1) glfw.glfwWindowHint(glfw.GLFW_OPENGL_PROFILE, glfw.GLFW_OPENGL_ANY_PROFILE) # our window hints ## http://www.glfw.org/docs/latest/window.html ## set our framebuffer related hints glfw.glfwWindowHint(glfw.GLFW_DEPTH_BITS, 24) glfw.glfwWindowHint(glfw.GLFW_STENCIL_BITS, 8) glfw.glfwWindowHint(glfw.GLFW_FOCUSED, True) fullScreen = False # create window if (not fullScreen): glfw_window = glfw.glfwCreateWindow(1024, 768, "PyCEGUI glfw3 Demo", None, None) else: glfw_window = glfw.glfwCreateWindow(1024, 768, "PyCEGUI glfw3 Demo", glfw.glfwGetPrimaryMonitor(), None) # check window created if not glfw_window: print (" Error : glfw failed to create a window") glfw.glfwTerminate() sys.exit() self.glfw_window = glfw_window glfw.glfwMakeContextCurrent(glfw_window) self.showglfwInfo() ## this does nothing on linux glfw.glfwSwapInterval(0) glfw.glfwSetInputMode(glfw_window, glfw.GLFW_CURSOR, glfw.GLFW_CURSOR_HIDDEN) # call backs glfw.glfwSetKeyCallback( glfw_window, self.on_key) glfw.glfwSetMouseButtonCallback( glfw_window, self.on_mouse) glfw.glfwSetCursorPosCallback( glfw_window, self.on_move) glfw.glfwSetWindowSizeCallback( glfw_window, self.on_resize) glfw.glfwSetCharCallback( glfw_window, self.on_char_callback) glfw.glfwSetFramebufferSizeCallback( glfw_window, self.on_framebuffer_size_callback) # initialise our CEGUI renderer ctx_major = glfw.glfwGetWindowAttrib(glfw_window, glfw.GLFW_CONTEXT_VERSION_MAJOR) ctx_minor = glfw.glfwGetWindowAttrib(glfw_window, glfw.GLFW_CONTEXT_VERSION_MINOR) forward_compat = glfw.glfwGetWindowAttrib(glfw_window, glfw.GLFW_OPENGL_FORWARD_COMPAT) if (not ceguiGL3Renderer): PyCEGUIOpenGLRenderer.OpenGLRenderer.bootstrapSystem() else : PyCEGUIOpenGLRenderer.OpenGL3Renderer.bootstrapSystem() # initialise PyCEGUI and resources rp = PyCEGUI.System.getSingleton().getResourceProvider() rp.setResourceGroupDirectory("schemes", CEGUI_PATH + "schemes") rp.setResourceGroupDirectory("imagesets", CEGUI_PATH + "imagesets") rp.setResourceGroupDirectory("fonts", CEGUI_PATH + "fonts") rp.setResourceGroupDirectory("layouts", CEGUI_PATH + "layouts") rp.setResourceGroupDirectory("looknfeels", CEGUI_PATH + "looknfeel") rp.setResourceGroupDirectory("schemas", CEGUI_PATH + "xml_schemas") PyCEGUI.ImageManager.setImagesetDefaultResourceGroup("imagesets") PyCEGUI.Font.setDefaultResourceGroup("fonts") PyCEGUI.Scheme.setDefaultResourceGroup("schemes") PyCEGUI.WidgetLookManager.setDefaultResourceGroup("looknfeels") PyCEGUI.WindowManager.setDefaultResourceGroup("layouts") parser = PyCEGUI.System.getSingleton().getXMLParser() if parser.isPropertyPresent("SchemaDefaultResourceGroup"): parser.setProperty("SchemaDefaultResourceGroup", "schemas") # Load schemes PyCEGUI.SchemeManager.getSingleton().createFromFile("TaharezLook.scheme") PyCEGUI.SchemeManager.getSingleton().createFromFile("WindowsLook.scheme") PyCEGUI.System.getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage("TaharezLook/MouseArrow") # set root window root = PyCEGUI.WindowManager.getSingleton().createWindow("DefaultWindow", "background_wnd"); root.setArea( PyCEGUI.UVector2(PyCEGUI.UDim(0.0, 0),PyCEGUI.UDim(0.0, 0)) ,PyCEGUI.USize(PyCEGUI.UDim(1.0, 0),PyCEGUI.UDim(1.0, 0))) PyCEGUI.System.getSingleton().getDefaultGUIContext().setRootWindow(root) # load a layout layout = PyCEGUI.WindowManager.getSingleton().loadLayoutFromFile("TextDemo.layout") root.addChild(layout.getChild('TextDemo')) self.edit = root.getChild('TextDemo/MultiLineGroup/editMulti') # create label for our FPS self.labelFPS = PyCEGUI.WindowManager.getSingleton().createWindow("TaharezLook/Label", "FPSLabel") root.addChild(self.labelFPS) # create hello button button = PyCEGUI.WindowManager.getSingleton().createWindow("TaharezLook/Button", "HelloButton") button.setArea( PyCEGUI.UVector2(PyCEGUI.UDim(.50, 0),PyCEGUI.UDim(.92, 0)) ,PyCEGUI.USize(PyCEGUI.UDim(0.3, 0),PyCEGUI.UDim(0.05, 0))) button.setText("Hello") root.addChild(button) button.subscribeEvent(PyCEGUI.PushButton.EventClicked, self.OnbuttonClicked) # init simple timing self.previous_time = glfw.glfwGetTime() self.current_time = self.previous_time