Exemple #1
0
    def init(self, hide_window):
        # Shift from ARGB to RGBA
        self.color_palette = [((x << 8) & 0xFFFFFFFF) | 0x000000FF
                              for x in self.color_palette]
        self.alphamask = 0x000000FF
        self.color_format = u"RGB"
        self.buffer_dims = (144, 160)

        if not glutInit():
            raise Exception("OpenGL couldn't initialize!")
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA)
        glutInitWindowSize(*self._scaledresolution)
        glutCreateWindow("PyBoy")
        glutKeyboardFunc(self._key)
        glutKeyboardUpFunc(self._keyUp)
        glutSpecialFunc(self._spec)
        glutSpecialUpFunc(self._specUp)
        self.events = []

        glPixelZoom(self._scale, self._scale)
        glutReshapeFunc(self._glreshape)
        glutDisplayFunc(self._gldraw)

        if hide_window:
            logger.warning("Hiding the window is not supported in OpenGL")
Exemple #2
0
    def __init__(self, model):
        """Initialize input handlers and link given Model to the Input."""
        self.__model = model

        glutKeyboardFunc(lambda key, x, y: self.__handle_key(key, False))
        glutKeyboardUpFunc(lambda key, x, y: self.__handle_key(key, True))
        glutSpecialFunc(lambda key, x, y: self.__handle_special(key))
Exemple #3
0
    def __init__(self, model):
        """Initialize input handlers and link given Model to the Input."""
        self.__model = model

        glutKeyboardFunc(lambda key, x, y: self.__handle_key(key, False))
        glutKeyboardUpFunc(lambda key, x, y: self.__handle_key(key, True))
        glutSpecialFunc(lambda key, x, y: self.__handle_special(key))
Exemple #4
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()
    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)
Exemple #6
0
    def init(self):
        # Shift from ARGB to RGBA
        self.color_palette = [((x << 8) & 0xFFFFFFFF) | 0x000000FF for x in self.color_palette]
        self.alphamask = 0x000000FF
        self.color_format = u"RGB"

        glutInit()
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA)
        glutInitWindowSize(*self._scaledresolution)
        glutCreateWindow("PyBoy")
        glutKeyboardFunc(self._key)
        glutKeyboardUpFunc(self._keyUp)
        glutSpecialFunc(self._spec)
        glutSpecialUpFunc(self._specUp)
        self.events = []

        glPixelZoom(self._scale, self._scale)
        glutReshapeFunc(self._glreshape)
        glutDisplayFunc(self._gldraw)
Exemple #7
0
    def __init__(self, pyboy, mb, pyboy_argv):
        super().__init__(pyboy, mb, pyboy_argv)

        if not self.enabled():
            return

        if not glutInit():
            raise Exception("OpenGL couldn't initialize!")
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA)
        glutInitWindowSize(*self._scaledresolution)
        glutCreateWindow("PyBoy")
        glutKeyboardFunc(self._key)
        glutKeyboardUpFunc(self._keyUp)
        glutSpecialFunc(self._spec)
        glutSpecialUpFunc(self._specUp)
        self.events = []

        glPixelZoom(self.scale, self.scale)
        glutReshapeFunc(self._glreshape)
        glutDisplayFunc(self._gldraw)
Exemple #8
0
    def init(self):
        # Shift from ARGB to RGBA
        self.color_palette = [((x << 8) & 0xFFFFFFFF) | 0x000000FF
                              for x in self.color_palette]
        self.alphamask = 0x000000FF
        self.color_format = u"RGB"

        glutInit()
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA)
        glutInitWindowSize(*self._scaledresolution)
        glutCreateWindow("PyBoy")
        glutKeyboardFunc(self._key)
        glutKeyboardUpFunc(self._keyUp)
        glutSpecialFunc(self._spec)
        glutSpecialUpFunc(self._specUp)
        self.events = []

        glPixelZoom(self._scale, self._scale)
        glutReshapeFunc(self._glreshape)
        glutDisplayFunc(self._gldraw)
Exemple #9
0
def register_callbacks():
    """
    Registers the following callbacks with GLUT:
        - glutKeyboardFunc
        - glutKeyboardUpFunc

        - glutSpecialFunc
        - glutSpecialUpFunc

        - glutMotionFunc
        - glutPassiveMotionFunc

        - glutMouseFunc
    """
    glutKeyboardFunc(_key_down)
    glutKeyboardUpFunc(_key_up)

    glutSpecialFunc(_special_down)
    glutSpecialUpFunc(_special_up)

    glutMotionFunc(_mouse_pos_listener)
    glutPassiveMotionFunc(_mouse_pos_listener)

    glutMouseFunc(_mouse_button_listener)
Exemple #10
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()
Exemple #11
0
    def __init__(self, hat):
        self.hat = hat

        if hat:
            self.config = hat.config['lcd']
        elif micropython:
            from config_esp32 import read_config
            self.config = read_config()
        else:
            self.config = {}

        default = {
            'contrast': 60,
            'invert': False,
            'backlight': 20,
            'flip': False,
            'language': 'en',
            'bigstep': 10,
            'smallstep': 1
        }

        for name in default:
            if not name in self.config:
                self.config[name] = default[name]

        # set the driver to the one from hat eeprom
        driver = 'default'
        if self.hat and 'hat' in self.hat.config:
            driver = self.hat.config['hat']['lcd']['driver']
            self.host = self.hat.client.config['host']
        else:
            self.host = False

        for pdriver in [
                'nokia5110', 'jlx12864', 'glut', 'framebuffer', 'tft', 'none'
        ]:
            if pdriver in sys.argv:
                print('overriding driver', driver, ' to command line', pdriver)
                sys.argv.remove(pdriver)
                driver = pdriver
                break

        self.battery_voltage = 0
        use_tft = True if micropython else False

        if not use_tft:
            use_glut = 'DISPLAY' in os.environ
        self.use_glut = False
        self.surface = None

        if driver == 'none':
            page = None
        elif driver == 'tft' or (driver == 'default' and use_tft):
            screen = ugfx.surface(136, 240, 1)
            self.surface = screen
        elif driver == 'nokia5110' or (driver == 'default' and not use_glut):
            screen = ugfx.spiscreen(0)
        elif driver == 'jlx12864':
            screen = ugfx.spiscreen(1)
        elif driver == 'glut' or (driver == 'default' and use_glut):
            self.use_glut = True
            print('using glut')
            import glut
            # emulate which screen resolution?
            #screen = glut.screen((240, 320))
            screen = glut.screen((136, 240))
            #screen = glut.screen((48, 84))
            #screen = glut.screen((96, 168))

            from OpenGL.GLUT import glutKeyboardFunc, glutKeyboardUpFunc
            from OpenGL.GLUT import glutSpecialFunc, glutSpecialUpFunc

            glutKeyboardFunc(self.glutkeydown)
            glutKeyboardUpFunc(self.glutkeyup)
            glutSpecialFunc(self.glutspecialdown)
            glutSpecialUpFunc(self.glutspecialup)
            self.glutkeytime = False
            #        glutIgnoreKeyRepeat(True)
        elif driver == 'framebuffer':
            print('using framebuffer')
            screen = ugfx.screen("/dev/fb0")
            if screen.width > 480:
                print('warning huge width')
                #screen.width = 480
                #screen.height= min(screen.height, 640)

        if screen:
            self.bw = 1 if screen.width < 120 else False
            self.mag = 1

            if not self.surface:
                w, h = screen.width, screen.height
                self.surface = ugfx.surface(w, h, screen.bypp, None)

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

                self.invsurface = ugfx.surface(self.surface)
        else:
            self.surface = None

        self.lastframetime = 0
        self.screen = screen

        set_language(self.config['language'])
        self.client = False
        self.connect()

        self.menu = False
        self.page = connecting(self)
        self.need_refresh = True

        self.keypad = []
        for i in range(NUM_KEYS):
            self.keypad.append(Key())

        self.blink = black, white  # two cursor states
        self.data_update = False
Exemple #12
0
    def __init__(self, config):
        if config:
            self.config = config['lcd']
        else:
            self.config = {}
        self.pipe = False
        self.poller = False
        self.voltage = False

        default = {
            'contrast': 60,
            'invert': False,
            'backlight': 20,
            'hue': 214,
            'flip': False,
            'language': 'en',
            'bigstep': 10,
            'smallstep': 1,
            'buzzer': 2
        }

        for name in default:
            if not name in self.config:
                self.config[name] = default[name]

        global driver
        # set the driver to the one read from hat eeprom, or specified in hat.conf
        if config and 'hat' in config:
            if driver == 'default':
                driver = config['hat']['lcd']['driver']
            self.host = config['host']
        else:
            self.host = False

        self.battery_voltage = 0
        use_tft = True if micropython else False
        self.keypress = False

        use_glut = not use_tft and 'DISPLAY' in os.environ
        self.surface = None

        self.use_glut = False
        print('lcd driver', driver, use_tft, use_glut)
        if driver == 'none':
            page = None
            screen = None
            self.bw = None
        elif driver == 'tft' or (driver == 'default' and use_tft):
            import gc
            if gc.mem_free() > 1e6:  # larger ttgo display
                screen = ugfx.surface(240, 320, 1)
            else:
                screen = ugfx.surface(136, 240, 1)
            self.surface = screen
        elif driver == 'nokia5110' or (driver == 'default' and not use_glut):
            screen = ugfx.spiscreen(0)
        elif driver == 'jlx12864':
            screen = ugfx.spiscreen(1)
        elif driver == 'glut' or (driver == 'default' and use_glut):
            self.use_glut = True
            print('using glut')
            import glut
            # emulate which screen resolution?
            #screen = glut.screen((240, 320))
            screen = glut.screen((136, 240))
            #screen = glut.screen((48, 84))
            #screen = glut.screen((96, 168))

            from OpenGL.GLUT import glutKeyboardFunc, glutKeyboardUpFunc
            from OpenGL.GLUT import glutSpecialFunc, glutSpecialUpFunc

            glutKeyboardFunc(self.glutkeydown)
            glutKeyboardUpFunc(self.glutkeyup)
            glutSpecialFunc(self.glutspecialdown)
            glutSpecialUpFunc(self.glutspecialup)
            self.glutkeytime = False
            #        glutIgnoreKeyRepeat(True)
        elif driver == 'framebuffer':
            print('using framebuffer')
            screen = ugfx.screen("/dev/fb0")
            if screen.width > 480:
                print('warning huge width')
                #screen.width = 480
                #screen.height= min(screen.height, 640)

        if screen:
            self.bw = 1 if screen.width < 120 else False
            self.mag = 1

            if not self.surface:
                w, h = screen.width, screen.height
                self.surface = ugfx.surface(w, h, screen.bypp, None)

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

                self.invsurface = ugfx.surface(self.surface)
        else:
            self.surface = None

        self.screen = screen

        set_language(self.config['language'])
        self.client = False
        self.connect()

        self.menu = False
        self.page = connecting(self)
        self.need_refresh = True

        self.keypad = []
        for i in range(NUM_KEYS):
            self.keypad.append(Key())

        self.blink = black, white  # two cursor states
        self.data_update = False
Exemple #13
0
    def __init__(self):

        print(str(bool(glutInit)))
        print("hello and weolcome")
        print(
            "if you see an error next try the unofficial binaries of pyopengl")

        print("initializing glut etc")
        glutInit(sys.argv)
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH)
        glutInitWindowSize(640, 480)
        glutCreateWindow(name)

        print("set blend function")
        glBlendFunc(GL_SRC_ALPHA, GL_ONE)

        print("set colours and lights")
        glClearColor(0., 0., 0., 1.)
        glShadeModel(GL_SMOOTH)
        glEnable(GL_CULL_FACE)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_LIGHTING)

        print("set light 1")
        lightZeroPosition = [10., 4., 10., 1.]
        lightZeroColor = [0.9, 1.0, 0.9, 1.0]  #green tinged
        glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor)
        glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.2)
        glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05)
        glEnable(GL_LIGHT0)

        print("set light 2")
        lightZeroPosition2 = [-10., -4., 10., 1.]
        lightZeroColor2 = [1.0, 0.9, 0.9, 1.0]  #green tinged
        glLightfv(GL_LIGHT1, GL_POSITION, lightZeroPosition2)
        glLightfv(GL_LIGHT1, GL_DIFFUSE, lightZeroColor2)
        glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.2)
        glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.05)
        glEnable(GL_LIGHT1)

        #initialization of letters
        print("initialzing letters")
        self.letters = Letters.Letters()

        #for game models
        print("making model lists")
        MakeLists()

        print("ignore key repeat")
        glutIgnoreKeyRepeat(1)

        print("attach glut events to functions")
        glutSpecialFunc(self.keydownevent)
        glutSpecialUpFunc(self.keyupevent)
        glutReshapeFunc(self.reshape)

        glutKeyboardFunc(self.keydownevent)
        glutKeyboardUpFunc(self.keyupevent)
        glutDisplayFunc(self.display)
        #glutIdleFunc(self.display)

        print("initial projection")
        glMatrixMode(GL_PROJECTION)
        gluPerspective(60.0, 640.0 / 480., 1., 50.)
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()

        print("generating level")
        self.level = generateLevel(0)

        print("keys set up")
        self.initkey("zxdcfvqaopm")
        self.animate()

        print("about to loop...")
        glutMainLoop()

        return
Exemple #14
0
    def __init__(self, hat):
        self.hat = hat
        self.config = hat.config['lcd']
        default = {
            'contrast': 60,
            'invert': False,
            'backlight': 200,
            'flip': False,
            'language': 'en',
            'bigstep': 10,
            'smallstep': 1,
            'remote': False
        }

        for name in default:
            if not name in self.config:
                self.config[name] = default[name]

        # set the driver to the one from hat eeprom
        driver = 'default'
        if self.hat.hatconfig:
            driver = self.hat.hatconfig['lcd']['driver']

        for pdriver in [
                'nokia5110', 'jlx12864', 'glut', 'framebuffer', 'none'
        ]:
            if pdriver in sys.argv:
                sys.argv.remove(pdriver)
                driver = pdriver
                break

        print('Using driver', driver)

        use_glut = 'DISPLAY' in os.environ
        self.use_glut = False
        if driver == 'none':
            screen = None
        elif driver == 'nokia5110' or (driver == 'default' and not use_glut):
            screen = ugfx.spiscreen(0)
        elif driver == 'jlx12864':
            screen = ugfx.spiscreen(1)
        elif driver == 'glut' or (driver == 'default' and use_glut):
            self.use_glut = True
            print('using glut')
            import glut
            #screen = glut.screen((120, 210))
            #screen = glut.screen((64, 128))
            screen = glut.screen((48, 84))
            #screen = glut.screen((96, 168))

            from OpenGL.GLUT import glutKeyboardFunc, glutKeyboardUpFunc
            from OpenGL.GLUT import glutSpecialFunc, glutSpecialUpFunc

            glutKeyboardFunc(self.glutkeydown)
            glutKeyboardUpFunc(self.glutkeyup)
            glutSpecialFunc(self.glutspecialdown)
            glutSpecialUpFunc(self.glutspecialup)
#        glutIgnoreKeyRepeat(True)
        elif driver == 'framebuffer':
            print('using framebuffer')
            screen = ugfx.screen("/dev/fb0")
            if screen.width > 480:
                screen.width = 480
                screen.height = min(screen.height, 640)

        if screen:
            w, h = screen.width, screen.height
            mul = int(math.ceil(w / 48.0))

            self.bw = 1 if w < 256 else False

            width = min(w, 48 * mul)
            self.surface = ugfx.surface(width, int(width * h / w), screen.bypp,
                                        None)

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

            self.invsurface = ugfx.surface(self.surface)

            self.frameperiod = .25  # 4 frames a second possible
            self.lastframetime = 0
        else:
            self.surface = None
            self.frameperiod = 1

        self.screen = screen

        self.set_language(self.config['language'])
        self.range_edit = False

        self.modes = {
            'compass': self.have_compass,
            'gps': self.have_gps,
            'wind': self.have_wind,
            'true wind': self.have_true_wind
        }

        self.modes_list = ['compass', 'gps', 'wind', 'true wind']  # in order

        self.watchlist = [
            'ap.enabled', 'ap.mode', 'ap.pilot', 'ap.heading_command',
            'gps.source', 'wind.source', 'servo.controller', 'servo.flags',
            'imu.compass.calibration', 'imu.compass.calibration.sigmapoints',
            'imu.compass.calibration.locked', 'imu.alignmentQ',
            'rudder.calibration_state'
        ]
        self.initial_gets = [
            'servo.speed.min', 'servo.speed.max', 'servo.max_current',
            'servo.period', 'imu.alignmentCounter'
        ]

        self.create_mainmenu()

        self.display_page = self.display_control
        self.connecting_dots = 0

        self.keypad = [False, False, False, False, False, False, False, False]
        self.keypadup = list(self.keypad)

        self.blink = black, white
        self.control = False  # used to keep track of what is drawn on screen to avoid redrawing it
        self.wifi = False
Exemple #15
0
 def __init__(self, root_layout, hotkeys, events):
     super(EventManager, self).__init__(root_layout, hotkeys, events)
     
     glutKeyboardFunc(self.key_pressed)
     glutKeyboardUpFunc(self.key_released)