Exemplo n.º 1
0
Arquivo: View.py Projeto: fossabot/mfm
    def __init__(self, size):
        """Initialize viewport with initial Face rotation and position."""
        self.__size = size

        self.__height, self.__width = self.__size
        self.__output_image = zeros(self.__width * self.__height * 4,
                                    dtype='f')

        self.__light = None
        self.__face = None
        self.__face_vertices = None
        self.__model_matrix = zeros((4, 4), dtype='f')
        self.__light_matrix = zeros((4, 4), dtype='f')

        self.__init_display()
        self.__enable_depth_test()

        glEnableClientState(GL_COLOR_ARRAY)
        glEnableClientState(GL_VERTEX_ARRAY)

        glClearColor(1., 1., 1., 0.)

        self.__sh = ShadersHelper(['face.vert', 'depth.vert'],
                                  ['face.frag', 'depth.frag'], 2, 1)

        glutDisplayFunc(self.__display)
        self.__callback = None
        self.__synchronous = False

        self.__sh.add_attribute(0, array([]), 'face_vertices')
        self.__sh.add_attribute(1, array([]), 'normal_vector')
        self.__sh.bind_buffer()
        self.__sh.use_shaders()
        self.__sh.link_texture('depth_map', 0)
        self.__sh.bind_depth_texture(self.__size)
Exemplo n.º 2
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)
Exemplo n.º 3
0
    def __init__(self, size):
        """Initialize viewport with initial Face rotation and position."""
        self.__size = size

        self.__height, self.__width = self.__size
        self.__output_image = zeros(self.__width * self.__height * 4,
                                    dtype='f')

        self.__light = None
        self.__face = None
        self.__model_matrix = zeros((4, 4), dtype='f')
        self.__light_matrix = zeros((4, 4), dtype='f')

        self.__init_display()
        self.__enable_depth_test()

        glEnableClientState(GL_COLOR_ARRAY)
        glEnableClientState(GL_VERTEX_ARRAY)

        glClearColor(1., 1., 1., 0.)

        self.__sh = ShadersHelper(['face.vert', 'depth.vert'],
                                  ['face.frag', 'depth.frag'], 1, 2)

        glutDisplayFunc(self.__display)
        self.__callback = None

        self.__sh.add_attribute(0, self.__mean_face, 'mean_position')
        self.__sh.bind_buffer()
        self.__sh.use_shaders()
        self.__sh.link_texture('principal_components', 0)
        self.__sh.link_texture('depth_map', 1)
        self.__bind_pca_texture()
        self.__sh.bind_depth_texture(self.__size)
Exemplo n.º 4
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")
Exemplo n.º 5
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.)
Exemplo n.º 6
0
Arquivo: View.py Projeto: char-lie/mfm
    def __init__(self, size):
        """Initialize viewport with initial Face rotation and position."""
        self.__size = size

        self.__height, self.__width = self.__size
        self.__output_image = zeros(self.__width * self.__height * 4,
                                    dtype='f')

        self.__light = None
        self.__face = None
        self.__face_vertices = None
        self.__model_matrix = zeros((4, 4), dtype='f')
        self.__light_matrix = zeros((4, 4), dtype='f')

        self.__init_display()
        self.__enable_depth_test()

        glEnableClientState(GL_COLOR_ARRAY)
        glEnableClientState(GL_VERTEX_ARRAY)

        glClearColor(1., 1., 1., 0.)

        self.__sh = ShadersHelper(['face.vert', 'depth.vert'],
                                  ['face.frag', 'depth.frag'], 2, 1)

        glutDisplayFunc(self.__display)
        self.__callback = None
        self.__synchronous = False

        self.__sh.add_attribute(0, array([]), 'face_vertices')
        self.__sh.add_attribute(1, array([]), 'normal_vector')
        self.__sh.bind_buffer()
        self.__sh.use_shaders()
        self.__sh.link_texture('depth_map', 0)
        self.__sh.bind_depth_texture(self.__size)
Exemplo n.º 7
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)
Exemplo n.º 8
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()
Exemplo n.º 9
0
 def init_interface(self):
     """ 初始化窗口并注册渲染函数 """
     glutInit()
     glutInitWindowSize(640, 480)
     glutCreateWindow("python-three-body by lovememo")
     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
     #注册窗口渲染函数
     glutDisplayFunc(self.render)
 def init_interface(self):
     """ 初始化窗口并注册渲染函数 """
     glutInit()
     glutInitWindowSize(640, 480)
     glutCreateWindow(b"3D Modeller")
     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
     #注册窗口渲染函数
     glutDisplayFunc(self.render)
Exemplo n.º 11
0
    def init_interface(self):

        glutInit()
        glutInitWindowSize(640, 480)
        glutCreateWindow(b"3D Modeller")
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
        #register render function
        glutDisplayFunc(self.render)
Exemplo n.º 12
0
 def init_interface(self):
     ''' 初始化窗口并注册 渲染函数 '''
     glutInit()
     glutInitWindowSize(640, 480)
     glutInitWindowPosition(200, 200)
     glutCreateWindow(b"3D Modeller")
     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
     # 注册窗口函数
     glutDisplayFunc(self.render)
Exemplo n.º 13
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()
Exemplo n.º 14
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()
Exemplo n.º 15
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()
Exemplo n.º 16
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()
Exemplo n.º 17
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);
Exemplo n.º 18
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)
Exemplo n.º 19
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()
Exemplo n.º 20
0
def main():
    #Load up the local settings
    game_settings = load_settings()
    #Network starts first since it gives us many of the parameters we need to initialize our game grid.
    network = MasterNetworkMode(game_settings)
    network.startNetwork()

    #Client-side game related stuffs below
    #This function will wait until the network thread either connects or times out
    #This really shouldn't take more than a few hundred milliseconds at worst on a local connection

    game_grid_params = network.getParameters()
    if game_grid_params is None:  #YOU DUN GOOFED UP NOW
        print "Failed to initialize network thread. Quitting..."
        exit(1)
    '''
    if game_settings["net_mode"] == "ClientMode":
        print "Client recv params:"
        print game_grid_params
    '''

    #Update our globals
    update_params(game_grid_params)
    #Get our player init data from the client thread.
    init_player_data = network.getInitPlayerData()
    client_connection_id = network.getConnectionID()
    #initilize our game grid and SnakeManager objects using the data gathered above.
    snakepit = SnakeManager(client_connection_id, init_player_data)
    Game_Grid = Grid(snakepit, game_grid_params["GRID_SIDE_SIZE_PX"],
                     game_grid_params["WINDOW_SIZE"])

    #Update our network side with the SnakeManager and Grid references
    network.setSnakeReference(snakepit)
    network.setGridReference(Game_Grid)

    #class to handle the drawing of our various elements
    #This has turned into more of a driver class for everything.
    renderman = RenderManager(Game_Grid)

    #Gl/Glut stuffs below
    glinit("PyGLSnake-Multiplayer :: Connection ID: %s" % client_connection_id)
    glutSpecialFunc(snakepit.keypressCallbackGLUT)
    #glutDisplayFunc is the main callback function opengl calls when GLUT determines that the display must be redrawn
    glutDisplayFunc(renderman.render_all_shapes)

    glutTimerFunc(TICKRATE_MS, renderman.calc_movement_all_shapes, 0)

    #Might want to get rid of this unless we plan to run it through the komodo profiler
    glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION)
    #Start everything up
    glutMainLoop()
Exemplo n.º 21
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)
Exemplo n.º 22
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()
Exemplo n.º 23
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)
Exemplo n.º 24
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)
Exemplo n.º 25
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)
Exemplo 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)
Exemplo n.º 27
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()
Exemplo n.º 28
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)
Exemplo n.º 29
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
Exemplo n.º 30
0
    def mainloop(self):
        '''Main loop is done by GLUT itself.'''

        # callback for ticking
        def _glut_redisplay():
            evloop = getEventLoop()

            # hack, glut seem can't handle the leaving on the mainloop
            # so... leave with sys.exit() :[
            try:
                evloop.idle()
            except KeyboardInterrupt:
                evloop.quit = True
            if evloop.quit:
                sys.exit(0)

            glutPostRedisplay()

        # install handler
        glutDisplayFunc(_glut_redisplay)

        # run main loop
        glutMainLoop()
Exemplo n.º 31
0
    def mainloop(self):
        '''Main loop is done by GLUT itself.'''

        # callback for ticking
        def _glut_redisplay():
            evloop = getEventLoop()

            # hack, glut seem can't handle the leaving on the mainloop
            # so... leave with sys.exit() :[
            try:
                evloop.idle()
            except KeyboardInterrupt:
                evloop.quit = True
            if evloop.quit:
                sys.exit(0)

            glutPostRedisplay()

        # install handler
        glutDisplayFunc(_glut_redisplay)

        # run main loop
        glutMainLoop()
Exemplo n.º 32
0
def main():
    init()

    Game_Grid = Grid()

    snake = Snake(Game_Grid)

    #I didnt really want to use GLUT much but eh, I will work this out with standard libraries  later
    glutSpecialFunc(snake.keypress_callback_GLUT)

    renderman = RenderManager(Game_Grid, snake)
    glutDisplayFunc(renderman.render_all_shapes)

    glutTimerFunc(TICKRATE_MS, renderman.calc_movement_all_shapes, 0)

    #Tell Glut to continue execution after we exit the main loop
    #Komodo's code profiler will not return any results unless you shut down just right
    glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION)

    #set vsync
    swap_control.wglSwapIntervalEXT(VSYNC)

    #Start everything up
    glutMainLoop()
Exemplo 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()
Exemplo n.º 34
0
shaders.glUseProgram(shaderProg)

points = vbo.VBO(data=imgnp,
                 usage="GL_DYNAMIC_DRAW",
                 target='GL_ARRAY_BUFFER',
                 size=None)
points.bind()

modelmat = glGetUniformLocation(shaderProg, 'model')
viewmat = glGetUniformLocation(shaderProg, 'view')
projectionmat = glGetUniformLocation(shaderProg, 'projection')

glPushMatrix()
glRotatef(-90, 0, 0, 1)

scal = 0.01
glTranslatef(-0.5, -0.5, 0)
glScalef(1 / imgnp.shape[0], 1 / imgnp.shape[1], 1)
model2 = glGetDoublev(GL_MODELVIEW_MATRIX)
glPopMatrix()
# print(model2)

glUniformMatrix4fv(modelmat, 1, GL_FALSE, model2)

glutDisplayFunc(draw_points)

# glutInitWindowPosition(600, 100)
# wind2 = glutCreateWindow("OpenGL Window2")
# glutMouseFunc(moveMouse)
glutMainLoop()
Exemplo n.º 35
0
            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()
Exemplo n.º 36
0
    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()
Exemplo n.º 37
0
    return x_lst, y_lst


def plot():
    glClear(GL_COLOR_BUFFER_BIT)

    glPointSize(3.0)
    glColor3f(1.0, 0.0, 0.0)

    glBegin(GL_POINTS)

    x_lst, y_lst = circle(0, 0, 1, 100)
    for x, y in zip(x_lst, y_lst):
        glVertex2f(x, y)

    glEnd()

    glFlush()


if __name__ == '__main__':
    glutInit()
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
    glutInitWindowPosition(100, 100)
    glutInitWindowSize(900, 600)
    glutCreateWindow(b"Funciont Plotter")
    glutDisplayFunc(plot)
    glClearColor(1.0, 1.0, 1.0, 1.0)
    gluOrtho2D(-5.0, 5.0, -5.0, 5.0)
    glutMainLoop()
Exemplo n.º 38
0
 def display_func(cls, callback):
     glutDisplayFunc(callback)
Exemplo n.º 39
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