Example #1
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.)
Example #2
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")
Example #3
0
    def create_window(self, params):
        if self.__glut_window is None:
            # init GLUT !
            pymt_logger.debug('WinGlut: GLUT initialization')
            glutInit('')
            if 'PYMT_GLUT_UNITTEST' in os.environ:
                glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE)
            else:
                glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA
                                    | GLUT_DEPTH | GLUT_MULTISAMPLE
                                    | GLUT_STENCIL | GLUT_ACCUM)

            # create the window
            self.__glut_window = glutCreateWindow('pymt')

        # register all callbcaks
        glutReshapeFunc(self._glut_reshape)
        glutMouseFunc(self._glut_mouse)
        glutMotionFunc(self._glut_mouse_motion)
        glutKeyboardFunc(self._glut_keyboard)

        # update window size
        glutShowWindow()
        self.size = params['width'], params['height']
        if params['fullscreen']:
            pymt_logger.debug('WinGlut: Set window to fullscreen mode')
            glutFullScreen()

        super(MTWindowGlut, self).create_window(params)
Example #4
0
    def create_window(self, params):
        if self.__glut_window is None:
            # init GLUT !
            pymt_logger.debug('WinGlut: GLUT initialization')
            glutInit('')
            glutInitDisplayMode(
                GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH |
                GLUT_MULTISAMPLE | GLUT_STENCIL | GLUT_ACCUM)

            # create the window
            self.__glut_window = glutCreateWindow('pymt')

        # register all callbcaks
        glutReshapeFunc(self._glut_reshape)
        glutMouseFunc(self._glut_mouse)
        glutMotionFunc(self._glut_mouse_motion)
        glutKeyboardFunc(self._glut_keyboard)

        # update window size
        glutShowWindow()
        self.size = params['width'], params['height']
        if params['fullscreen']:
            pymt_logger.debug('WinGlut: Set window to fullscreen mode')
            glutFullScreen()

        super(MTWindowGlut, self).create_window(params)
Example #5
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);
Example #6
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)
Example #7
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()
Example #8
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)
Example #9
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)
Example #10
0
    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)
Example #11
0
def main():
    glutInit(sys.argv)

    glutInitDisplayMode(GLUT_DOUBLE)

    glutInitWindowSize(800, 600)

    glutInitWindowPosition(100, 100)

    glutCreateWindow('Particle System')

    fountains = Context()

    glutDisplayFunc(fountains.display)

    glutReshapeFunc(fountains.reshape)

    glEnable(GL_POINT_SMOOTH)

    glutMainLoop()
Example #12
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)
Example #13
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)
Example #14
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)
Example #15
0
    def activate(self, width, height):
        glutInit(['mesh_viewer'])
        glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH)
        glutInitWindowSize(width, height)
        glutInitWindowPosition(0, 0)
        self.root_window_id = glutCreateWindow(self.titlebar)
        glutDisplayFunc(self.on_draw)

        glutTimerFunc(100, self.checkQueue, 0)
        glutReshapeFunc(self.on_resize_window)

        glutKeyboardFunc(self.on_keypress)
        glutMouseFunc(self.on_click)
        glutMotionFunc(self.on_drag)

        # for r, lst in enumerate(self.mesh_viewers):
        #     for c, mv in enumerate(lst):
        #         mv.glut_window_id = glutCreateSubWindow(self.root_window_id, c*width/len(lst), r*height/len(self.mesh_viewers), width/len(lst), height/len(self.mesh_viewers))

        glutDisplayFunc(self.on_draw)
        self.init_opengl()

        glutMainLoop()  # won't return until process is killed
Example #16
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
Example #17
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()
Example #18
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()
Example #19
0
 def reshape_func(cls, callback):
     glutReshapeFunc(callback)