def _visible(self, vis):
     # Called from OpenGL when visibility changes (windows are either visible
     # or completely invisible/hidden)
     if vis == GLUT_VISIBLE:
         glutIdleFunc(self._idle)
     else:
         glutIdleFunc(None)
Exemple #2
0
    def __init__(self,
                 title,
                 width=1024,
                 height=768,
                 background_color=color.Smoke):
        self.base_width = width
        self.base_height = height

        glutInit(sys.argv)
        glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH)
        glutInitWindowSize(width, height)
        glutInitWindowPosition((self.screen_width - width) // 2,
                               (self.screen_height - height) // 2)
        glutCreateWindow(title)

        glutKeyboardFunc(self.handle_key)
        glutDisplayFunc(self._draw)
        glutIdleFunc(self.handle_idle)
        glutMouseFunc(self.handle_mouse)
        glutSpecialFunc(self.handle_special_key)
        glutReshapeFunc(self.handle_reshape)

        glEnable(GL_DEPTH_TEST)

        if background_color is not None:
            self.fill_color(*color.Smoke, 1.)
 def init_interface(self):
     """ initialize the window and register the render function """
     glutInit()
     glutInitWindowSize(640, 480)
     glutCreateWindow("3D Modeller")
     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
     glutDisplayFunc(self.render) # top level render call
     glutIdleFunc(self.ROSsleep)
Exemple #4
0
def main():
    hat = Hat()
    if hat.lcd and hat.lcd.use_glut:
        from OpenGL.GLUT import glutMainLoop, glutIdleFunc
        glutIdleFunc(hat.poll)
        glutMainLoop()
    else:
        while True:
            hat.poll()
Exemple #5
0
def main(path=None):
    glutInit(sys.argv)

    if sys.platform == 'darwin':
        if not path:
            path = dialog()

    if not path:
        sys.exit(0)

    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE)
    glutInitWindowPosition(0, 0)
    glutInitWindowSize(730, 650)

    win = glutCreateWindow(b'MIDI Player')

    (width, height, img) = read_image(join(dirname(__file__), 'mixer.ppm'))
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
    texture = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, texture)
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB,
                 GL_UNSIGNED_BYTE, img)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)

    glMatrixMode(GL_TEXTURE)
    glLoadIdentity()
    glScale(1 / width, 1 / height, 1)

    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    glOrtho(0, 730, 0, 650, 0, 1)

    player = Player(win, path, width, height)

    glutDisplayFunc(player.display_func)
    glutKeyboardFunc(player.keyboard_func)
    glutMouseFunc(player.mouse_func)
    glutMotionFunc(player.motion_func)
    glutIdleFunc(player.process_events)

    submenus = []
    for instrument in range(128):
        if instrument % 8 == 0:
            submenus.append([
                families[instrument // 8],
                glutCreateMenu(player.change_instrument)
            ])
        glutAddMenuEntry(instruments[instrument].encode('ascii'), instrument)
    glutCreateMenu(player.change_instrument)
    for family, submenu in submenus:
        glutAddSubMenu(family.encode('ascii'), submenu)
    glutAttachMenu(GLUT_RIGHT_BUTTON)

    glutMainLoop()
Exemple #6
0
def main(path=None):
    glutInit(sys.argv)

    if sys.platform == 'darwin':
        if not path:
            path = dialog()

    if not path:
        sys.exit(0)

    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE)
    glutInitWindowPosition(0, 0)
    glutInitWindowSize(730, 650)

    win = glutCreateWindow(b'MIDI Player')

    (width, height, img) = read_image('mixer.ppm')
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1)

    rbo = c_uint(int(glGenRenderbuffersEXT(1)))
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rbo)
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, width, height)

    fbo = c_uint(int(glGenFramebuffersEXT(1)))
    glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, fbo)
    glFramebufferRenderbufferEXT(GL_READ_FRAMEBUFFER_EXT,
                                 GL_COLOR_ATTACHMENT0_EXT,
                                 GL_RENDERBUFFER_EXT, rbo)

    glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fbo)
    glClear(GL_COLOR_BUFFER_BIT)
    glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, img)
    glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0)

    player = Player(win, path, width, height)

    glutDisplayFunc(player.display_func)
    glutKeyboardFunc(player.keyboard_func)
    glutMouseFunc(player.mouse_func)
    glutMotionFunc(player.motion_func)
    glutIdleFunc(player.process_events)

    submenus = []
    for instrument in range(128):
        if instrument % 8 == 0:
            submenus.append([families[instrument // 8],
                             glutCreateMenu(player.change_instrument)])
        glutAddMenuEntry(instruments[instrument].encode('ascii'), instrument)
    glutCreateMenu(player.change_instrument)
    for family, submenu in submenus:
        glutAddSubMenu(family.encode('ascii'), submenu)
    glutAttachMenu(GLUT_RIGHT_BUTTON)

    glutMainLoop()
Exemple #7
0
def main(path=None):
    glutInit(sys.argv)

    if sys.platform == 'darwin':
        if not path:
            path = dialog()

    if not path:
        sys.exit(0)

    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE)
    glutInitWindowPosition(0, 0)
    glutInitWindowSize(730, 650)

    win = glutCreateWindow(b'MIDI Player')

    (width, height, img) = read_image(join(dirname(__file__), 'mixer.ppm'))
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
    texture = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, texture)
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0,
                 GL_RGB, GL_UNSIGNED_BYTE, img)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)

    glMatrixMode(GL_TEXTURE)
    glLoadIdentity()
    glScale(1/width, 1/height, 1)

    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    glOrtho(0, 730, 0, 650, 0, 1)

    player = Player(win, path, width, height)

    glutDisplayFunc(player.display_func)
    glutKeyboardFunc(player.keyboard_func)
    glutMouseFunc(player.mouse_func)
    glutMotionFunc(player.motion_func)
    glutIdleFunc(player.process_events)

    submenus = []
    for instrument in range(128):
        if instrument % 8 == 0:
            submenus.append([families[instrument // 8],
                             glutCreateMenu(player.change_instrument)])
        glutAddMenuEntry(instruments[instrument].encode('ascii'), instrument)
    glutCreateMenu(player.change_instrument)
    for family, submenu in submenus:
        glutAddSubMenu(family.encode('ascii'), submenu)
    glutAttachMenu(GLUT_RIGHT_BUTTON)

    glutMainLoop()
Exemple #8
0
    def init_opengl(self, width, height, x, y):
        glutInit()
        glutInitWindowPosition(x, y)
        glutInitWindowSize(width, height)
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE)
        glutCreateWindow("Rainbow Alga")
        glutDisplayFunc(self.render)
        glutIdleFunc(self.render)
        glutReshapeFunc(self.resize)

        glutMouseFunc(self.mouse)
        glutMotionFunc(self.drag)
        glutKeyboardFunc(self.keyboard)
        glutSpecialFunc(self.special_keyboard)

        glClearDepth(1.0)
        glClearColor(0.0, 0.0, 0.0, 0.0)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 3000)
        glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT)


        # Lighting
        light_ambient = (0.0, 0.0, 0.0, 1.0)
        light_diffuse = (1.0, 1.0, 1.0, 1.0)
        light_specular = (1.0, 1.0, 1.0, 1.0)
        light_position = (-100.0, 100.0, 100.0, 0.0)

        mat_ambient = (0.7, 0.7, 0.7, 1.0)
        mat_diffuse = (0.8, 0.8, 0.8, 1.0)
        mat_specular = (1.0, 1.0, 1.0, 1.0)
        high_shininess = (100)

        glEnable(GL_LIGHT0)
        glEnable(GL_NORMALIZE)
        glEnable(GL_COLOR_MATERIAL)
        glEnable(GL_LIGHTING)

        glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse)
        glLightfv(GL_LIGHT0, GL_SPECULAR,  light_specular)
        glLightfv(GL_LIGHT0, GL_POSITION, light_position)

        glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient)
        glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse)
        glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular)
        glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess)

        # Transparency
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Exemple #9
0
def create_window(winname, size=(800, 600), display=None, resize=None):
    glutInit(argv)
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
    glutInitWindowSize(size[0], size[1])
    glutCreateWindow(winname.encode('ascii'))

    if display is not None:
        display_func = _display_wrapper(display)
        glutDisplayFunc(display_func)
        glutIdleFunc(display_func)

    if resize is not None:
        glutReshapeFunc(resize)
Exemple #10
0
        def process(pipe, config):
            import lcd
            print('lcd process on', os.getpid())
            self.lcd = lcd.LCD(self.hat.config)
            self.lcd.pipe = pipe

            if self.lcd.use_glut:
                from OpenGL.GLUT import glutMainLoop, glutIdleFunc
                glutIdleFunc(self.lcd.poll)
                glutMainLoop()
            else:
                while True:
                    self.lcd.poll()
Exemple #11
0
def run():
    global window
    glutInit(sys.argv)

    # Select type of Display mode:   
    #  Double buffer 
    #  RGBA color
    # Alpha components supported 
    # Depth buffer
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
    
    # get a 640 x 480 window
    resolution = get_state()["camera"]["resolution"]
    glutInitWindowSize(int(resolution[0]), int(resolution[1]))
    
    # the window starts at the upper left corner of the screen 
    glutInitWindowPosition(0, 0)
    
    # Okay, like the C version we retain the window id to use when closing, but for those of you new
    # to Python (like myself), remember this assignment would make the variable local and not global
    # if it weren't for the global declaration at the start of main.
    window = glutCreateWindow("Waffle")

       # Register the drawing function with glut, BUT in Python land, at least using PyOpenGL, we need to
    # set the function pointer and invoke a function to actually register the callback, otherwise it
    # would be very much like the C version of the code.    
    glutDisplayFunc(DrawGLScene)
    
    # Uncomment this line to get full screen.
    # glutFullScreen()

    # When we are doing nothing, redraw the scene.
    glutIdleFunc(idleFunc)
    
    # Register the function called when our window is resized.
    glutReshapeFunc(ReSizeGLScene)
    
    # Register the function called when the keyboard is pressed.  
    glutKeyboardFunc(keyDown)
    glutKeyboardUpFunc(keyUp)
    glutMouseFunc(onMouseClick)
    glutMotionFunc(onMouseClickMove)
    glutPassiveMotionFunc(onMouseMove)

    # Initialize our window. 
    InitGL()
    init_world()
    init_interface()

    # Start Event Processing Engine    
    glutMainLoop()
Exemple #12
0
 def _initGL(self, extraArgs):
     """initializes OpenGL and creates the Window"""
     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
     glutInitWindowSize(self.size, self.size)
     glutInitWindowPosition(self.initx, self.inity)
     glutInit(extraArgs.split(" "))
     glutCreateWindow(VERSIONSTRING.encode("ascii"))
     glutDisplayFunc(self.Draw)
     glutIdleFunc(glutPostRedisplay)
     glutReshapeFunc(self.Reshape)
     glutKeyboardFunc(self.HandleKeys)
     glutSpecialFunc(self.HandleKeys)
     glutMouseFunc(self.HandleMouse)
     glClearColor(*(self.bgcolor + [0.0]))
     glEnable(GL_LINE_SMOOTH)
     glLineWidth(1.3)
    def initialize(self):
        """Sets up the OpenGL window and binds input callbacks to it
        """

        glutKeyboardFunc(self._on_key_down)
        glutSpecialFunc(self._on_special_key_down)

        # [Keyboard/Special]Up methods aren't supported on some old GLUT implementations
        has_keyboard_up = False
        has_special_up = False
        try:
            if bool(glutKeyboardUpFunc):
                glutKeyboardUpFunc(self._on_key_up)
                has_keyboard_up = True
            if bool(glutSpecialUpFunc):
                glutSpecialUpFunc(self._on_special_key_up)
                has_special_up = True
        except NullFunctionError:
            # Methods aren't available on this GLUT version
            pass

        if not has_keyboard_up or not has_special_up:
            # Warn on old GLUT implementations that don't implement much of the interface.
            self._logger.warning(
                "Warning: Old GLUT implementation detected - keyboard remote control of Vector disabled."
                "We recommend installing freeglut. %s",
                _glut_install_instructions())
            self._is_keyboard_control_enabled = False
        else:
            self._is_keyboard_control_enabled = True

        try:
            GLUT_BITMAP_9_BY_15
        except NameError:
            self._logger.warning(
                "Warning: GLUT font not detected. Help message will be unavailable."
            )

        glutMouseFunc(self._on_mouse_button)
        glutMotionFunc(self._on_mouse_move)
        glutPassiveMotionFunc(self._on_mouse_move)

        glutIdleFunc(self._idle)
        glutVisibilityFunc(self._visible)
    def __init__(self, winname, size=(800, 600), display_func=None, resize_func=None):
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
        glutInitWindowSize(size[0], size[1])
        self._win_id = glutCreateWindow(winname.encode('ascii'))
        self.display_func = display_func
        self.resize_func = resize_func
        self.width = size[0]
        self.height = size[1]

        if display_func is not None:
            display_func = _display_wrapper(display_func)
            glutDisplayFunc(display_func)
            glutIdleFunc(display_func)

        if resize_func is not None:
            resize_func = _resize_wrapper(self, resize_func)
            glutReshapeFunc(resize_func)

        glClearColor(0, 0, 0, 0)
Exemple #15
0
    def initialize(self, display_function: callable):
        """Initialze the OpenGL display parts of the Window.

        Warning:
            Must be called on the same thread as OpenGL (usually the main thread),
        """

        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)

        glutInitWindowSize(self.width, self.height)
        glutInitWindowPosition(*self._pos)
        self._gl_window = glutCreateWindow(self._window_name)

        glClearColor(0, 0, 0, 0)
        glEnable(GL_DEPTH_TEST)
        glShadeModel(GL_SMOOTH)

        glutIdleFunc(self._idle)
        glutVisibilityFunc(self._visible)
        glutReshapeFunc(self._reshape)

        glutDisplayFunc(display_function)
Exemple #16
0
def main():
    lcd = LCD(False)

    def idle():
        lcd.poll()
        if lcd.glutkeytime:
            k, t = lcd.glutkeytime
            dt = gettime() - t
            if dt > .5:
                lcd.keypad[k].update(False)
                lcd.glutkeytime = False

        time.sleep(.1)

    if lcd.use_glut:
        from OpenGL.GLUT import glutMainLoop, glutIdleFunc
        glutIdleFunc(idle)
        glutMainLoop()
    else:
        while True:
            lcd.poll()
            time.sleep(.1)
Exemple #17
0
 def idle_func(cls, callback):
     glutIdleFunc(callback)
    grid += struct.pack('6f', i - 16.0, -16.0, 0.0, 0.0, 0.0, 0.0)
    grid += struct.pack('6f', i - 16.0, 16.0, 0.0, 0.0, 0.0, 0.0)
    grid += struct.pack('6f', -16.0, i - 16.0, 0.0, 0.0, 0.0, 0.0)
    grid += struct.pack('6f', 16.0, i - 16.0, 0.0, 0.0, 0.0, 0.0)

vbo = ctx.buffer(grid)
vao = ctx.simple_vertex_array(prog, vbo, ['in_vert', 'in_color'])


def display():
    ctx.viewport = (0, 0, width, height)
    ctx.clear(0.9, 0.9, 0.9)
    ctx.enable(ModernGL.DEPTH_TEST)

    proj = Matrix44.perspective_projection(45.0, width / height, 0.1, 1000.0)
    lookat = Matrix44.look_at(
        (40.0, 30.0, 20.0),
        (0.0, 0.0, 0.0),
        (0.0, 0.0, 1.0),
    )

    mvp.write((proj * lookat).astype('float32').tobytes())
    vao.render(ModernGL.LINES)

    glutSwapBuffers()


glutDisplayFunc(display)
glutIdleFunc(display)
glutMainLoop()
Exemple #19
0
    progress = 0.0
    textures = {}
    picture_display_lists = {}
    mosaic_display_lists = {}

    mosaic_factory = MosaicFactory.load(args.folder)

    HEIGHT = 100.
    size = HEIGHT / args.tiles

    iterator = image_iterator(mosaic_factory, args.tiles, args.reuse)
    current_tile_picture = iterator.next()
    current_mosaic_picture = iterator.next()
    start_orientation = current_tile_picture.orientation

    start_picture_coord = find_picture_in_mosaic(
        current_tile_picture,
        mosaic_factory.mosaic(current_mosaic_picture, args.tiles, args.reuse)
    )

    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
    glutInitWindowSize(640, 480)
    glutCreateWindow("Mosaic for " + args.folder)
    init()
    glutDisplayFunc(display)
    glutReshapeFunc(reshape)
    glutIdleFunc(spin_display)
    glutMainLoop()
Exemple #20
0
    args = parser.parse_args()

    progress = 0.0
    textures = {}
    picture_display_lists = {}
    mosaic_display_lists = {}

    mosaic_factory = MosaicFactory.load(args.folder)

    HEIGHT = 100.
    size = HEIGHT / args.tiles

    iterator = image_iterator(mosaic_factory, args.tiles, args.reuse)
    current_tile_picture = iterator.next()
    current_mosaic_picture = iterator.next()
    start_orientation = current_tile_picture.orientation

    start_picture_coord = find_picture_in_mosaic(
        current_tile_picture,
        mosaic_factory.mosaic(current_mosaic_picture, args.tiles, args.reuse))

    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
    glutInitWindowSize(640, 480)
    glutCreateWindow("Mosaic for " + args.folder)
    init()
    glutDisplayFunc(display)
    glutReshapeFunc(reshape)
    glutIdleFunc(spin_display)
    glutMainLoop()
            f_color = vec4(v_color, 1.0);
        }
    '''),
])

window_size = prog.uniforms['WindowSize']

vbo = ctx.buffer(struct.pack(
    '15f',
    0.0, 100.0, 1.0, 0.0, 0.0,
    -86.0, -50.0, 0.0, 1.0, 0.0,
    86.0, -50.0, 0.0, 0.0, 1.0,
))

vao = ctx.simple_vertex_array(prog, vbo, ['in_vert', 'in_color'])


def display():
    ctx.viewport = (0, 0, width, height)
    ctx.clear(0.9, 0.9, 0.9)
    ctx.enable(ModernGL.BLEND)
    window_size.value = (width, height)
    vao.render()

    glutSwapBuffers()


glutDisplayFunc(display)
glutIdleFunc(display)
glutMainLoop()
Exemple #22
0
def main():
    print 'init...'
    screen = None
    for arg in sys.argv:
        if 'nokia5110' in arg:
            sys.argv.remove(arg)
            print 'using nokia5110'
            screen = ugfx.nokia5110screen()

    if not screen:
        if use_glut:
            screen = glut.screen((120, 210))
            #screen = glut.screen((64, 128))
            #screen = glut.screen((48, 84))
        else:
            screen = ugfx.screen("/dev/fb0")
            if screen.width == 416 and screen.height == 656:
                # no actual device or display
                print 'no actual screen, running headless'
                screen = None

            if screen.width > 480:
                screen.width = 480
                screen.height= min(screen.height, 640)

    lcdclient = LCDClient(screen)
    if screen:
        # magnify to fill screen
        mag = min(screen.width / lcdclient.surface.width, screen.height / lcdclient.surface.height)
        if mag != 1:
            print "magnifying lcd surface to fit screen"
            magsurface = ugfx.surface(screen)

        invsurface = ugfx.surface(lcdclient.surface)
        
    def idle():
        if screen:
            lcdclient.display()

            surface = lcdclient.surface
            if lcdclient.config['invert']:
                invsurface.blit(surface, 0, 0)
                surface = invsurface
                surface.invert(0, 0, surface.width, surface.height)

            if mag != 1:
                magsurface.magnify(surface, mag)
                surface = magsurface
                #        mag = 2
                #surface.magnify(mag)

            screen.blit(surface, 0, 0, lcdclient.config['flip'])
            screen.refresh()

            if 'contrast' in lcdclient.config:
                screen.contrast = int(lcdclient.config['contrast'])

        lcdclient.idle()

    if use_glut:
        from OpenGL.GLUT import glutMainLoop
        from OpenGL.GLUT import glutIdleFunc
        from OpenGL.GLUT import glutKeyboardFunc
        from OpenGL.GLUT import glutKeyboardUpFunc
        from OpenGL.GLUT import glutSpecialFunc
        from OpenGL.GLUT import glutSpecialUpFunc

        glutKeyboardFunc(lcdclient.glutkeydown)
        glutKeyboardUpFunc(lcdclient.glutkeyup)
        glutSpecialFunc(lcdclient.glutspecialdown)
        glutSpecialUpFunc(lcdclient.glutspecialup)
        glutIdleFunc(idle)
#        glutIgnoreKeyRepeat(True)
        glutMainLoop()
    else:
        while True:
            idle()