Exemple #1
0
    def __init__(self, str_vs, str_fs):
        cwd = os.getcwd()                   # get current working directory

        glfw.glfwInit()                     # glfw initialization

        os.chdir(cwd)                      # restore current directory

        # make a window
        self.width, self.height = 640, 480
        self.aspect = self.width / float(self.height)
        self.win = glfw.glfwCreateWindow(self.width, self.height, b'simpleglfw')

        glfw.glfwMakeContextCurrent(self.win)       # current context

        # initialize GL
        glViewport(0, 0, self.width, self.height)
        glEnable(GL_DEPTH_TEST)
        glClearColor(0.5, 0.5, 0.5, 1.0)

        # set window callbacks
        glfw.glfwSetMouseButtonCallback(self.win, self.on_mouse_button)
        glfw.glfwSetKeyCallback(self.win, self.on_keyboard)
        glfw.glfwSetWindowSizeCallback(self.win, self.on_size)

        self.scene = Scene(str_vs, str_fs)                  # create 3D
        self.exit_now = False                   # exit flag
Exemple #2
0
    def __init__(self):
        cwd = os.getcwd()
        glfw.glfwInit()
        os.chdir(cwd)

        #将OpenGL版本设置为OpenGL 3.3的核心模式
        glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MAJOR, 3)
        glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MINOR, 3)
        glfw.glfwWindowHint(glfw.GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE)
        glfw.glfwWindowHint(glfw.GLFW_OPENGL_PROFILE,
                            glfw.GLFW_OPENGL_CORE_PROFILE)

        self.width, self.height = 640, 480
        self.aspect = self.width / self.height
        #创建尺寸为640x480,支持OpenGL的窗口
        self.win = glfw.glfwCreateWindow(self.width, self.height,
                                         b"simpleglfw")

        #该窗口设为当前OpenGL的上下文
        glfw.glfwMakeContextCurrent(self.win)

        glViewport(0, 0, self.width, self.height)
        glEnable(GL_DEPTH_TEST)
        glClearColor(0.5, 0.5, 0.5, 1.0)

        glfw.glfwSetMouseButtonCallback(self.win, self.onMouseButton)
        glfw.glfwSetKeyCallback(self.win, self.onKeyboard)
        glfw.glfwSetWindowSizeCallback(self.win, self.onSize)

        self.scene = Scene()
        self.exitNow = False
Exemple #3
0
 def _register_callbacks(self, window):
     glfw.glfwSetWindowSizeCallback(window, self._on_set_window_size)
     glfw.glfwSetWindowPosCallback(window, self._on_set_window_pos)
     glfw.glfwSetFramebufferSizeCallback(window, self._on_set_frame_buffer_size)
     glfw.glfwSetMouseButtonCallback(window, self._on_set_mouse_button)
     glfw.glfwSetCursorPosCallback(window, self._on_set_cursor_pos)
     glfw.glfwSetScrollCallback(window, self._on_set_scroll)
     glfw.glfwSetWindowCloseCallback(window, self._on_set_window_close)
Exemple #4
0
 def _register_callbacks(self, window):
     glfw.glfwSetWindowSizeCallback(window, self._on_set_window_size)
     glfw.glfwSetWindowPosCallback(window, self._on_set_window_pos)
     glfw.glfwSetFramebufferSizeCallback(window, self._on_set_frame_buffer_size)
     glfw.glfwSetMouseButtonCallback(window, self._on_set_mouse_button)
     glfw.glfwSetCursorPosCallback(window, self._on_set_cursor_pos)
     glfw.glfwSetScrollCallback(window, self._on_set_scroll)
     glfw.glfwSetWindowCloseCallback(window, self._on_set_window_close)
Exemple #5
0
    def __init__(self):
        self.camera = Camera([15.0, 0.0, 2.5],
                             [0.0, 0.0, 2.5],
                             [0.0, 0.0, 1.0])
        self.aspect = 1.0
        self.numP = 300
        self.t = 0
        # flag to rotate camera view
        self.rotate = True

        # save current working directory
        cwd = os.getcwd()

        # initialize glfw - this changes cwd
        glfw.glfwInit()
        
        # restore cwd
        os.chdir(cwd)

        # version hints
        glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MAJOR, 3)
        glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MINOR, 3)
        glfw.glfwWindowHint(glfw.GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE)
        glfw.glfwWindowHint(glfw.GLFW_OPENGL_PROFILE, 
                            glfw.GLFW_OPENGL_CORE_PROFILE)

        # make a window
        self.width, self.height = 640, 480
        self.aspect = self.width/float(self.height)
        self.win = glfw.glfwCreateWindow(self.width, self.height, 
                                     b"Particle System")
        # make context current
        glfw.glfwMakeContextCurrent(self.win)
        
        # initialize GL
        glViewport(0, 0, self.width, self.height)
        glEnable(GL_DEPTH_TEST)
        glClearColor(0.2, 0.2, 0.2,1.0)

        # set window callbacks
        glfw.glfwSetMouseButtonCallback(self.win, self.onMouseButton)
        glfw.glfwSetKeyCallback(self.win, self.onKeyboard)
        glfw.glfwSetWindowSizeCallback(self.win, self.onSize)        

        # create 3D
        self.psys = ParticleSystem(self.numP)
        self.box = Box(1.0)

        # exit flag
        self.exitNow = False
    def __init__(self):
        self.camera = Camera([15.0, 0.0, 2.5], [0.0, 0.0, 2.5],
                             [0.0, 0.0, 1.0])
        self.aspect = 1.0
        self.numP = 300
        self.t = 0
        # flag to rotate camera view
        self.rotate = True

        # save current working directory
        cwd = os.getcwd()

        # initialize glfw - this changes cwd
        glfw.glfwInit()

        # restore cwd
        os.chdir(cwd)

        # version hints
        glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MAJOR, 3)
        glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MINOR, 3)
        glfw.glfwWindowHint(glfw.GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE)
        glfw.glfwWindowHint(glfw.GLFW_OPENGL_PROFILE,
                            glfw.GLFW_OPENGL_CORE_PROFILE)

        # make a window
        self.width, self.height = 640, 480
        self.aspect = self.width / float(self.height)
        self.win = glfw.glfwCreateWindow(self.width, self.height,
                                         b"Particle System")
        # make context current
        glfw.glfwMakeContextCurrent(self.win)

        # initialize GL
        glViewport(0, 0, self.width, self.height)
        glEnable(GL_DEPTH_TEST)
        glClearColor(0.2, 0.2, 0.2, 1.0)

        # set window callbacks
        glfw.glfwSetMouseButtonCallback(self.win, self.onMouseButton)
        glfw.glfwSetKeyCallback(self.win, self.onKeyboard)
        glfw.glfwSetWindowSizeCallback(self.win, self.onSize)

        # create 3D
        self.psys = ParticleSystem(self.numP)
        self.box = Box(1.0)

        # exit flag
        self.exitNow = False
Exemple #7
0
    def __init__(self):

        # save current working directory
        cwd = os.getcwd()

        # initialize glfw - this changes cwd
        glfw.glfwInit()

        # restore cwd
        os.chdir(cwd)

        # version hints
        glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MAJOR, 4)
        glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MINOR, 0)
        glfw.glfwWindowHint(glfw.GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE)
        glfw.glfwWindowHint(glfw.GLFW_OPENGL_PROFILE,
                            glfw.GLFW_OPENGL_CORE_PROFILE)

        # make a window
        self.width, self.height = 640, 480
        self.aspect = self.width / float(self.height)
        self.win = glfw.glfwCreateWindow(self.width, self.height,
                                         b'simpleglfw')
        # make context current
        glfw.glfwMakeContextCurrent(self.win)

        # initialize GL
        glViewport(0, 0, self.width, self.height)
        #glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_NEVER)
        glClearColor(0.5, 0.5, 0.5, 1.0)

        # set window callbacks
        glfw.glfwSetMouseButtonCallback(self.win, self.onMouseButton)
        glfw.glfwSetKeyCallback(self.win, self.onKeyboard)
        glfw.glfwSetWindowSizeCallback(self.win, self.onSize)

        # create 3D
        self.scene = Scene()

        # exit flag
        self.exitNow = False
    def __init__(self, imageDir):

        # save current working directory
        cwd = os.getcwd()

        # initialize glfw - this changes cwd
        glfw.glfwInit()

        # restore cwd
        os.chdir(cwd)

        # version hints
        glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MAJOR, 3)
        glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MINOR, 3)
        glfw.glfwWindowHint(glfw.GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE)
        glfw.glfwWindowHint(glfw.GLFW_OPENGL_PROFILE,
                            glfw.GLFW_OPENGL_CORE_PROFILE)

        # make a window
        self.width, self.height = 512, 512
        self.aspect = self.width / float(self.height)
        self.win = glfw.glfwCreateWindow(self.width, self.height, b"volrender")
        # make context current
        glfw.glfwMakeContextCurrent(self.win)

        # initialize GL
        glViewport(0, 0, self.width, self.height)
        glEnable(GL_DEPTH_TEST)
        glClearColor(0.0, 0.0, 0.0, 0.0)

        # set window callbacks
        glfw.glfwSetMouseButtonCallback(self.win, self.onMouseButton)
        glfw.glfwSetKeyCallback(self.win, self.onKeyboard)
        glfw.glfwSetWindowSizeCallback(self.win, self.onSize)

        # load volume data
        self.volume = volreader.loadVolume(imageDir)
        # create renderer
        self.renderer = RayCastRender(self.width, self.height, self.volume)

        # exit flag
        self.exitNow = False
Exemple #9
0
    def __init__(self, imageDir):
        
        # save current working directory
        cwd = os.getcwd()

        # initialize glfw - this changes cwd
        glfw.glfwInit()
        
        # restore cwd
        os.chdir(cwd)

        # version hints
        glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MAJOR, 3)
        glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MINOR, 3)
        glfw.glfwWindowHint(glfw.GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE)
        glfw.glfwWindowHint(glfw.GLFW_OPENGL_PROFILE, glfw.GLFW_OPENGL_CORE_PROFILE)

        # make a window
        self.width, self.height = 512, 512
        self.aspect = self.width/float(self.height)
        self.win = glfw.glfwCreateWindow(self.width, self.height, b"volrender")
        # make context current
        glfw.glfwMakeContextCurrent(self.win)
        
        # initialize GL
        glViewport(0, 0, self.width, self.height)
        glEnable(GL_DEPTH_TEST)
        glClearColor(0.0, 0.0, 0.0, 0.0)

        # set window callbacks
        glfw.glfwSetMouseButtonCallback(self.win, self.onMouseButton)
        glfw.glfwSetKeyCallback(self.win, self.onKeyboard)
        glfw.glfwSetWindowSizeCallback(self.win, self.onSize)

        # load volume data
        self.volume =  volreader.loadVolume(imageDir)
        # create renderer
        self.renderer = RayCastRender(self.width, self.height, self.volume)

        # exit flag
        self.exitNow = False
Exemple #10
0
    def __init__(self):

        # save current working directory
        cwd = os.getcwd()

        # initialize glfw - this changes cwd
        glfw.glfwInit()
        
        # restore cwd
        os.chdir(cwd)

        # version hints
        glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MAJOR, 3)
        glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MINOR, 3)
        glfw.glfwWindowHint(glfw.GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE)
        glfw.glfwWindowHint(glfw.GLFW_OPENGL_PROFILE, 
                            glfw.GLFW_OPENGL_CORE_PROFILE)
    
        # make a window
        self.width, self.height = 640, 480
        self.aspect = self.width/float(self.height)
        self.win = glfw.glfwCreateWindow(self.width, self.height, 
                                         b'simpleglfw')
        # make context current
        glfw.glfwMakeContextCurrent(self.win)
        
        # initialize GL
        glViewport(0, 0, self.width, self.height)
        glEnable(GL_DEPTH_TEST)
        glClearColor(0.5, 0.5, 0.5,1.0)

        # set window callbacks
        glfw.glfwSetMouseButtonCallback(self.win, self.onMouseButton)
        glfw.glfwSetKeyCallback(self.win, self.onKeyboard)
        glfw.glfwSetWindowSizeCallback(self.win, self.onSize)        

        # create 3D
        self.scene = Scene()

        # exit flag
        self.exitNow = False
 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