Ejemplo n.º 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.)
Ejemplo n.º 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")
Ejemplo n.º 3
0
def main():
    moons = [Moon(pos) for pos in d12_input]
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
    glutInitWindowSize(800, 800)
    glutInitWindowPosition(350, 200)
    glutCreateWindow('name')
    glClearColor(0., 0., 0., 1.)
    glShadeModel(GL_SMOOTH)
    glEnable(GL_CULL_FACE)
    glEnable(GL_DEPTH_TEST)
    glEnable(GL_LIGHTING)
    lightZeroPosition = [10., 4., 10., 1.]
    lightZeroColor = [0.8, 1.0, 0.8, 1.0]
    glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition)
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor)
    glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1)
    glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05)
    glEnable(GL_LIGHT0)
    glutDisplayFunc(lambda: display_scene(moons))
    glutTimerFunc(0, timer, 0)
    glMatrixMode(GL_PROJECTION)
    gluPerspective(40., 1., 1., 40.)
    glMatrixMode(GL_MODELVIEW)
    gluLookAt(0, -10, 10, 0, 0, 0, 0, 1, 0)
    glPushMatrix()
    glutMainLoop()
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 def init_interface(self):
     """ 初始化窗口并注册渲染函数 """
     glutInit()
     glutInitWindowSize(640, 480)
     glutCreateWindow("python-three-body by lovememo")
     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
     #注册窗口渲染函数
     glutDisplayFunc(self.render)
Ejemplo n.º 7
0
Archivo: View.py Proyecto: char-lie/mfm
    def __init_display(self):
        """Initialize the viewport with specified size."""
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA | GLUT_DEPTH)
        glutInitWindowSize(*self.__size)

        glutInitWindowPosition(0, 0)
        glutInit(sys.argv)
        glutCreateWindow(b"Morphable face model")
Ejemplo n.º 8
0
Archivo: View.py Proyecto: fossabot/mfm
    def __init_display(self):
        """Initialize the viewport with specified size."""
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA | GLUT_DEPTH)
        glutInitWindowSize(*self.__size)

        glutInitWindowPosition(0, 0)
        glutInit(sys.argv)
        glutCreateWindow(b"Morphable face model")
 def init_interface(self):
     """ 初始化窗口并注册渲染函数 """
     glutInit()
     glutInitWindowSize(640, 480)
     glutCreateWindow(b"3D Modeller")
     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
     #注册窗口渲染函数
     glutDisplayFunc(self.render)
Ejemplo n.º 10
0
    def init_interface(self):

        glutInit()
        glutInitWindowSize(640, 480)
        glutCreateWindow(b"3D Modeller")
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
        #register render function
        glutDisplayFunc(self.render)
Ejemplo n.º 11
0
 def init_interface(self):
     ''' 初始化窗口并注册 渲染函数 '''
     glutInit()
     glutInitWindowSize(640, 480)
     glutInitWindowPosition(200, 200)
     glutCreateWindow(b"3D Modeller")
     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
     # 注册窗口函数
     glutDisplayFunc(self.render)
Ejemplo n.º 12
0
    def init(self):
        glutInit(sys.argv)
        glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE)
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
        glutCreateWindow('Main Window')
        glutDisplayFunc(self.display)
        glutKeyboardFunc(self.keyboard)

        glutMainLoop()
Ejemplo n.º 13
0
def init():
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
    glutInitWindowSize(*WINDOW_SIZE)
    glutInitWindowPosition(50, 50)
    glutCreateWindow("PyGLSnake")
    glClearColor(
        *(ELEMENT_TYPES[0] + [255])
    )  #All our colors are 3-ints, this one needs alpha channel too so we just tack it on
    gluOrtho2D(0, WINDOW_SIZE[0], WINDOW_SIZE[1], 0)
Ejemplo n.º 14
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);
Ejemplo n.º 15
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)
Ejemplo n.º 16
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)
Ejemplo n.º 17
0
def glut_context():
    from OpenGL.GLUT import glutInit, glutCreateWindow, glutHideWindow
    glutInit()
    context = glutCreateWindow('Hidden window for OpenGL context')
    glutHideWindow()
    logger.debug('glut context created')
    yield context
Ejemplo n.º 18
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)
Ejemplo n.º 19
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)
Ejemplo n.º 20
0
    def create_display(width=WIDTH, height=HEIGHT) -> int:
        glutInit([])
        glutInitWindowSize(width, height)
        window_id = glutCreateWindow('Test window title')
        glutHideWindow()

        glViewport(0, 0, width, height)

        return window_id
Ejemplo n.º 21
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)
Ejemplo n.º 22
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()
Ejemplo n.º 23
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)
Ejemplo n.º 24
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()
Ejemplo n.º 25
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()
Ejemplo n.º 26
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)
Ejemplo n.º 27
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()
Ejemplo n.º 28
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()
Ejemplo n.º 29
0
def show_OpenGL(csg):
    if not _have_OpenGL:
        raise RuntimeError("PyOpenGL not available")
    renderable = TestRenderable(csg)

    glutInit()
    glutInitWindowSize(640, 480)
    renderable.win_id = glutCreateWindow("CSG Test")
    glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION)
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA)
    glutDisplayFunc(renderable.display)
    glutKeyboardFunc(renderable.keypress)
    glutSpecialFunc(renderable.special_keypress)

    renderable.init()

    glutMainLoop()
Ejemplo n.º 30
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)
Ejemplo n.º 31
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)
Ejemplo n.º 32
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
Ejemplo n.º 33
0
    glBegin(GL_LINE_LOOP)
    glVertex2iv(p1)
    glVertex2iv(p2)
    glVertex2iv(p3)
    glVertex2iv(p4)
    glVertex2iv(p5)
    glEnd()

    glBegin(GL_POLYGON)
    glVertex2i(50, 50)
    glVertex2i(75, 25)
    glVertex2i(125, 25)
    glVertex2i(150, 50)
    glVertex2i(125, 75)
    glVertex2i(75, 75)
    glEnd()

    glFlush()


if __name__ == '__main__':
    glutInit()
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
    glutInitWindowPosition(50, 100)
    glutInitWindowSize(400, 300)
    glutCreateWindow("OpenGL")

    init()
    glutDisplayFunc(plot_func)
    glutMainLoop()
Ejemplo n.º 34
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()
Ejemplo n.º 35
0
import struct
import sys

import ModernGL
from OpenGL.GLUT import (
    GLUT_DEPTH, GLUT_DOUBLE, GLUT_ELAPSED_TIME, GLUT_RGB, GLUT_WINDOW_HEIGHT, GLUT_WINDOW_WIDTH, glutCreateWindow,
    glutDisplayFunc, glutGet, glutIdleFunc, glutInit, glutInitDisplayMode, glutInitWindowSize, glutMainLoop,
    glutSwapBuffers
)

glutInit(sys.argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
glutInitWindowSize(800, 600)
glutCreateWindow(b'Uniforms and Attributes')

ctx = ModernGL.create_context()

prog = ctx.program(
    ctx.vertex_shader('''
        #version 330

        in vec2 in_vert;
        in vec3 in_color;

        out vec3 v_color;

        uniform vec2 Scale;
        uniform float Rotation;

        void main() {
            v_color = in_color;
Ejemplo n.º 36
0
import struct
import sys

import ModernGL
from OpenGL.GLUT import (
    GLUT_DEPTH, GLUT_DOUBLE, GLUT_RGB, glutCreateWindow, glutDisplayFunc, glutIdleFunc, glutInit, glutInitDisplayMode,
    glutInitWindowSize, glutMainLoop, glutSwapBuffers
)
from pyrr import Matrix44

width, height = 1280, 720

glutInit(sys.argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
glutInitWindowSize(width, height)
glutCreateWindow(b'')

ctx = ModernGL.create_context()

prog = ctx.program(
    ctx.vertex_shader('''
        #version 330

        uniform mat4 Mvp;

        in vec3 in_vert;
        in vec3 in_color;

        out vec3 v_color;

        void main() {
Ejemplo n.º 37
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()
Ejemplo n.º 38
0
import struct
import sys

import ModernGL
from OpenGL.GLUT import (
    GLUT_DEPTH, GLUT_DOUBLE, GLUT_RGB, glutCreateWindow, glutDisplayFunc, glutInit, glutInitDisplayMode,
    glutInitWindowSize, glutMainLoop, glutSwapBuffers
)

glutInit(sys.argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
glutInitWindowSize(800, 600)
glutCreateWindow(b'Hello World')

ctx = ModernGL.create_context()

prog = ctx.program(
    ctx.vertex_shader('''
        #version 330

        in vec2 vert;

        void main() {
            gl_Position = vec4(vert, 0.0, 1.0);
        }
    '''),
    ctx.fragment_shader('''
        #version 330

        out vec4 color;
Ejemplo n.º 39
0
import struct
import sys

import ModernGL
from OpenGL.GLUT import (
    GLUT_DEPTH, GLUT_DOUBLE, GLUT_RGB, glutCreateWindow, glutDisplayFunc, glutIdleFunc, glutInit, glutInitDisplayMode,
    glutInitWindowSize, glutMainLoop, glutSwapBuffers
)

width, height = 1280, 720

glutInit(sys.argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
glutInitWindowSize(width, height)
glutCreateWindow(b'')

ctx = ModernGL.create_context()

prog = ctx.program(
    ctx.vertex_shader('''
        #version 330

        uniform vec2 WindowSize;

        in vec2 in_vert;
        in vec3 in_color;

        out vec3 v_color;

        void main() {
            v_color = in_color;
Ejemplo n.º 40
0
import struct
import sys

import ModernGL
from OpenGL.GLUT import (GLUT_DEPTH, GLUT_DOUBLE, GLUT_RGB, glutCreateWindow,
                         glutDisplayFunc, glutInit, glutInitDisplayMode,
                         glutInitWindowSize, glutMainLoop, glutSwapBuffers)

glutInit(sys.argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
glutInitWindowSize(800, 600)
glutCreateWindow(b'Hello World')

ctx = ModernGL.create_context()

prog = ctx.program([
    ctx.vertex_shader('''
        #version 330

        in vec2 vert;

        void main() {
            gl_Position = vec4(vert, 0.0, 1.0);
        }
    '''),
    ctx.fragment_shader('''
        #version 330

        out vec4 color;

        void main() {
Ejemplo n.º 41
0
    glDrawArrays(GL_POINTS, 0, imgnp.shape[0] * imgnp.shape[1])

    glDisableVertexAttribArray(0)
    glDisableVertexAttribArray(1)
    glutSwapBuffers()


def moveMouse(x, y, z, w):
    pass


glutInit()
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH)
glutInitWindowSize(500, 500)
glutInitWindowPosition(100, 100)
wind = glutCreateWindow("OpenGL Window")
glPointSize(1)

vertshader = shaders.compileShader("""
    #version 330 core    
    layout (location = 0) in vec3 aPos;
    layout (location = 1) in vec3 aColor;

    uniform mat4 model;
    uniform mat4 view;
    uniform mat4 projection;

    out vec3 ourColor;

    void main()
    {
Ejemplo n.º 42
0
import os
import struct
import sys

import ModernGL
from OpenGL.GLUT import (
    GLUT_DEPTH, GLUT_DOUBLE, GLUT_ELAPSED_TIME, GLUT_RGB, GLUT_WINDOW_HEIGHT, GLUT_WINDOW_WIDTH, glutCreateWindow,
    glutDisplayFunc, glutGet, glutIdleFunc, glutInit, glutInitDisplayMode, glutInitWindowSize, glutMainLoop,
    glutSwapBuffers
)
from PIL import Image

glutInit(sys.argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
glutInitWindowSize(800, 600)
glutCreateWindow(b'Alpha Blending')

ctx = ModernGL.create_context()

prog = ctx.program(
    ctx.vertex_shader('''
        #version 330

        uniform vec2 Scale;
        uniform float Rotation;

        in vec2 in_vert;
        in vec2 in_text;

        out vec2 v_text;