Esempio n. 1
0
def main():
    global wmngr_glut

    ###################
    # GLUT Window Initialization
    glut.glutInit()
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB
                             | glut.GLUT_DEPTH)  # zBuffer
    glut.glutInitWindowSize(600, 600)
    glut.glutInitWindowPosition(100, 100)
    glut.glutCreateWindow("Simple GLUT")

    # Register callbacks
    glut.glutReshapeFunc(reshape)
    glut.glutDisplayFunc(display)
    glut.glutMouseFunc(mouse)
    glut.glutMotionFunc(motion)
    glut.glutKeyboardFunc(keyboard)
    glut.glutSpecialFunc(special)
    glut.glutIdleFunc(idle)

    wmngr_glut = dfm2.gl.glut.WindowManagerGLUT(0.3)

    dfm2.gl.setSomeLighting()

    ####
    # Turn the flow of control over to GLUT
    glut.glutMainLoop()
Esempio n. 2
0
 def __init__(self, width=640, height=480, fullscreen=False, aspect=None):
     self.gl = gl
     glut.glutInit(sys.argv)
     glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB
                              | glut.GLUT_DEPTH)
     glut.glutInitWindowPosition(0, 0)
     glut.glutCreateWindow(b"BlitzLoop Karaoke")
     if not fullscreen:
         glut.glutReshapeWindow(width, height)
     else:
         glut.glutSetCursor(glut.GLUT_CURSOR_NONE)
     BaseDisplay.__init__(self, width, height, fullscreen, aspect)
     self._on_reshape(width, height)
     if fullscreen:
         self.saved_size = (width, height)
         glut.glutFullScreen()
     glut.glutDisplayFunc(self._render)
     glut.glutIdleFunc(self._render)
     glut.glutReshapeFunc(self._on_reshape)
     glut.glutKeyboardFunc(self._on_keyboard)
     glut.glutSpecialFunc(self._on_keyboard)
     try:
         glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE,
                            glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS)
         print("Using FreeGLUT mainloop return feature")
     except:
         pass
     self._initialize()
Esempio n. 3
0
 def __init__(self, width=640, height=480, fullscreen=False, aspect=None):
     self.gl = gl
     glut.glutInit(sys.argv)
     glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH)
     glut.glutInitWindowPosition(0, 0)
     glut.glutCreateWindow(b"BlitzLoop Karaoke")
     if not fullscreen:
         glut.glutReshapeWindow(width, height)
     else:
         glut.glutSetCursor(glut.GLUT_CURSOR_NONE)
     BaseDisplay.__init__(self, width, height, fullscreen, aspect)
     self._on_reshape(width, height)
     if fullscreen:
         self.saved_size = (width, height)
         glut.glutFullScreen()
     glut.glutDisplayFunc(self._render)
     glut.glutIdleFunc(self._render)
     glut.glutReshapeFunc(self._on_reshape)
     glut.glutKeyboardFunc(self._on_keyboard)
     glut.glutSpecialFunc(self._on_keyboard)
     try:
         glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE, glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS)
         print("Using FreeGLUT mainloop return feature")
     except:
         pass
     self._initialize()
Esempio n. 4
0
def main():
    GLUT.glutInit(sys.argv)
    GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH)
    GLUT.glutInitWindowSize(320, 240)
    global window
    window = GLUT.glutCreateWindow("Babal")

    GLUT.glutDisplayFunc(display_cb)
    GLUT.glutVisibilityFunc(visibility_cb)
    GLUT.glutReshapeFunc(reshape_cb)

    GLUT.glutIgnoreKeyRepeat(1)
    GLUT.glutKeyboardFunc(keyboard_cb)
    GLUT.glutKeyboardUpFunc(keyboard_up_cb)
    GLUT.glutSpecialFunc(special_cb)
    GLUT.glutSpecialUpFunc(special_up_cb)
    GLUT.glutJoystickFunc(joystick_cb, 0)

    map_file = None
    if len(sys.argv) > 1:
        map_file = open(sys.argv[1])

    global game
    game = Game(map_file)
    gl_draw.init(GL, GLU, game)

    # reshape_cb gets called when window is made visible

    GLUT.glutMainLoop()
Esempio n. 5
0
File: _glut.py Progetto: kif/vispy
    def __init__(self, *args, **kwargs):
        BaseCanvasBackend.__init__(self)
        title, size, show, position = self._process_backend_kwargs(kwargs)
        glut.glutInitWindowSize(size[0], size[1])
        self._id = glut.glutCreateWindow(title.encode('ASCII'))
        if not self._id:
            raise RuntimeError('could not create window')
        glut.glutSetWindow(self._id)
        _VP_GLUT_ALL_WINDOWS.append(self)

        # Cache of modifiers so we can send modifiers along with mouse motion
        self._modifiers_cache = ()
        self._closed = False  # Keep track whether the widget is closed

        # Register callbacks
        glut.glutDisplayFunc(self.on_draw)
        glut.glutReshapeFunc(self.on_resize)
        # glut.glutVisibilityFunc(self.on_show)
        glut.glutKeyboardFunc(self.on_key_press)
        glut.glutSpecialFunc(self.on_key_press)
        glut.glutKeyboardUpFunc(self.on_key_release)
        glut.glutMouseFunc(self.on_mouse_action)
        glut.glutMotionFunc(self.on_mouse_motion)
        glut.glutPassiveMotionFunc(self.on_mouse_motion)
        _set_close_fun(self._id, self.on_close)
        self._vispy_canvas_ = None
        if position is not None:
            self._vispy_set_position(*position)
        if not show:
            glut.glutHideWindow()
Esempio n. 6
0
    def run(self):
        GLUT.glutInit()
        GLUT.glutSetOption(GLUT.GLUT_MULTISAMPLE, 4)
        GLUT.glutInitDisplayMode(GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH
                                 | GLUT.GLUT_MULTISAMPLE)
        self.width = 1200
        self.height = 720

        GLUT.glutInitWindowSize(self.width, self.height)
        GLUT.glutInitWindowPosition(100, 100)

        self.window = GLUT.glutCreateWindow(self.title)

        self.init_program()

        self.clear()
        self.show_loading_screen()
        self.init_line_buffer()
        self.load_line_buffer()

        GLUT.glutDisplayFunc(self.display)
        GLUT.glutIdleFunc(self.idle)
        GLUT.glutReshapeFunc(self.reshape)
        GLUT.glutKeyboardFunc(self.keyboard)
        GLUT.glutSpecialFunc(self.special)
        GLUT.glutMouseFunc(self.mouse)
        GLUT.glutMotionFunc(self.motion)
        GLUT.glutPassiveMotionFunc(self.motion)

        GLUT.glutMainLoop()
Esempio n. 7
0
    def __init__( self, width=256, height=256, title=None, visible=True, aspect=None,
                  decoration=True, fullscreen=False, config=None, context=None, color=(0,0,0,1), vsync=False):

        if vsync:
            log.warn('vsync not implemented for osxglut backend')

        if len(__windows__) > 0:
            log.critical(
                """OSXGLUT backend is unstable with more than one window.\n"""
                """Exiting...""")
            sys.exit(0)

        window.Window.__init__(self, width=width,
                                     height=height,
                                     title=title,
                                     visible=visible,
                                     aspect=aspect,
                                     decoration=decoration,
                                     fullscreen=fullscreen,
                                     config=config,
                                     context=context,
                                     color=color)

        if config is None:
            config = configuration.Configuration()
        set_configuration(config)

        self._native_window = glut.glutCreateWindow( self._title )
        if bool(glut.glutSetOption):
            glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE,
                               glut.GLUT_ACTION_CONTINUE_EXECUTION)
            glut.glutSetOption(glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS,
                               glut.GLUT_ACTION_CONTINUE_EXECUTION)
        glut.glutWMCloseFunc( self._close )
        glut.glutDisplayFunc( self._display )
        glut.glutReshapeFunc( self._reshape )
        glut.glutKeyboardFunc( self._keyboard )
        glut.glutKeyboardUpFunc( self._keyboard_up )
        glut.glutMouseFunc( self._mouse )
        glut.glutMotionFunc( self._motion )
        glut.glutPassiveMotionFunc( self._passive_motion )
        glut.glutVisibilityFunc( self._visibility )
        glut.glutEntryFunc( self._entry )
        glut.glutSpecialFunc( self._special )
        glut.glutSpecialUpFunc( self._special_up )
        glut.glutReshapeWindow( self._width, self._height )
        if visible:
            glut.glutShowWindow()
        else:
            glut.glutHideWindow()

        # This ensures glutCheckLoop never blocks
        def on_idle(): pass
        glut.glutIdleFunc(on_idle)

        __windows__.append(self)
    def __glInit(self):
        self.initTime = time.time()
        glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB)
        glut.glutInitWindowSize(1000, 1000)
        glut.glutInitWindowPosition(50, 50)
        glut.glutInit([])
        glut.glutCreateWindow(b"OpenGL Fractal Renderer")

        self.gpu_vendor = gl_v1.glGetString(gl.GL_VENDOR).decode("ascii")
        self.gpu_model = gl_v1.glGetString(gl.GL_RENDERER).decode("ascii")
        self.gpu_attrib_count = gl.glGetInteger(gl.GL_MAX_VERTEX_ATTRIBS)

        print(f"Found {self.gpu_vendor} {self.gpu_model}")
        print(f"GPU supports {self.gpu_attrib_count} vertex attributes")

        self.shaderProgram = gl.glCreateProgram()
        self.shaderVertex = self.__glCreateShader(
            gl.GL_VERTEX_SHADER, """
        #version 410
        layout(location = 0) in vec4 vertexPosition;
        //[0] - centerX, [1] - centerY, [2] - scaleH, [3] - width / height
        layout(location = 1) in vec4 centerAndScale;
        out mat2 pos;
        void main() {
            gl_Position = vertexPosition;
            float x = centerAndScale[0] + vertexPosition[0] / 2.0
             * centerAndScale[2] * centerAndScale[3];
            float y = centerAndScale[1] + vertexPosition[1] / 2.0
             * centerAndScale[2] ;
            pos = mat2(x,y,-y,x);
        }
        """)

        self.shaderSourceGenerator = GLFractalSourceGenerator()
        self.shaderSourceGenerator.generateSource(self.fractal)
        self.shaderSource = self.shaderSourceGenerator.getOneSourceString()
        self.shaderFragment = self.__glCreateFragmentShader(self.shaderSource)
        self.shaderSourceGenerator.printSource()

        gl.glAttachShader(self.shaderProgram, self.shaderVertex)
        gl.glAttachShader(self.shaderProgram, self.shaderFragment)
        gl.glLinkProgram(self.shaderProgram)

        linkStatus = gl.glGetProgramiv(self.shaderProgram, gl.GL_LINK_STATUS)
        if linkStatus != gl.GL_TRUE:
            error = gl.glGetProgramInfoLog(self.shaderProgram).decode("ascii")
            raise GLShaderLinkError(error)

        gl.glUseProgram(self.shaderProgram)
        self.__glSetupVarloc()
        glut.glutSpecialFunc(self.__glutSpecialKeyHandler)
        glut.glutDisplayFunc(self.__glDraw)
        glut.glutIdleFunc(self.__glDraw)
        glut.glutMainLoop()
Esempio n. 9
0
 def on(self):
     glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB)
     glut.glutInitWindowSize(self.ww, self.hh)
     glut.glutInitWindowPosition(300, 100)
     glut.glutInit(sys.argv)
     glut.glutCreateWindow(b"PCViewer")
     glut.glutDisplayFunc(self.__draw__)
     gl.glEnable(gl.GL_DEPTH_TEST)
     glut.glutReshapeFunc(self.__reshape__)
     glut.glutSpecialFunc(self.__specialkeys__)
     glut.glutMainLoop()
Esempio n. 10
0
    def __init__(self,
                 width=256,
                 height=256,
                 title=None,
                 visible=True,
                 decoration=True,
                 fullscreen=False,
                 config=None,
                 context=None):

        if len(__windows__) > 0:
            log.critical(
                """OSXGLUT backend is unstable with more than one window.\n"""
                """Exiting...""")
            sys.exit(0)

        window.Window.__init__(self, width, height, title, visible, decoration,
                               fullscreen, config, context)

        if config is None:
            config = configuration.Configuration()
        set_configuration(config)

        self._native_window = glut.glutCreateWindow(self._title)
        if bool(glut.glutSetOption):
            glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE,
                               glut.GLUT_ACTION_CONTINUE_EXECUTION)
            glut.glutSetOption(glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS,
                               glut.GLUT_ACTION_CONTINUE_EXECUTION)
        glut.glutWMCloseFunc(self._close)
        glut.glutDisplayFunc(self._display)
        glut.glutReshapeFunc(self._reshape)
        glut.glutKeyboardFunc(self._keyboard)
        glut.glutKeyboardUpFunc(self._keyboard_up)
        glut.glutMouseFunc(self._mouse)
        glut.glutMotionFunc(self._motion)
        glut.glutPassiveMotionFunc(self._passive_motion)
        glut.glutVisibilityFunc(self._visibility)
        glut.glutEntryFunc(self._entry)
        glut.glutSpecialFunc(self._special)
        glut.glutSpecialUpFunc(self._special_up)
        glut.glutReshapeWindow(self._width, self._height)
        if visible:
            glut.glutShowWindow()
        else:
            glut.glutHideWindow()

        # This ensures glutCheckLoop never blocks
        def on_idle():
            pass

        glut.glutIdleFunc(on_idle)

        __windows__.append(self)
Esempio n. 11
0
    def __init__(self, *args, **kwargs):
        BaseCanvasBackend.__init__(self, *args)
        title, size, position, show, vsync, resize, dec, fs, parent, context, \
            = self._process_backend_kwargs(kwargs)
        self._initialized = False
        
        # Deal with context
        if not context.istaken:
            context.take('glut', self)
            _set_config(context.config)
        else:
            raise RuntimeError('Glut cannot share contexts.')
        
        glut.glutInitWindowSize(size[0], size[1])
        self._id = glut.glutCreateWindow(title.encode('ASCII'))
        if not self._id:
            raise RuntimeError('could not create window')
        glut.glutSetWindow(self._id)
        _VP_GLUT_ALL_WINDOWS.append(self)
        if fs is not False:
            self._fullscreen = True
            self._old_size = size
            if fs is not True:
                logger.warning('Cannot specify monitor for glut fullscreen, '
                               'using default')
            glut.glutFullScreen()
        else:
            self._fullscreen = False

        # Cache of modifiers so we can send modifiers along with mouse motion
        self._modifiers_cache = ()
        self._closed = False  # Keep track whether the widget is closed
        
        # Register callbacks
        glut.glutDisplayFunc(self.on_draw)
        glut.glutReshapeFunc(self.on_resize)
        # glut.glutVisibilityFunc(self.on_show)
        glut.glutKeyboardFunc(self.on_key_press)
        glut.glutSpecialFunc(self.on_key_press)
        glut.glutKeyboardUpFunc(self.on_key_release)
        glut.glutMouseFunc(self.on_mouse_action)
        glut.glutMotionFunc(self.on_mouse_motion)
        glut.glutPassiveMotionFunc(self.on_mouse_motion)
        _set_close_fun(self._id, self.on_close)
        if position is not None:
            self._vispy_set_position(*position)
        if not show:
            glut.glutHideWindow()
        
        # Init
        self._initialized = True
        self._vispy_set_current()
        self._vispy_canvas.events.initialize()
Esempio n. 12
0
    def attachGLUT(self):
        glut.glutMouseFunc(self.mouseInputHandler)
        glut.glutMouseWheelFunc(self.mouseWheelHandler)

        glut.glutMotionFunc(self.mouseMoveHandler)
        glut.glutPassiveMotionFunc(self.mouseMoveHandler)

        glut.glutKeyboardFunc(self.keyboardHandler)
        glut.glutKeyboardUpFunc(lambda *x:self.keyboardHandler(*x,isEnd=True))

        glut.glutSpecialFunc(self.specialKeyHandler)
        glut.glutSpecialUpFunc(lambda *x:self.specialKeyHandler(*x,isEnd=True))
Esempio n. 13
0
def main():
    GLUT.glutInit(argv)
    GLUT.glutInitDisplayMode(GLUT.GLUT_DOUBLE | GLUT.GLUT_RGBA
                             | GLUT.GLUT_DEPTH | GLUT.GLUT_MULTISAMPLE)

    # Creating a screen with good resolution proportions
    screen_width = GLUT.glutGet(GLUT.GLUT_SCREEN_WIDTH)
    screen_height = GLUT.glutGet(GLUT.GLUT_SCREEN_HEIGHT)

    window_width = round(2 * screen_width / 3)
    window_height = round(2 * screen_height / 3)

    GLUT.glutInitWindowSize(window_width, window_height)
    GLUT.glutInitWindowPosition(round((screen_width - window_width) / 2),
                                round((screen_height - window_height) / 2))
    GLUT.glutCreateWindow(window_name)

    # Reshape Function
    GLUT.glutReshapeFunc(reshape)

    # Drawing Function
    GLUT.glutDisplayFunc(draw)

    # Input Functions
    GLUT.glutSpecialFunc(special_key_pressed)
    GLUT.glutKeyboardFunc(key_pressed)
    GLUT.glutMouseFunc(mouse_click)
    GLUT.glutMotionFunc(mouse_move)

    #GL.glShadeModel(GL.GL_FLAT)
    GL.glShadeModel(GL.GL_SMOOTH)

    #First Material
    GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, materials[0][0])
    GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, materials[0][1])
    GL.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, materials[0][2])
    GL.glMaterialfv(GL.GL_FRONT, GL.GL_SHININESS, materials[0][3])

    light_position = (10, 0, 0)
    GL.glEnable(GL.GL_LIGHTING)
    GL.glEnable(GL.GL_LIGHT0)
    GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, light_position)

    GL.glEnable(GL.GL_MULTISAMPLE)
    GL.glEnable(GL.GL_DEPTH_TEST)

    GL.glClearColor(*background_color)

    # Pre-render camera positioning
    GLU.gluPerspective(45, window_width / window_height, 0.1, 50.0)

    GLUT.glutTimerFunc(50, timer, 1)
    GLUT.glutMainLoop()
Esempio n. 14
0
 def _glut_init(self):
     glut.glutInit(sys.argv)
     glut.glutInitDisplayMode(glut.GLUT_RGB | glut.GLUT_SINGLE)
     glut.glutInitWindowSize(self.window_size, self.window_size)
     glut.glutInitWindowPosition(0, 0)
     glut.glutCreateWindow(sys.argv[0])
     glut.glutDisplayFunc(self._display)
     glut.glutSpecialFunc(self._on_key_press)
     glut.glutMouseFunc(self._on_mouse_click)
     glut.glutMotionFunc(self._on_mouse_move)
     glut.glutReshapeFunc(self._on_window_resize)
     glut.glutIdleFunc(self._on_idle)
     glut.glutMainLoop()
Esempio n. 15
0
  def draw_loop(self,draw_func0):  

    # Register callbacks
    glut.glutReshapeFunc(self.reshape)
    glut.glutDisplayFunc(self.display)
    glut.glutMouseFunc(self.mouse)
    glut.glutMotionFunc(self.motion)
    glut.glutKeyboardFunc(self.keyboard)
    glut.glutSpecialFunc(self.special)
    glut.glutIdleFunc(self.idle)

    self.draw_func = draw_func0
    glut.glutMainLoop()
Esempio n. 16
0
    def __init__(self, width=None, height=None, caption=None, visible=True, fullscreen=False):

        event.EventDispatcher.__init__(self)

        self._event_queue = []
        if width and width > 0:
            self._width = width
        else:
            self._width = Window._default_width
        if height and height > 0:
            self._height = height
        else:
            self._height = Window._default_height
        if caption is None:
            caption = sys.argv[0]
        self._caption = caption

        self._saved_width  = self._width
        self._saved_height = self._height

        if _window is None:
            glut.glutInit(sys.argv)
            glut.glutInitDisplayMode(glut.GLUT_DOUBLE |
                                     glut.GLUT_RGBA   |
                                     glut.GLUT_DEPTH)
            self._window_id = glut.glutCreateWindow(self._caption)
        glut.glutDisplayFunc(self._display)
        glut.glutReshapeFunc(self._reshape)
        glut.glutKeyboardFunc(self._keyboard)
        glut.glutKeyboardUpFunc(self._keyboard_up)
        glut.glutMouseFunc(self._mouse)
        glut.glutMotionFunc(self._motion)
        glut.glutPassiveMotionFunc(self._passive_motion)
        glut.glutVisibilityFunc(self._visibility)
        glut.glutEntryFunc(self._entry)
        glut.glutSpecialFunc(self._special)
        glut.glutSpecialUpFunc(self._special_up)
        gl.glClearColor(0,0,0,0)
        self._visible = visible
        self._time = glut.glutGet(glut.GLUT_ELAPSED_TIME)
        if not visible:
            glut.glutHideWindow()
        else:
            glut.glutShowWindow()
        self.set_size(self._width, self._height)
        screen_width = glut.glutGet(glut.GLUT_SCREEN_WIDTH)
        screen_height= glut.glutGet(glut.GLUT_SCREEN_HEIGHT)
        glut.glutPositionWindow((screen_width-self._width)//2,
                                (screen_height-self._height)//2)
        self.fullscreen = fullscreen
Esempio n. 17
0
    def attachGLUT(self):
        glut.glutMouseFunc(self.mouseInputHandler)
        glut.glutMouseWheelFunc(self.mouseWheelHandler)

        glut.glutMotionFunc(self.mouseMoveHandler)
        glut.glutPassiveMotionFunc(self.mouseMoveHandler)

        glut.glutKeyboardFunc(self.keyboardHandler)
        glut.glutKeyboardUpFunc(
            lambda *x: self.keyboardHandler(*x, isEnd=True))

        glut.glutSpecialFunc(self.specialKeyHandler)
        glut.glutSpecialUpFunc(
            lambda *x: self.specialKeyHandler(*x, isEnd=True))
Esempio n. 18
0
    def __init__(self,*args,**kwargs):

        oglut.glutInit(sys.argv)
        oglut.glutInitDisplayMode(oglut.GLUT_RGBA | oglut.GLUT_DOUBLE | oglut.GLUT_DEPTH)
        oglut.glutInitWindowSize(800, 480)
        self.window = oglut.glutCreateWindow(b"window")
        oglut.glutDisplayFunc(self.display)
        #oglut.glutIdleFunc(self.display) 
        oglut.glutReshapeFunc(self.resize)  
        oglut.glutKeyboardFunc(self.on_keyboard)   
        oglut.glutSpecialFunc(self.on_special_key)  
        oglut.glutMouseFunc(self.on_mouse)
        oglut.glutMotionFunc(self.on_mousemove)
        self.controller = None
        self.update_if = oglut.glutPostRedisplay
Esempio n. 19
0
def main():
    print("-----------------------------------------------------------")
    print("Alternar entre Fill e Wireframe: 'v'")
    print("Modo Translação: 't'")
    print("\t →  : deslocamento positivo em X")
    print("\t ←  : deslocamento negativo em X")
    print("\t ↑  : deslocamento positivo em Y")
    print("\t ↓  : deslocamento negativo em Y")
    print("\t'a' : deslocamento positivo em Z")
    print("\t'd' : deslocamento negativo em Z")

    print("Modo Rotação: 'r'")
    print("\t ↑  : rotação positivo em X")
    print("\t ↓  : rotação negativo em X")
    print("\t →  : rotação positivo em Y")
    print("\t ←  : rotação negativo em Y")
    print("\t'a' : rotação positivo em Z")
    print("\t'd' : rotação negativo em Z")

    print("Modo Escala: 'e'")
    print("\t →  : fator positivo em X")
    print("\t ←  : fator negativo em X")
    print("\t ↑  : fator positivo em Y")
    print("\t ↓  : fator negativo em Y")
    print("\t'a' : fator positivo em Z")
    print("\t'd' : fator negativo em Z")
    print("-----------------------------------------------------------")

    glut.glutInit()
    glut.glutInitContextVersion(3, 3);
    glut.glutInitContextProfile(glut.GLUT_CORE_PROFILE);
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH)
    glut.glutInitWindowSize(win_width, win_height)
    glut.glutCreateWindow('Trabalho 2')

    # Init vertex data for the triangle.
    initData()

    # Create shaders.
    initShaders()

    glut.glutReshapeFunc(reshape)
    glut.glutDisplayFunc(display)
    glut.glutKeyboardFunc(keyboard)
    glut.glutIdleFunc(idle);
    glut.glutSpecialFunc(SpecialInput)

    glut.glutMainLoop()
Esempio n. 20
0
 def init_window(self):
     glut.glutInit(sys.argv)
     glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_ALPHA | glut.GLUT_DEPTH)
     glut.glutInitWindowPosition(
         (glut.glutGet(glut.GLUT_SCREEN_WIDTH) - self.window_width) // 2,
         (glut.glutGet(glut.GLUT_SCREEN_HEIGHT) - self.window_height) // 2,
     )
     glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE, glut.GLUT_ACTION_CONTINUE_EXECUTION)
     glut.glutInitWindowSize(self.window_width, self.window_height)
     self.window_handle = glut.glutCreateWindow(WINDOW_TITLE_PREFIX)
     glut.glutDisplayFunc(self.render_func)
     glut.glutReshapeFunc(self.resize_func)
     glut.glutMouseFunc(self.mouse)
     glut.glutMotionFunc(self.mouse_motion)
     glut.glutKeyboardFunc(self.keyboard)
     glut.glutSpecialFunc(self.keyboard_s)
Esempio n. 21
0
    def __init__(self, name='glut window', *args, **kwargs):
        BaseCanvasBackend.__init__(self)
        self._id = glut.glutCreateWindow(name)
        global ALL_WINDOWS
        ALL_WINDOWS.append(self)

        # Cache of modifiers so we can send modifiers along with mouse motion
        self._modifiers_cache = ()

        # Note: this seems to cause the canvas to ignore calls to show()
        # about half of the time.
        # glut.glutHideWindow()  # Start hidden, like the other backends

        # Register callbacks
        glut.glutDisplayFunc(self.on_draw)
        glut.glutReshapeFunc(self.on_resize)
        # glut.glutVisibilityFunc(self.on_show)
        glut.glutKeyboardFunc(self.on_key_press)
        glut.glutSpecialFunc(self.on_key_press)
        glut.glutKeyboardUpFunc(self.on_key_release)
        glut.glutMouseFunc(self.on_mouse_action)
        glut.glutMotionFunc(self.on_mouse_motion)
        glut.glutPassiveMotionFunc(self.on_mouse_motion)

        # Set close function. See issue #10. For some reason, the function
        # can still not exist even if we checked its boolean status.
        closeFuncSet = False
        if bool(glut.glutWMCloseFunc):  # OSX specific test
            try:
                glut.glutWMCloseFunc(self.on_close)
                closeFuncSet = True
            except OpenGL.error.NullFunctionError:
                pass
        if not closeFuncSet:
            try:
                glut.glutCloseFunc(self.on_close)
                closeFuncSet = True
            except OpenGL.error.NullFunctionError:
                pass

        # glut.glutFunc(self.on_)

        self._initialized = False

        # LC: I think initializing here makes it more consistent with other
        # backends
        glut.glutTimerFunc(0, self._emit_initialize, None)
def main():
    GLUT.glutInit(argv)
    GLUT.glutInitDisplayMode(GLUT.GLUT_DOUBLE | GLUT.GLUT_RGBA
                             | GLUT.GLUT_DEPTH | GLUT.GLUT_MULTISAMPLE)

    # Creating a screen with good resolution proportions
    screen_width = GLUT.glutGet(GLUT.GLUT_SCREEN_WIDTH)
    screen_height = GLUT.glutGet(GLUT.GLUT_SCREEN_HEIGHT)

    window_width = round(2 * screen_width / 3)
    window_height = round(2 * screen_height / 3)

    GLUT.glutInitWindowSize(window_width, window_height)
    GLUT.glutInitWindowPosition(round((screen_width - window_width) / 2),
                                round((screen_height - window_height) / 2))
    GLUT.glutCreateWindow(window_name)

    # Drawing Function
    GLUT.glutDisplayFunc(draw)

    # Input Functions
    GLUT.glutSpecialFunc(special_key_pressed)
    GLUT.glutKeyboardFunc(key_pressed)
    GLUT.glutMouseFunc(mouse_click)
    GLUT.glutMotionFunc(mouse_move)

    load_textures()

    GL.glEnable(GL.GL_MULTISAMPLE)
    GL.glEnable(GL.GL_DEPTH_TEST)
    GL.glEnable(GL.GL_TEXTURE_2D)

    GL.glClearColor(*background_color)
    GL.glClearDepth(1.0)
    GL.glDepthFunc(GL.GL_LESS)

    GL.glShadeModel(GL.GL_SMOOTH)
    GL.glMatrixMode(GL.GL_PROJECTION)

    # Pre-render camera positioning
    GLU.gluPerspective(-45, window_width / window_height, 0.1, 100.0)
    GL.glTranslatef(0.0, 0.0, -10)

    GL.glMatrixMode(GL.GL_MODELVIEW)

    GLUT.glutTimerFunc(10, timer, 1)
    GLUT.glutMainLoop()
Esempio n. 23
0
    def __init__(self, name='glut window', *args, **kwargs):
        BaseCanvasBackend.__init__(self)
        self._id = glut.glutCreateWindow(name)
        global ALL_WINDOWS
        ALL_WINDOWS.append(self)

        # Cache of modifiers so we can send modifiers along with mouse motion
        self._modifiers_cache = ()

        # Note: this seems to cause the canvas to ignore calls to show()
        # about half of the time.
        # glut.glutHideWindow()  # Start hidden, like the other backends

        # Register callbacks
        glut.glutDisplayFunc(self.on_draw)
        glut.glutReshapeFunc(self.on_resize)
        # glut.glutVisibilityFunc(self.on_show)
        glut.glutKeyboardFunc(self.on_key_press)
        glut.glutSpecialFunc(self.on_key_press)
        glut.glutKeyboardUpFunc(self.on_key_release)
        glut.glutMouseFunc(self.on_mouse_action)
        glut.glutMotionFunc(self.on_mouse_motion)
        glut.glutPassiveMotionFunc(self.on_mouse_motion)

        # Set close function. See issue #10. For some reason, the function
        # can still not exist even if we checked its boolean status.
        closeFuncSet = False
        if bool(glut.glutWMCloseFunc):  # OSX specific test
            try:
                glut.glutWMCloseFunc(self.on_close)
                closeFuncSet = True
            except OpenGL.error.NullFunctionError:
                pass
        if not closeFuncSet:
            try:
                glut.glutCloseFunc(self.on_close)
                closeFuncSet = True
            except OpenGL.error.NullFunctionError:
                pass

        # glut.glutFunc(self.on_)

        self._initialized = False

        # LC: I think initializing here makes it more consistent with other
        # backends
        glut.glutTimerFunc(0, self._emit_initialize, None)
Esempio n. 24
0
    def main(self):
        """Main function responsible for run the game."""

        glut.glutInit(sys.argv)

        # Select type of Display mode:
        #  Double buffer
        #  RGBA color
        # Alpha components supported
        # Depth buffer
        glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DOUBLE
                                 | glut.GLUT_DEPTH)

        # get a 640 x 480 window
        glut.glutInitWindowSize(1000, 800)

        # the window starts at the upper left corner of the screen
        glut.glutInitWindowPosition(0, 0)

        # Asign name of the window
        glut.glutCreateWindow("PacMan")

        # Register the function called when the keyboard is pressed.
        glut.glutKeyboardFunc(self.key_pressed)

        glut.glutSpecialFunc(self.key_pressed_special)

        glut.glutSpecialUpFunc(self.key_pressed_special_up)

        # Register the drawing function with glut.
        glut.glutDisplayFunc(self.draw_scene)

        # Uncomment this line to get full screen.
        # glut.glutFullScreen()

        # When we are doing nothing, redraw the scene.
        glut.glutIdleFunc(self.draw_scene)

        # Register the function called when our window is resized.
        glut.glutReshapeFunc(self.re_size_gl_scene)

        # Initialize our window.
        self.init_gl(640, 480)

        # Start Event Processing Engine
        glut.glutMainLoop()
Esempio n. 25
0
def init():
    GLUT.glutInit()
    #GLUT.glutInitDisplayMode(GLUT.GLUT_RGB | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH)
    GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE
                             | GLUT.GLUT_ALPHA | GLUT.GLUT_DEPTH)
    GLUT.glutInitWindowSize(width, height)
    # the window starts at the upper left corner of the screen
    GLUT.glutInitWindowPosition(0, 0)
    window = GLUT.glutCreateWindow(winName)
    GLUT.glutDisplayFunc(DrawGLScene)
    # Uncomment this line to get full screen.
    #glutFullScreen()
    # When we are doing nothing, redraw the scene.
    GLUT.glutIdleFunc(DrawGLScene)
    GLUT.glutReshapeFunc(resizeWindow)
    GLUT.glutKeyboardFunc(keyPressed)
    GLUT.glutSpecialFunc(keyPressed)
Esempio n. 26
0
 def init_window(self):
     glut.glutInit(sys.argv)
     glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA
                              | glut.GLUT_ALPHA | glut.GLUT_DEPTH)
     glut.glutInitWindowPosition(
         (glut.glutGet(glut.GLUT_SCREEN_WIDTH) - self.window_width) // 2,
         (glut.glutGet(glut.GLUT_SCREEN_HEIGHT) - self.window_height) // 2)
     glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE,
                        glut.GLUT_ACTION_CONTINUE_EXECUTION)
     glut.glutInitWindowSize(self.window_width, self.window_height)
     self.window_handle = glut.glutCreateWindow(WINDOW_TITLE_PREFIX)
     glut.glutDisplayFunc(self.render_func)
     glut.glutReshapeFunc(self.resize_func)
     glut.glutMouseFunc(self.mouse)
     glut.glutMotionFunc(self.mouse_motion)
     glut.glutKeyboardFunc(self.keyboard)
     glut.glutSpecialFunc(self.keyboard_s)
Esempio n. 27
0
def main(filepath, texpath):

    glut.glutInit()
    glut.glutInitContextVersion(3, 3)
    glut.glutInitContextProfile(glut.GLUT_CORE_PROFILE)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH)
    glut.glutInitWindowSize(win_width,win_height)
    glut.glutCreateWindow('M E S H')

    initData(filepath, texpath)
    initShaders()

    glut.glutReshapeFunc(reshape)
    glut.glutDisplayFunc(display)
    glut.glutKeyboardFunc(keyboard)
    glut.glutSpecialFunc(special_keyboard)
    glut.glutIdleFunc(idle)

    glut.glutMainLoop()
Esempio n. 28
0
    def start(self):
        """
        Запуск
        """

        GLUT.glutInit([])  # Инициализация библиотеки GLUT
        buffering = GLUT.GLUT_SINGLE  # Вариант буферизации
        color_model = GLUT.GLUT_RGB  # Вариант цветовой модели

        # Инициализация отображения в нужном режимах
        GLUT.glutInitDisplayMode(buffering | color_model | GLUT.GLUT_DEPTH)
        GLUT.glutInitWindowSize(self.window_width,
                                self.window_height)  # Размер окна
        GLUT.glutInitWindowPosition(self.move_window_x,
                                    self.move_window_y)  # Позиция окна
        GLUT.glutCreateWindow(
            self.window_name)  # Создание окна с указанным именем

        GLUT.glutDisplayFunc(
            self.__draw)  # Отображение изображения (перерисовка окна)
        GLUT.glutIdleFunc(
            self.__draw
        )  # Вызывается системой всякий раз, когда приложение простаивает

        GLUT.glutReshapeFunc(self.__resize)  # Изменение размеров окна

        # Обработка нажатий на клавиатуру (клавиша Escape)
        GLUT.glutKeyboardFunc(self.__keyboard)
        GLUT.glutSpecialFunc(
            self.__keyboard)  # Обработка нажатий на клавиатуру

        GL.glClearColor(0.0, 0.0, 0.0, 1.0)
        GL.glEnable(GL.GL_DEPTH_TEST)
        GL.glMatrixMode(
            GL.GL_PROJECTION
        )  # Применять матричные операции к стеку проекционных матриц
        GL.glLoadIdentity()  # Единичная матрица
        GL.glOrtho(-1, 1, -1, 1, -1,
                   1)  # Умножение текущей матрицы на ортографическую матрицу

        GLUT.glutMainLoop()  # Цикл обработки событий GLUT
Esempio n. 29
0
    def __init__(self, scene):
        """Sets up the core functionality we need
        to begin rendering.
        This includes the OpenGL configuration, the
        window, the viewport, the event handler
        and update loop registration.
        """
        super(Application, self).__init__(scene)

        if self.scene.core_profile:
            raise ValueError("GLUT does not support Core profile")

        # glut initialization
        GLUT.glutInit(sys.argv)
        GLUT.glutInitDisplayMode(GLUT.GLUT_DOUBLE | GLUT.GLUT_RGBA
                                 | GLUT.GLUT_DEPTH)

        # set the window's dimensions
        GLUT.glutInitWindowSize(1024, 768)

        # set the window caption
        # create our window
        GLUT.glutCreateWindow("PyGLy - GLUT - " + scene.name)

        # print some opengl information
        pygly.gl.print_gl_info()

        # create the scene now that we've got our window open
        self.scene.initialise()

        self.last_time = time()

        # set the function to draw
        GLUT.glutReshapeFunc(self.on_window_resized)
        GLUT.glutIdleFunc(self.idle)
        GLUT.glutDisplayFunc(self.render)
        GLUT.glutKeyboardFunc(self.on_key_pressed)
        GLUT.glutKeyboardUpFunc(self.on_key_released)
        GLUT.glutSpecialFunc(self.on_special_key_pressed)
        GLUT.glutSpecialUpFunc(self.on_special_key_released)
Esempio n. 30
0
def main():    
    GLUT.glutInit(argv)
    GLUT.glutInitDisplayMode(
        GLUT.GLUT_DOUBLE | GLUT.GLUT_RGBA | GLUT.GLUT_DEPTH | GLUT.GLUT_MULTISAMPLE
    )

    
    screen_width = GLUT.glutGet(GLUT.GLUT_SCREEN_WIDTH)
    screen_height = GLUT.glutGet(GLUT.GLUT_SCREEN_HEIGHT)

    window_width = round(2 * screen_width / 3)
    window_height = round(2 * screen_height / 3)

    GLUT.glutInitWindowSize(window_width, window_height)
    GLUT.glutInitWindowPosition(
        round((screen_width - window_width) / 2), round((screen_height - window_height) / 2)
    )
    GLUT.glutCreateWindow(window_name)

 
    GLUT.glutDisplayFunc(draw)

    
    GLUT.glutSpecialFunc(special_key_pressed)
    GLUT.glutKeyboardFunc(key_pressed)
    GLUT.glutMouseFunc(mouse_click)
    GLUT.glutMotionFunc(mouse_move)

    GL.glEnable(GL.GL_MULTISAMPLE)
    GL.glEnable(GL.GL_DEPTH_TEST)

    GL.glClearColor(*background_color)


    GLU.gluPerspective(-45, window_width / window_height, 0.1, 100.0)
    GL.glTranslatef(0.0, 0.0, -10)

    GLUT.glutTimerFunc(10, timer, 1)
    GLUT.glutMainLoop()
Esempio n. 31
0
    def __init__( self, scene ):
        """Sets up the core functionality we need
        to begin rendering.
        This includes the OpenGL configuration, the
        window, the viewport, the event handler
        and update loop registration.
        """
        super( Application, self ).__init__( scene )

        if self.scene.core_profile:
            raise ValueError( "GLUT does not support Core profile" )

        # glut initialization
        GLUT.glutInit( sys.argv )
        GLUT.glutInitDisplayMode( GLUT.GLUT_DOUBLE | GLUT.GLUT_RGBA | GLUT.GLUT_DEPTH )

        # set the window's dimensions
        GLUT.glutInitWindowSize( 1024, 768 )

        # set the window caption
        # create our window
        GLUT.glutCreateWindow( "PyGLy - GLUT - " + scene.name )

        # print some opengl information
        pygly.gl.print_gl_info()

        # create the scene now that we've got our window open
        self.scene.initialise()

        self.last_time = time()

        # set the function to draw
        GLUT.glutReshapeFunc( self.on_window_resized )
        GLUT.glutIdleFunc( self.idle )
        GLUT.glutDisplayFunc( self.render )
        GLUT.glutKeyboardFunc( self.on_key_pressed )
        GLUT.glutKeyboardUpFunc( self.on_key_released )
        GLUT.glutSpecialFunc( self.on_special_key_pressed )
        GLUT.glutSpecialUpFunc( self.on_special_key_released )
Esempio n. 32
0
    def __init__(self, width=640, height=480, fullscreen=False, aspect=None):
        self.gl = gl
        glut.glutInit(sys.argv)
        glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH)
        glut.glutInitWindowPosition(0, 0)
        glut.glutCreateWindow(b"BlitzLoop Karaoke")
        if not fullscreen:
            glut.glutReshapeWindow(width, height)
        else:
            glut.glutSetCursor(glut.GLUT_CURSOR_NONE)
        BaseDisplay.__init__(self, width, height, fullscreen, aspect)
        self._on_reshape(width, height)
        if fullscreen:
            self.saved_size = (width, height)
            glut.glutFullScreen()
        glut.glutDisplayFunc(self._render)
        glut.glutIdleFunc(self._render)
        glut.glutReshapeFunc(self._on_reshape)
        glut.glutKeyboardFunc(self._on_keyboard)
        glut.glutSpecialFunc(self._on_keyboard)

        self._initialize()
Esempio n. 33
0
	def __init__(self, width=640, height=480, fullscreen=False, aspect=None):
		self.kbd_handler = None
		self.win_width = width
		self.win_height = height
		glut.glutInit(sys.argv)
		glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH)
		glut.glutInitWindowPosition(0, 0)
		glut.glutCreateWindow("Karaoke")
		if not fullscreen:
			glut.glutReshapeWindow(width, height)
		else:
			glut.glutSetCursor(glut.GLUT_CURSOR_NONE)
		self.win_width = width
		self.win_height = height
		self.set_aspect(aspect)
		self._on_reshape(width, height)
		if fullscreen:
			glut.glutFullScreen()
		glut.glutDisplayFunc(self._render)
		glut.glutIdleFunc(self._render)
		glut.glutReshapeFunc(self._on_reshape)
		glut.glutKeyboardFunc(self._on_keyboard)
		glut.glutSpecialFunc(self._on_keyboard)
Esempio n. 34
0
    def __init__(self, **kwargs):
        BaseCanvasBackend.__init__(self, capability, SharedContext)
        title, size, position, show, vsync, resize, dec, fs, context = \
            self._process_backend_kwargs(kwargs)
        _set_config(context)
        glut.glutInitWindowSize(size[0], size[1])
        self._id = glut.glutCreateWindow(title.encode('ASCII'))
        if not self._id:
            raise RuntimeError('could not create window')
        glut.glutSetWindow(self._id)
        _VP_GLUT_ALL_WINDOWS.append(self)
        if fs is not False:
            if isinstance(fs, int):
                logger.warn('Cannot specify monitor for glut fullscreen, '
                            'using default')
            glut.glutFullScreen()

        # Cache of modifiers so we can send modifiers along with mouse motion
        self._modifiers_cache = ()
        self._closed = False  # Keep track whether the widget is closed

        # Register callbacks
        glut.glutDisplayFunc(self.on_draw)
        glut.glutReshapeFunc(self.on_resize)
        # glut.glutVisibilityFunc(self.on_show)
        glut.glutKeyboardFunc(self.on_key_press)
        glut.glutSpecialFunc(self.on_key_press)
        glut.glutKeyboardUpFunc(self.on_key_release)
        glut.glutMouseFunc(self.on_mouse_action)
        glut.glutMotionFunc(self.on_mouse_motion)
        glut.glutPassiveMotionFunc(self.on_mouse_motion)
        _set_close_fun(self._id, self.on_close)
        self._vispy_canvas_ = None
        if position is not None:
            self._vispy_set_position(*position)
        if not show:
            glut.glutHideWindow()
Esempio n. 35
0
 def __init__(self, width=640, height=480, fullscreen=False, aspect=None):
     self.kbd_handler = None
     self.win_width = width
     self.win_height = height
     glut.glutInit(sys.argv)
     glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB
                              | glut.GLUT_DEPTH)
     glut.glutInitWindowPosition(0, 0)
     glut.glutCreateWindow("BlitzLoop Karaoke")
     if not fullscreen:
         glut.glutReshapeWindow(width, height)
     else:
         glut.glutSetCursor(glut.GLUT_CURSOR_NONE)
     self.win_width = width
     self.win_height = height
     self.set_aspect(aspect)
     self._on_reshape(width, height)
     if fullscreen:
         glut.glutFullScreen()
     glut.glutDisplayFunc(self._render)
     glut.glutIdleFunc(self._render)
     glut.glutReshapeFunc(self._on_reshape)
     glut.glutKeyboardFunc(self._on_keyboard)
     glut.glutSpecialFunc(self._on_keyboard)
Esempio n. 36
0
def main() :
    global tetris
    tetris = Tetris()

    _ = glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH)

    glut.glutInitWindowSize(600, 600)
    glut.glutInitWindowPosition(0, 100)
    _ = glut.glutCreateWindow('Tetris!!!')

    init()

    _ = glut.glutDisplayFunc(display)
    _ = glut.glutReshapeFunc(reshape)
    _ = glut.glutKeyboardFunc(keyboard)
    _ = glut.glutIdleFunc(idle)
    _ = glut.glutMotionFunc(mouse)
    _ = glut.glutSpecialFunc(special)

    glut.glutMainLoop()
Esempio n. 37
0
 def start(self):
     GLUT.glutIgnoreKeyRepeat(True)
     GLUT.glutSpecialFunc(self.special_keyboard_down)
     GLUT.glutSpecialUpFunc(self.special_keyboard_up)
Esempio n. 38
0
def handle_special_keypress(key, x, y):
    if key == GLUT_KEY_LEFT and not camera.position.x == 24:
        camera.position += glm.vec3(10.0, 0.0, 0.0)

    if key == GLUT_KEY_RIGHT and not camera.position.x == -26:
        camera.position -= glm.vec3(10.0, 0.0, 0.0)

    if key == GLUT_KEY_UP and not camera.position.y == 60:
        camera.position += glm.vec3(0.0, 10.0, 0.0)

    if key == GLUT_KEY_DOWN and not camera.position.y == 0:
        camera.position -= glm.vec3(0.0, 10.0, 0.0)


glut.glutKeyboardUpFunc(keyboard_up_input)
glut.glutSpecialFunc(handle_special_keypress)


def keyboard_input(key, x, y):
    pressed_keys.add(key)

    if key == b'-':
        player.scale -= glm.vec3(0.1)
        player.scaling(player.scale)

    if key == b'+':
        player.scale += glm.vec3(0.1)
        player.scaling(player.scale)

    if key == b'r':
        ball.position = glm.vec3(-5, 0, -10)
Esempio n. 39
0
                doc='glutInitDisplayString(  ) -> None',
                argNames=())
            text = ctypes.c_char_p("rgba stencil double samples=8 hidpi")
            glutInitDisplayString(text)
        except:
            pass

    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB
                             | glut.GLUT_DEPTH)
    glut.glutInitWindowSize(1000, 1000)
    glut.glutCreateWindow(
        "Dashed & antialiased bezier curve [Arrow keys change offset]")
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)
    glut.glutSpecialFunc(on_special)

    # Some init
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
    gl.glDisable(gl.GL_DEPTH_TEST)
    gl.glEnable(gl.GL_BLEND)
    gl.glClearColor(1.0, 1.0, 1.0, 1.0)
    u_projection = np.eye(4).astype(np.float32)
    u_view = np.eye(4).astype(np.float32)
    u_model = np.eye(4).astype(np.float32)

    collection = DashLines()

    # ---------------------------------
    points = np.array([[.1, .6], [.5, 1.], [.9, .6]])
    vertices = curve3_bezier(*points)
Esempio n. 40
0
    global deltaMove

    if key == glut.GLUT_KEY_UP:
        deltaMove = 0.5
    elif key == glut.GLUT_KEY_DOWN:
        deltaMove = -0.5


# -------------------------------------------------------
def releaseKey(key, xx, yy):
    global deltaMove

    deltaMove = 0


# -------------------------------------------------------
# main program init
glut.glutInit()
glut.glutInitWindowSize(800, 600)
glut.glutInitDisplayMode(glut.GLUT_RGB | glut.GLUT_DOUBLE | glut.GLUT_DEPTH)
glut.glutCreateWindow("DynSimTest")
glut.glutDisplayFunc(render)
glut.glutIdleFunc(simulate)
glut.glutMouseFunc(mouseButton)
glut.glutMotionFunc(mouseMove)
glut.glutSpecialFunc(pressKey)
glut.glutSpecialUpFunc(releaseKey)

init()

glut.glutMainLoop()
Esempio n. 41
0
    #     game_state.modify('right')
    #     glut.glutPostRedisplay()
    # elif key == glut.GLUT_KEY_UP:
    #     game_state.modify('up')
    #     glut.glutPostRedisplay()
    # elif key == glut.GLUT_KEY_DOWN:
    #     game_state.modify('down')
    #     glut.glutPostRedisplay()
    pass

task_spec = json.loads(open(sys.argv[1]).read())

units = list(lib._unit_generator(
    task_spec['sourceSeeds'][0],
    task_spec['units'],
    limit=task_spec['sourceLength']))

init_board = lib.Board(task_spec['width'], task_spec['height'], task_spec['filled'])
game_state = lib.InitState(init_board, units)


glut.glutInit()
glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
glut.glutCreateWindow('Honeycomb board visualisation')
glut.glutReshapeWindow(800,800)
glut.glutReshapeFunc(reshape)
glut.glutDisplayFunc(display)
glut.glutKeyboardFunc(keyboard)
glut.glutSpecialFunc(special_input)
glut.glutMainLoop()
Esempio n. 42
0
    def __init__(self, size=None, position=None, title=None, fullscreen=False,enableAlpha=True,pointSize=2):
        '''
        Constructor
        '''
        self._mouse_x = 0
        self._mouse_y = 0
        self._button = mouse.NONE
        self._modifiers = None
        self._motionEventCounter=0
        self._time = None
        self._timer_stack = []
        self._timer_date = []
        self._title = title or "PyGLer" # FIXME: get default name from a central location 
        self._fullscreen = -1
        
        self.dragSensitivity = 5
        
        # Is there any glut loop already running ?
        if glut.glutGetWindow( ) == 0:
            glut.glutInit()
            glut.glutInitDisplayMode( glut.GLUT_DOUBLE |
                                      glut.GLUT_RGBA   |
                                      glut.GLUT_DEPTH )
            self._interactive = False
        else:
            self._interactive = True
            
        self._id = glut.glutCreateWindow( self._title )
        glut.glutShowWindow()        
        
        glut.glutDisplayFunc( self.redraw )
        glut.glutReshapeFunc( self._reshape )
        glut.glutKeyboardFunc( self._keyboard )
        glut.glutKeyboardUpFunc( self._keyboard_up )
        glut.glutMouseFunc( self._mouse )
        glut.glutMotionFunc( self._motion )
        glut.glutPassiveMotionFunc( self._passive_motion )
        glut.glutVisibilityFunc( self._visibility )
        glut.glutEntryFunc( self._entry )
        glut.glutSpecialFunc( self._special )
        glut.glutSpecialUpFunc( self._special_up )   
            
        GL.glEnable(GL.GL_DEPTH_TEST)
        
        GL.glEnable(GL.GL_BLEND)
        if enableAlpha:
            GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
        
        GL.glPolygonOffset(1, 1);
        GL.glEnable(GL.GL_POLYGON_OFFSET_FILL);

        GL.glPointSize(pointSize)
        GL.glEnable(GL.GL_PROGRAM_POINT_SIZE)
            
        if size is not None:
            width, height = size
            glut.glutReshapeWindow( width, height )

        width = glut.glutGet( glut.GLUT_WINDOW_WIDTH )
        height= glut.glutGet( glut.GLUT_WINDOW_HEIGHT )
        self._width = width
        self._height = height
        if position is not None:
            x,y = position
            glut.glutPositionWindow( x, y )
            
        x = glut.glutGet( glut.GLUT_WINDOW_X )
        y = glut.glutGet( glut.GLUT_WINDOW_X )
        self._x, self._y = x, y

        # These ones will be used when exiting fullscreen
        self._saved_width  = self._width
        self._saved_height = self._height
        self._saved_x = self._x
        self._saved_y = self._y

        self._time = glut.glutGet( glut.GLUT_ELAPSED_TIME )
        self._fullscreen = fullscreen
        if fullscreen:
            self.set_fullscreen(True)
Esempio n. 43
0
def tiny_glut(args):
    global vertex_code, fragment_code
    scale = 0.01

    def display():
        CAMERA.render()
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        nonlocal scale
        scale_location = gl.glGetUniformLocation(program, "gScale")
        assert scale_location != 0xffffffff
        world_location = gl.glGetUniformLocation(program, "gWorld")
        assert world_location != 0xffffffff

        scale += 0.01

        pipeline = Pipeline(rotation=[0.0, 30*scale, 0.0],
                            # scaling=[math.sin(scale)] * 3,
                            translation=[0, 0, 6],
                            projection=ProjParams(WINDOW_WIDTH, WINDOW_HEIGHT, 1.0, 100.0, 60.0))
        pipeline.set_camera(CAMERA)

        gl.glUniformMatrix4fv(world_location, 1, gl.GL_TRUE, pipeline.get_wvp())
        gl.glDrawElements(gl.GL_TRIANGLES, 18, gl.GL_UNSIGNED_INT, ctypes.c_void_p(0))
        glut.glutSwapBuffers()
        # glut.glutPostRedisplay()

    def mouse(x, y):
        CAMERA.mouse(x, y)

    def keyboard(key, x, y):
        if key == glut.GLUT_KEY_F1:
            sys.exit(0)
        elif key == glut.GLUT_KEY_HOME:
            CAMERA.setup()
        else:
            CAMERA.keyboard(key)

    glut.glutInit(args)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_3_2_CORE_PROFILE)
    glut.glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT)
    glut.glutInitWindowPosition(400, 100)
    # glut.glutCreateWindow("Camera Tutorial")
    glut.glutGameModeString("1920x1200@32")
    glut.glutEnterGameMode()

    # callbacks initialization
    glut.glutDisplayFunc(display)
    glut.glutIdleFunc(display)
    # glut.glutKeyboardFunc(keyboard)
    glut.glutPassiveMotionFunc(mouse)
    glut.glutSpecialFunc(keyboard)

    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glDepthFunc(gl.GL_LESS)
    gl.glClearColor(0, 0, 0, 0)

    vertices = np.array([
        -1, -1, 0,
        0, -1, -1,
        1, -1, 0,
        0, -1, 1,
        0, 1, 0
    ], dtype=np.float32)

    indexes = np.array([
        0, 1, 2,
        1, 2, 3,
        0, 1, 4,
        1, 2, 4,
        2, 3, 4,
        3, 0, 4
    ], dtype=np.uint32)

    vertex_shader = gl.glCreateShader(gl.GL_VERTEX_SHADER)
    gl.glShaderSource(vertex_shader, vertex_code)
    gl.glCompileShader(vertex_shader)

    if not gl.glGetShaderiv(vertex_shader, gl.GL_COMPILE_STATUS):
        info = gl.glGetShaderInfoLog(vertex_shader)
        print("vertex shader error occurred")
        print(bytes.decode(info))
        return

    fragment_shader = gl.glCreateShader(gl.GL_FRAGMENT_SHADER)
    gl.glShaderSource(fragment_shader, fragment_code)
    gl.glCompileShader(fragment_shader)

    if not gl.glGetShaderiv(fragment_shader, gl.GL_COMPILE_STATUS):
        info = gl.glGetShaderInfoLog(fragment_shader)
        print("fragment shader error occurred")
        print(bytes.decode(info))
        return

    program = gl.glCreateProgram()
    gl.glAttachShader(program, vertex_shader)
    gl.glAttachShader(program, fragment_shader)
    gl.glLinkProgram(program)
    gl.glUseProgram(program)

    vao = gl.glGenVertexArrays(1)
    gl.glBindVertexArray(vao)

    vbo = gl.glGenBuffers(1)
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vbo)
    gl.glBufferData(gl.GL_ARRAY_BUFFER, vertices.nbytes, vertices, gl.GL_STATIC_DRAW)
    gl.glEnableVertexAttribArray(0)
    gl.glVertexAttribPointer(0, 3, gl.GL_FLOAT, gl.GL_FALSE, 0, ctypes.c_void_p(0))

    ibo = gl.glGenBuffers(1)
    gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, ibo)
    gl.glBufferData(gl.GL_ELEMENT_ARRAY_BUFFER, indexes.nbytes, indexes, gl.GL_STATIC_DRAW)
    glut.glutMainLoop()
Esempio n. 44
0
    def __init__( self, size=None, position=None, title=None, fullscreen=False):
        '''
        Create a window with given sise, position and title.

        :param (int,int) size:
            Initial window size as (width,height) in pixels.

        :param (int,int) position:
            Initial window position. Depending on the window-manager, the
            position request may or may not be honored.

        :param string title:
           The title of the window.
        '''

        global _window

        window.Window.__init__( self, size, position, title )
        self._mouse_x = 0
        self._mouse_y = 0
        self._button = mouse.NONE
        self._modifiers = None
        self._time = None
        self._timer_stack = []
        self._timer_date = []
        self._title = title or sys.argv[0]
        self._fullscreen = -1

        # Is there any glut loop already running ?
        if glut.glutGetWindow( ) == 0:
            glut.glutInit( sys.argv )
            glut.glutInitDisplayMode( glut.GLUT_DOUBLE |
                                      glut.GLUT_RGBA   |
                                      glut.GLUT_DEPTH )
            self._interactive = False
        else:
            self._interactive = True

        self._id = glut.glutCreateWindow( self._title )
        glut.glutShowWindow( )

        glut.glutDisplayFunc( self._display )
        glut.glutReshapeFunc( self._reshape )
        glut.glutKeyboardFunc( self._keyboard )
        glut.glutKeyboardUpFunc( self._keyboard_up )
        glut.glutMouseFunc( self._mouse )
        glut.glutMotionFunc( self._motion )
        glut.glutPassiveMotionFunc( self._passive_motion )
        glut.glutVisibilityFunc( self._visibility )
        glut.glutEntryFunc( self._entry )
        glut.glutSpecialFunc( self._special )
        glut.glutSpecialUpFunc( self._special_up )

        if size is not None:
            width, height = size
            glut.glutReshapeWindow( width, height )
        width = glut.glutGet( glut.GLUT_WINDOW_WIDTH )
        height= glut.glutGet( glut.GLUT_WINDOW_HEIGHT )
        self._width = width
        self._height = height
        if position is not None:
            x,y = position
            glut.glutPositionWindow( x, y )
        #else:
        #    screen_width = glut.glutGet( glut.GLUT_SCREEN_WIDTH )
        #    screen_height= glut.glutGet( glut.GLUT_SCREEN_HEIGHT )
        #    x = (screen_width - self._size[0]) / 2
        #    y = (screen_width - self._size[0]) / 2
        #    glut.glutPositionWindow( x, y )
        x = glut.glutGet( glut.GLUT_WINDOW_X )
        y = glut.glutGet( glut.GLUT_WINDOW_X )
        self._x, self._y = x, y

        # These ones will be used when exiting fullscreen
        self._saved_width  = self._width
        self._saved_height = self._height
        self._saved_x = self._x
        self._saved_y = self._y

        self._time = glut.glutGet( glut.GLUT_ELAPSED_TIME )
        _window = self
        self._fullscreen = False
        if fullscreen:
            self.set_fullscreen(True)
Esempio n. 45
0
    glut.glutPostRedisplay()


if __name__ == '__main__':
    import sys
    import OpenGL.GLUT as glut
    from glagg import PathCollection

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB)
    glut.glutCreateWindow("Line joins")
    glut.glutReshapeWindow(512, 512)
    glut.glutDisplayFunc(on_display)
    glut.glutReshapeFunc(on_reshape)
    glut.glutKeyboardFunc(on_keyboard)
    glut.glutSpecialFunc(on_special)

    vertices = np.array( [(-0.50,-0.125),
                          (-0.25,+0.125),
                          (+0.00,-0.125),
                          (+0.25,+0.125),
                          (+0.50,-0.125) ] )
    collection = PathCollection()
    collection.append(vertices, linewidth = 40,
                      linejoin = 'miter', linecaps= ('<','>'),
                      scale = 300, translate = (256,128) )
    collection.append(vertices, linewidth = 40,
                      linejoin = 'round', linecaps= ('(',')'),
                      scale = 300, translate = (256,256) )
    collection.append(vertices, linewidth = 40,
                      linejoin = 'bevel', linecaps= ('=','='),
Esempio n. 46
0
if __name__ == '__main__':
    glut.glutInit(sys.argv)

    width, height = 640, 480

    glut.glutInitDisplayMode(glut.GLUT_RGBA
                             | glut.GLUT_DOUBLE
                             | glut.GLUT_DEPTH)
    glut.glutInitWindowSize(width, height)
    glut.glutInitWindowPosition(0, 0)

    # assign to global window variable
    window = glut.glutCreateWindow('Invaders')
    if config.fullscreen_mode:
        glut.glutFullScreen()

    world = World(config.mode[0])

    # draw scene on display and between other calculations
    draw_func = display.get_display(world)
    glut.glutDisplayFunc(draw_func)

    glut.glutIdleFunc(draw_func)
    glut.glutReshapeFunc(resize_func)
    glut.glutKeyboardFunc(keyboard.normal_keys)
    glut.glutSpecialFunc(keyboard.get_special_keys(world))

    init_environment(width, height)

    glut.glutMainLoop()