예제 #1
0
    def run(self):
        GLUT.glutInit()
        GLUT.glutSetOption(GLUT.GLUT_MULTISAMPLE, 4)
        GLUT.glutInitDisplayMode(GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH
                                 | GLUT.GLUT_MULTISAMPLE)
        self.width = 1200
        self.height = 720

        GLUT.glutInitWindowSize(self.width, self.height)
        GLUT.glutInitWindowPosition(100, 100)

        self.window = GLUT.glutCreateWindow(self.title)

        self.init_program()

        self.clear()
        self.show_loading_screen()
        self.init_line_buffer()
        self.load_line_buffer()

        GLUT.glutDisplayFunc(self.display)
        GLUT.glutIdleFunc(self.idle)
        GLUT.glutReshapeFunc(self.reshape)
        GLUT.glutKeyboardFunc(self.keyboard)
        GLUT.glutSpecialFunc(self.special)
        GLUT.glutMouseFunc(self.mouse)
        GLUT.glutMotionFunc(self.motion)
        GLUT.glutPassiveMotionFunc(self.motion)

        GLUT.glutMainLoop()
예제 #2
0
파일: _glut.py 프로젝트: kif/vispy
def _init_glut():
    # HiDPI support for retina display
    # This requires glut from
    # http://iihm.imag.fr/blanch/software/glut-macosx/
    if sys.platform == 'darwin':
        try:
            glutInitDisplayString = platform.createBaseFunction(
                'glutInitDisplayString', dll=platform.GLUT,
                resultType=None, argTypes=[ctypes.c_char_p],
                doc='glutInitDisplayString(  ) -> None', argNames=())
            text = ctypes.c_char_p("rgba stencil double samples=8 hidpi")
            glutInitDisplayString(text)
        except Exception:
            pass
    glut.glutInit(['vispy'.encode('ASCII')])  # todo: allow user to give args?
    mode = (glut.GLUT_RGBA | glut.GLUT_DOUBLE |
            glut.GLUT_STENCIL | glut.GLUT_DEPTH)
    if bool(glut.glutInitDisplayMode):
        glut.glutInitDisplayMode(mode)
    # Prevent exit when closing window
    try:
        glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE,
                           glut.GLUT_ACTION_CONTINUE_EXECUTION)
    except Exception:
        pass
    return glut
예제 #3
0
 def __init__(self, width=640, height=480, fullscreen=False, aspect=None):
     self.gl = gl
     glut.glutInit(sys.argv)
     glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB
                              | glut.GLUT_DEPTH)
     glut.glutInitWindowPosition(0, 0)
     glut.glutCreateWindow(b"BlitzLoop Karaoke")
     if not fullscreen:
         glut.glutReshapeWindow(width, height)
     else:
         glut.glutSetCursor(glut.GLUT_CURSOR_NONE)
     BaseDisplay.__init__(self, width, height, fullscreen, aspect)
     self._on_reshape(width, height)
     if fullscreen:
         self.saved_size = (width, height)
         glut.glutFullScreen()
     glut.glutDisplayFunc(self._render)
     glut.glutIdleFunc(self._render)
     glut.glutReshapeFunc(self._on_reshape)
     glut.glutKeyboardFunc(self._on_keyboard)
     glut.glutSpecialFunc(self._on_keyboard)
     try:
         glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE,
                            glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS)
         print("Using FreeGLUT mainloop return feature")
     except:
         pass
     self._initialize()
예제 #4
0
파일: glut.py 프로젝트: marcan/blitzloop
 def __init__(self, width=640, height=480, fullscreen=False, aspect=None):
     self.gl = gl
     glut.glutInit(sys.argv)
     glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH)
     glut.glutInitWindowPosition(0, 0)
     glut.glutCreateWindow(b"BlitzLoop Karaoke")
     if not fullscreen:
         glut.glutReshapeWindow(width, height)
     else:
         glut.glutSetCursor(glut.GLUT_CURSOR_NONE)
     BaseDisplay.__init__(self, width, height, fullscreen, aspect)
     self._on_reshape(width, height)
     if fullscreen:
         self.saved_size = (width, height)
         glut.glutFullScreen()
     glut.glutDisplayFunc(self._render)
     glut.glutIdleFunc(self._render)
     glut.glutReshapeFunc(self._on_reshape)
     glut.glutKeyboardFunc(self._on_keyboard)
     glut.glutSpecialFunc(self._on_keyboard)
     try:
         glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE, glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS)
         print("Using FreeGLUT mainloop return feature")
     except:
         pass
     self._initialize()
예제 #5
0
    def thread_main(instance):
        # sys.stderr.write("Starting thread_main\n")
        GLUT.glutInit(sys.argv)
        GLUT.glutInitContextVersion(3, 3)
        GLUT.glutInitContextFlags(GLUT.GLUT_FORWARD_COMPATIBLE)
        GLUT.glutInitContextProfile(GLUT.GLUT_CORE_PROFILE)
        GLUT.glutSetOption(GLUT.GLUT_ACTION_ON_WINDOW_CLOSE,
                           GLUT.GLUT_ACTION_GLUTMAINLOOP_RETURNS)
        GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE
                                 | GLUT.GLUT_DEPTH)

        # sys.stderr.write("Making default GLUT window.\n")
        GLUT.glutInitWindowSize(instance.width, instance.height)
        GLUT.glutInitWindowPosition(0, 0)
        instance.window = GLUT.glutCreateWindow(
            bytes(instance._title, encoding='UTF-8'))
        # Urgh.... according to the docs, I'm MUST register a display function
        #   for any GLUT window I create.  But... I don't want to do this until
        #   later (in self.__init__).  So, register a null function now,
        #   and hope that registering a new function is an OK thing to do.
        GLUT.glutDisplayFunc(lambda: None)

        # Not sure if I want this as a timer or an idle func
        GLUT.glutIdleFunc(lambda: GLUTContext.class_idle())
        # GLUT.glutTimerFunc(10, lambda val : GLUTContext.class_idle(), 0)
        sys.stderr.write("Going into GLUT.GLUT main loop.\n")
        GLUTContext._class_init = True

        GLUT.glutMainLoop()
예제 #6
0
    def __init__( self, width=256, height=256, title=None, visible=True, aspect=None,
                  decoration=True, fullscreen=False, config=None, context=None, color=(0,0,0,1), vsync=False):

        if vsync:
            log.warn('vsync not implemented for osxglut backend')

        if len(__windows__) > 0:
            log.critical(
                """OSXGLUT backend is unstable with more than one window.\n"""
                """Exiting...""")
            sys.exit(0)

        window.Window.__init__(self, width=width,
                                     height=height,
                                     title=title,
                                     visible=visible,
                                     aspect=aspect,
                                     decoration=decoration,
                                     fullscreen=fullscreen,
                                     config=config,
                                     context=context,
                                     color=color)

        if config is None:
            config = configuration.Configuration()
        set_configuration(config)

        self._native_window = glut.glutCreateWindow( self._title )
        if bool(glut.glutSetOption):
            glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE,
                               glut.GLUT_ACTION_CONTINUE_EXECUTION)
            glut.glutSetOption(glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS,
                               glut.GLUT_ACTION_CONTINUE_EXECUTION)
        glut.glutWMCloseFunc( self._close )
        glut.glutDisplayFunc( self._display )
        glut.glutReshapeFunc( self._reshape )
        glut.glutKeyboardFunc( self._keyboard )
        glut.glutKeyboardUpFunc( self._keyboard_up )
        glut.glutMouseFunc( self._mouse )
        glut.glutMotionFunc( self._motion )
        glut.glutPassiveMotionFunc( self._passive_motion )
        glut.glutVisibilityFunc( self._visibility )
        glut.glutEntryFunc( self._entry )
        glut.glutSpecialFunc( self._special )
        glut.glutSpecialUpFunc( self._special_up )
        glut.glutReshapeWindow( self._width, self._height )
        if visible:
            glut.glutShowWindow()
        else:
            glut.glutHideWindow()

        # This ensures glutCheckLoop never blocks
        def on_idle(): pass
        glut.glutIdleFunc(on_idle)

        __windows__.append(self)
예제 #7
0
    def enable(self, app=None):
        """DEPRECATED since IPython 5.0

        Enable event loop integration with GLUT.

        Parameters
        ----------

        app : ignored
            Ignored, it's only a placeholder to keep the call signature of all
            gui activation methods consistent, which simplifies the logic of
            supporting magics.

        Notes
        -----

        This methods sets the PyOS_InputHook for GLUT, which allows the GLUT to
        integrate with terminal based applications like IPython. Due to GLUT
        limitations, it is currently not possible to start the event loop
        without first creating a window. You should thus not create another
        window but use instead the created one. See 'gui-glut.py' in the
        docs/examples/lib directory.
        
        The default screen mode is set to:
        glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH
        """
        warn(
            "This function is deprecated since IPython 5.0 and will be removed in future versions.",
            DeprecationWarning,
            stacklevel=2)

        import OpenGL.GLUT as glut
        from IPython.lib.inputhookglut import glut_display_mode, \
                                              glut_close, glut_display, \
                                              glut_idle, inputhook_glut

        if GUI_GLUT not in self.manager.apps:
            glut.glutInit(sys.argv)
            glut.glutInitDisplayMode(glut_display_mode)
            # This is specific to freeglut
            if bool(glut.glutSetOption):
                glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE,
                                   glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS)
            glut.glutCreateWindow(sys.argv[0])
            glut.glutReshapeWindow(1, 1)
            glut.glutHideWindow()
            glut.glutWMCloseFunc(glut_close)
            glut.glutDisplayFunc(glut_display)
            glut.glutIdleFunc(glut_idle)
        else:
            glut.glutWMCloseFunc(glut_close)
            glut.glutDisplayFunc(glut_display)
            glut.glutIdleFunc(glut_idle)
        self.manager.set_inputhook(inputhook_glut)
예제 #8
0
    def __init__(self,
                 width=256,
                 height=256,
                 title=None,
                 visible=True,
                 decoration=True,
                 fullscreen=False,
                 config=None,
                 context=None):

        if len(__windows__) > 0:
            log.critical(
                """OSXGLUT backend is unstable with more than one window.\n"""
                """Exiting...""")
            sys.exit(0)

        window.Window.__init__(self, width, height, title, visible, decoration,
                               fullscreen, config, context)

        if config is None:
            config = configuration.Configuration()
        set_configuration(config)

        self._native_window = glut.glutCreateWindow(self._title)
        if bool(glut.glutSetOption):
            glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE,
                               glut.GLUT_ACTION_CONTINUE_EXECUTION)
            glut.glutSetOption(glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS,
                               glut.GLUT_ACTION_CONTINUE_EXECUTION)
        glut.glutWMCloseFunc(self._close)
        glut.glutDisplayFunc(self._display)
        glut.glutReshapeFunc(self._reshape)
        glut.glutKeyboardFunc(self._keyboard)
        glut.glutKeyboardUpFunc(self._keyboard_up)
        glut.glutMouseFunc(self._mouse)
        glut.glutMotionFunc(self._motion)
        glut.glutPassiveMotionFunc(self._passive_motion)
        glut.glutVisibilityFunc(self._visibility)
        glut.glutEntryFunc(self._entry)
        glut.glutSpecialFunc(self._special)
        glut.glutSpecialUpFunc(self._special_up)
        glut.glutReshapeWindow(self._width, self._height)
        if visible:
            glut.glutShowWindow()
        else:
            glut.glutHideWindow()

        # This ensures glutCheckLoop never blocks
        def on_idle():
            pass

        glut.glutIdleFunc(on_idle)

        __windows__.append(self)
예제 #9
0
 def _vispy_get_native_app(self):
     global _GLUT_INITIALIZED
     if not _GLUT_INITIALIZED:
         glut.glutInit(['vispy'.encode('ASCII')])
         # Prevent exit when closing window
         try:
             glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE,
                                glut.GLUT_ACTION_CONTINUE_EXECUTION)
         except Exception:
             pass
         _GLUT_INITIALIZED = True
     return glut
예제 #10
0
 def _vispy_get_native_app(self):
     global _GLUT_INITIALIZED
     if not _GLUT_INITIALIZED:
         glut.glutInit(['vispy'.encode('ASCII')])
         # Prevent exit when closing window
         try:
             glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE,
                                glut.GLUT_ACTION_CONTINUE_EXECUTION)
         except Exception:
             pass
         _GLUT_INITIALIZED = True
     return glut
예제 #11
0
    def enable(self, app=None):
        """DEPRECATED since IPython 5.0

        Enable event loop integration with GLUT.

        Parameters
        ----------

        app : ignored
            Ignored, it's only a placeholder to keep the call signature of all
            gui activation methods consistent, which simplifies the logic of
            supporting magics.

        Notes
        -----

        This methods sets the PyOS_InputHook for GLUT, which allows the GLUT to
        integrate with terminal based applications like IPython. Due to GLUT
        limitations, it is currently not possible to start the event loop
        without first creating a window. You should thus not create another
        window but use instead the created one. See 'gui-glut.py' in the
        docs/examples/lib directory.
        
        The default screen mode is set to:
        glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH
        """
        warn(
            "This function is deprecated since IPython 5.0 and will be removed in future versions.",
            DeprecationWarning,
            stacklevel=2,
        )

        import OpenGL.GLUT as glut
        from IPython.lib.inputhookglut import glut_display_mode, glut_close, glut_display, glut_idle, inputhook_glut

        if GUI_GLUT not in self.manager.apps:
            glut.glutInit(sys.argv)
            glut.glutInitDisplayMode(glut_display_mode)
            # This is specific to freeglut
            if bool(glut.glutSetOption):
                glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE, glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS)
            glut.glutCreateWindow(sys.argv[0])
            glut.glutReshapeWindow(1, 1)
            glut.glutHideWindow()
            glut.glutWMCloseFunc(glut_close)
            glut.glutDisplayFunc(glut_display)
            glut.glutIdleFunc(glut_idle)
        else:
            glut.glutWMCloseFunc(glut_close)
            glut.glutDisplayFunc(glut_display)
            glut.glutIdleFunc(glut_idle)
        self.manager.set_inputhook(inputhook_glut)
예제 #12
0
    def enable_glut(self, app=None):
        """ Enable event loop integration with GLUT.

        Parameters
        ----------

        app : ignored
            Ignored, it's only a placeholder to keep the call signature of all
            gui activation methods consistent, which simplifies the logic of
            supporting magics.

        Notes
        -----

        This methods sets the PyOS_InputHook for GLUT, which allows the GLUT to
        integrate with terminal based applications like IPython. Due to GLUT
        limitations, it is currently not possible to start the event loop
        without first creating a window. You should thus not create another
        window but use instead the created one. See 'gui-glut.py' in the
        docs/examples/lib directory.

        The default screen mode is set to:
        glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH
        """

        import OpenGL.GLUT as glut  # @UnresolvedImport
        from pydev_ipython.inputhookglut import glut_display_mode, \
                                              glut_close, glut_display, \
                                              glut_idle, inputhook_glut

        if GUI_GLUT not in self._apps:
            argv = getattr(sys, 'argv', [])
            glut.glutInit(argv)
            glut.glutInitDisplayMode(glut_display_mode)
            # This is specific to freeglut
            if bool(glut.glutSetOption):
                glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE,
                                   glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS)
            glut.glutCreateWindow(argv[0] if len(argv) > 0 else '')
            glut.glutReshapeWindow(1, 1)
            glut.glutHideWindow()
            glut.glutWMCloseFunc(glut_close)
            glut.glutDisplayFunc(glut_display)
            glut.glutIdleFunc(glut_idle)
        else:
            glut.glutWMCloseFunc(glut_close)
            glut.glutDisplayFunc(glut_display)
            glut.glutIdleFunc(glut_idle)
        self.set_inputhook(inputhook_glut)
        self._current_gui = GUI_GLUT
        self._apps[GUI_GLUT] = True
예제 #13
0
파일: glviewer.py 프로젝트: schnorr/tupan
 def init_window(self):
     glut.glutInit(sys.argv)
     glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_ALPHA | glut.GLUT_DEPTH)
     glut.glutInitWindowPosition(
         (glut.glutGet(glut.GLUT_SCREEN_WIDTH) - self.window_width) // 2,
         (glut.glutGet(glut.GLUT_SCREEN_HEIGHT) - self.window_height) // 2,
     )
     glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE, glut.GLUT_ACTION_CONTINUE_EXECUTION)
     glut.glutInitWindowSize(self.window_width, self.window_height)
     self.window_handle = glut.glutCreateWindow(WINDOW_TITLE_PREFIX)
     glut.glutDisplayFunc(self.render_func)
     glut.glutReshapeFunc(self.resize_func)
     glut.glutMouseFunc(self.mouse)
     glut.glutMotionFunc(self.mouse_motion)
     glut.glutKeyboardFunc(self.keyboard)
     glut.glutSpecialFunc(self.keyboard_s)
예제 #14
0
 def init_window(self):
     glut.glutInit(sys.argv)
     glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA
                              | glut.GLUT_ALPHA | glut.GLUT_DEPTH)
     glut.glutInitWindowPosition(
         (glut.glutGet(glut.GLUT_SCREEN_WIDTH) - self.window_width) // 2,
         (glut.glutGet(glut.GLUT_SCREEN_HEIGHT) - self.window_height) // 2)
     glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE,
                        glut.GLUT_ACTION_CONTINUE_EXECUTION)
     glut.glutInitWindowSize(self.window_width, self.window_height)
     self.window_handle = glut.glutCreateWindow(WINDOW_TITLE_PREFIX)
     glut.glutDisplayFunc(self.render_func)
     glut.glutReshapeFunc(self.resize_func)
     glut.glutMouseFunc(self.mouse)
     glut.glutMotionFunc(self.mouse_motion)
     glut.glutKeyboardFunc(self.keyboard)
     glut.glutSpecialFunc(self.keyboard_s)
예제 #15
0
    def glinit(self):
        self._sock_thread = threading.Thread(target=self._comm_thread,args=(self,))
        self._sock_thread.start()
        
        GLUT.glutInit()
        GLUT.glutSetOption(GLUT.GLUT_ACTION_ON_WINDOW_CLOSE,
                           GLUT.GLUT_ACTION_GLUTMAINLOOP_RETURNS)
        # Some window attributes
        GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE)
        GLUT.glutInitWindowSize(self._width, self._height)
        GLUT.glutInitWindowPosition(0, 0)
        self._win = GLUT.glutCreateWindow(self.title)

        # OpenGL callbacks
        GLUT.glutDisplayFunc(self._draw(self._render_func))
        GLUT.glutKeyboardFunc(self._on_key)
        GLUT.glutMouseFunc(self._on_click)
        GLUT.glutMotionFunc(self._on_mouse_motion)
        GLUT.glutCloseFunc(self._on_exit)
        GLUT.glutTimerFunc(self.refresh, self._timer, self.refresh)

        #set up 2d or 3d viewport in nice orthographic projection
        GL.glViewport(0, 0, self._width, self._height)
        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()
        if self._dim==3:
            GL.glOrtho(-1.,1.,-1,1.,-1000.,1000.)
            GL.glMatrixMode(GL.GL_MODELVIEW)
        else:
            GL.glMatrixMode(GL.GL_PROJECTION)
            GL.glLoadIdentity()
            GLU.gluOrtho2D(-1.,1.,-1.,1.)
        #smooth the crap out of everything
        GL.glEnable(GL.GL_POINT_SMOOTH)
        GL.glEnable(GL.GL_LINE_SMOOTH)
        GL.glEnable(GL.GL_POLYGON_SMOOTH)
        GL.glEnable(GL.GL_BLEND)
        GL.glBlendFunc(GL.GL_ONE,GL.GL_ONE_MINUS_SRC_ALPHA)
        GL.glHint(GL.GL_LINE_SMOOTH_HINT,GL.GL_NICEST)
        GL.glHint(GL.GL_POINT_SMOOTH_HINT,GL.GL_NICEST)
        GL.glHint(GL.GL_POLYGON_SMOOTH_HINT,GL.GL_NICEST)

        #Clear Everything and call the main loop
        GL.glClearColor(*self.background_color)
        self._window_open =True
        GLUT.glutMainLoop()
예제 #16
0
    def init_glut(self, args):
        """Initialize the GLUT state."""

        # Initialize GLUT.
        GLUT.glutInit(args)

        GLUT.glutInitContextVersion(
            self.context_version[0], self.context_version[1])
        GLUT.glutInitContextFlags(GLUT.GLUT_FORWARD_COMPATIBLE)
        GLUT.glutInitContextProfile(GLUT.GLUT_CORE_PROFILE)

        GLUT.glutSetOption(
            GLUT.GLUT_ACTION_ON_WINDOW_CLOSE,
            GLUT.GLUT_ACTION_GLUTMAINLOOP_RETURNS)

        # Initialize and create the main window.
        GLUT.glutInitDisplayMode(
            GLUT.GLUT_DOUBLE | GLUT.GLUT_RGBA | GLUT.GLUT_DEPTH)
        GLUT.glutInitWindowSize(
            self.window_size[0], self.window_size[1])
        GLUT.glutInitWindowPosition(
            self.window_position[0], self.window_position[1])
        GLUT.glutCreateWindow(self.window_title)

        GLUT.glutDisplayFunc(self.render)
        GLUT.glutIdleFunc(self.idle)
        GLUT.glutReshapeFunc(self.resize)
        GLUT.glutKeyboardFunc(self.keyboard)
        GLUT.glutTimerFunc(0, self.timer, 0)
        GLUT.glutMouseFunc(self.mouse)
        GLUT.glutMotionFunc(self.motion)
        GLUT.glutCloseFunc(self.cleanup)

        aspects = [('Vendor', GL.GL_VENDOR),
                   ('Renderer', GL.GL_RENDERER),
                   ('Version', GL.GL_VERSION),]
        if self.context_version[0] > 1:
            aspects.append(('GLSL', GL.GL_SHADING_LANGUAGE_VERSION))

        for i in aspects:
            print('{}: {}'.format(i[0],
                                  GL.glGetString(i[1]).decode()),
                  file=sys.stderr, flush=True)
예제 #17
0
    def display(self):
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        GL.glLoadIdentity()

        self.camera.update()

        self.drawObjects()

        if self.showStats:
            self.drawText()
        GLUT.glutSwapBuffers()

        if self.Animate:
                self.SaveImage(self.imagecount)
                self.imagecount += 1
                self.camera.phi += 1
                if self.imagecount == 360:

                    filenames = listdir('captures/images/')
                    filenames = [int(x.split(".")[0]) for x in filenames]
                    filenames.sort()
                    filenames = [str(x) + ".bmp" for x in filenames]

                    with imageio.get_writer('captures/animations/' +
                                            self.filename +
                                            '.gif', mode='I',
                                            fps=30) as writer:
                        from os import remove
                        for filename in filenames:
                            image = imageio.imread('captures/images/' +
                                                   filename)
                            writer.append_data(image)
                            remove('captures/images/' + filename)
                        GLUT.glutSetOption(GLUT.
                                           GLUT_ACTION_ON_WINDOW_CLOSE,
                                           GLUT.
                                           GLUT_ACTION_GLUTMAINLOOP_RETURNS)
                        self.running = False
                GLUT.glutPostRedisplay()
예제 #18
0
파일: n-body.py 프로젝트: inducer/pyopencl
    wall_time_start = time.time()

    Durations = np.array([], dtype=MyFloat)
    print("Starting!")
    if OpenGL:
        import OpenGL.GL as gl
        import OpenGL.GLUT as glut

        global ViewRX, ViewRY, ViewRZ
        Iterations = 0
        ViewRX, ViewRY, ViewRZ = 0.0, 0.0, 0.0
        # Launch OpenGL Loop
        glut.glutInit(sys.argv)
        glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB)
        glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE,
                           glut.GLUT_ACTION_CONTINUE_EXECUTION)
        glut.glutInitWindowSize(512, 512)
        glut.glutCreateWindow(b"NBodyGL")
        setup_viewport()
        glut.glutReshapeFunc(reshape)
        glut.glutDisplayFunc(display)
        glut.glutIdleFunc(display)
        #   glutMouseFunc(mouse)
        glut.glutSpecialFunc(special)
        glut.glutKeyboardFunc(keyboard)
        glut.glutMainLoop()
    else:
        for iteration in range(Iterations):
            Elapsed = MainOpenCL(clDataX, clDataV, Step, Method)
            if Verbose:
                # print("Duration of #%s iteration: %s" % (iteration,Elapsed))
예제 #19
0
파일: glut.py 프로젝트: 0038lana/Test-Task
    # Close function only hides the current window
    glut.glutHideWindow()
    glutMainLoopEvent()

def glut_int_handler(signum, frame):
    # Catch sigint and print the defaultipyt   message
    signal.signal(signal.SIGINT, signal.default_int_handler)
    print('\nKeyboardInterrupt')
    # Need to reprint the prompt at this stage

# Initialisation code
glut.glutInit( sys.argv )
glut.glutInitDisplayMode( glut_display_mode )
# This is specific to freeglut
if bool(glut.glutSetOption):
    glut.glutSetOption( glut.GLUT_ACTION_ON_WINDOW_CLOSE,
                        glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS )
glut.glutCreateWindow( b'ipython' )
glut.glutReshapeWindow( 1, 1 )
glut.glutHideWindow( )
glut.glutWMCloseFunc( glut_close )
glut.glutDisplayFunc( glut_display )
glut.glutIdleFunc( glut_idle )


def inputhook(context):
    """Run the pyglet event loop by processing pending events only.

    This keeps processing pending events until stdin is ready.  After
    processing all pending events, a call to time.sleep is inserted.  This is
    needed, otherwise, CPU usage is at 100%.  This sleep time should be tuned
    though for best performance.
예제 #20
0
    # Close function only hides the current window
    glut.glutHideWindow()
    glutMainLoopEvent()

def glut_int_handler(signum, frame):
    # Catch sigint and print the defaultipyt   message
    signal.signal(signal.SIGINT, signal.default_int_handler)
    print('\nKeyboardInterrupt')
    # Need to reprint the prompt at this stage

# Initialisation code
glut.glutInit( sys.argv )
glut.glutInitDisplayMode( glut_display_mode )
# This is specific to freeglut
if bool(glut.glutSetOption):
    glut.glutSetOption( glut.GLUT_ACTION_ON_WINDOW_CLOSE,
                        glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS )
glut.glutCreateWindow( b'ipython' )
glut.glutReshapeWindow( 1, 1 )
glut.glutHideWindow( )
glut.glutWMCloseFunc( glut_close )
glut.glutDisplayFunc( glut_display )
glut.glutIdleFunc( glut_idle )


def inputhook(context):
    """Run the pyglet event loop by processing pending events only.

    This keeps processing pending events until stdin is ready.  After
    processing all pending events, a call to time.sleep is inserted.  This is
    needed, otherwise, CPU usage is at 100%.  This sleep time should be tuned
    though for best performance.