Exemplo n.º 1
0
def main():
		global window
		# For now we just pass glutInit one empty argument. I wasn't sure what should or could be passed in (tuple, list, ...)
		# Once I find out the right stuff based on reading the PyOpenGL source, I'll address this.
		lutAsString = buildBitsLUT()
		GLUT.glutInit([])
		GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_ALPHA | GLUT.GLUT_DEPTH)
		
		# get a 640 x 480 window 
		GLUT.glutInitWindowSize(800, 600)
		
		# the window starts at the upper left corner of the screen 
		GLUT.glutInitWindowPosition(0, 0)
		
		window = GLUT.glutCreateWindow("Jeff Molofee's GL Code Tutorial ... NeHe '99")
		# glutFullScreen()
		#register callbacks
		GLUT.glutIdleFunc(DrawGLScene)		
		GLUT.glutReshapeFunc(ReSizeGLScene)
		GLUT.glutKeyboardFunc(keyPressed)
		GLUT.glutDisplayFunc(DrawGLScene)		

		InitGL(800, 600)

		GLUT.glutMainLoop()
Exemplo n.º 2
0
def visualizeGraph(V1,G1,C1,S1):


	#Assign
	global V
	global G
	global C
	global S
	V = V1
	G = G1
	C = C1
	S = S1

	#Take Log
	S = numpy.log(S + 1)


	#Init Glut
	glut.glutInit(sys.argv)
	glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH)
	glut.glutInitWindowSize(1024,1024)
	glut.glutCreateWindow("Visualize (GLUT)")
	glut.glutDisplayFunc(on_display)
	glut.glutKeyboardFunc(on_keyboard)
	glut.glutReshapeFunc(on_reshape);


	#Lookat	
	gluLookAt(0,12,0,  0,0,0,  0,0,1);
	

	#Idle function
	glut.glutIdleFunc(on_idle)
	glut.glutFullScreen()
	glut.glutMainLoop()
Exemplo n.º 3
0
    def run_sim_with_window(self):
        print("\n")
        print("space bar: simulation on/off")
        print("' ': run/stop simulation")
        print("'a': run/stop animation")
        print("'[' and ']': play one frame backward and forward")

        # Init glut
        GLUT.glutInit(())
        GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE
                                 | GLUT.GLUT_MULTISAMPLE | GLUT.GLUT_ALPHA
                                 | GLUT.GLUT_DEPTH)
        GLUT.glutInitWindowSize(*self.window_size)
        GLUT.glutInitWindowPosition(0, 0)
        self.window = GLUT.glutCreateWindow(self.title)

        # Init functions
        # glutFullScreen()
        GLUT.glutDisplayFunc(self.drawGL)
        GLUT.glutIdleFunc(self.idle)
        GLUT.glutReshapeFunc(self.resizeGL)
        GLUT.glutKeyboardFunc(self.keyPressed)
        GLUT.glutMouseFunc(self.mouseFunc)
        GLUT.glutMotionFunc(self.motionFunc)
        GLUT.glutTimerFunc(25, self.renderTimer, 1)
        self.initGL(*self.window_size)

        # Run
        GLUT.glutMainLoop()
Exemplo n.º 4
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()
Exemplo n.º 5
0
    def __init__(self):
        """
        Basic GLUT init and glut function definition.

        Notes
        -----
        `self.render_obj` is initialized here, which is then being used and drawn in `self.display`
        """

        glut.glutInit()
        glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DOUBLE
                                 | glut.GLUT_DEPTH | glut.GLUT_MULTISAMPLE)
        glut.glutCreateWindow('Frightened Glut Rabbit')
        glut.glutReshapeWindow(Global.WIDTH, Global.HEIGHT)
        glut.glutReshapeFunc(self.reshape)
        glut.glutDisplayFunc(self.display)
        glut.glutKeyboardFunc(self.keyboard)
        glut.glutMouseFunc(self.glutMousePressEvent)
        glut.glutMotionFunc(self.glutMouseMoveEvent)
        glut.glutTimerFunc(Global.REFRESH_TIMER, self.onTimer,
                           Global.REFRESH_TIMER)

        self.buildProgram()

        self.reshape(Global.WIDTH, Global.HEIGHT)

        # set object to be rendered
        self.render_obj = default_obj()

        # For checking if need to swap
        self.standalone = True
Exemplo n.º 6
0
    def __init__(self,
                 world,
                 title='',
                 height=500,
                 width=500):
        self.world = world
        self.time_interval = 10
        GLUT.glutInit(sys.argv)
        self.lastTime = GLUT.glutGet(GLUT.GLUT_ELAPSED_TIME)
        GLUT.glutInitDisplayMode(GLUT.GLUT_DOUBLE | 
                                 GLUT.GLUT_RGB | 
                                 GLUT.GLUT_DEPTH)
        GLUT.glutInitWindowSize(height, width)
        GLUT.glutCreateWindow(title)
        GLUT.glutDisplayFunc(self.render)
        GLUT.glutReshapeFunc(self.onSize)

        self.init = False
        
        #initialized to actual values in setupView
        self.viewport_left = 0
        self.viewport_bottom = 0
        self.viewport_height = 0
        self.viewport_width = 0
        
        self.timeStep = 1
        self.timeElapsed = self.time_interval / 1000.0
Exemplo n.º 7
0
    def run(self, ):
        print("\n")
        print("space bar: simulation on/off")
        print("' ': run/stop simulation")
        print("'a': run/stop animation")
        print("'[' and ']': play one frame backward and forward")

        # Init glut
        GLUT.glutInit(())
        GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA |
                                 GLUT.GLUT_DOUBLE |
                                 GLUT.GLUT_MULTISAMPLE |
                                 GLUT.GLUT_ALPHA |
                                 GLUT.GLUT_DEPTH)
        GLUT.glutInitWindowSize(*self.window_size)
        GLUT.glutInitWindowPosition(0, 0)
        self.window = GLUT.glutCreateWindow(self.title)

        # Init functions
        # glutFullScreen()
        GLUT.glutDisplayFunc(self.drawGL)
        GLUT.glutIdleFunc(self.idle)
        GLUT.glutReshapeFunc(self.resizeGL)
        GLUT.glutKeyboardFunc(self.keyPressed)
        GLUT.glutMouseFunc(self.mouseFunc)
        GLUT.glutMotionFunc(self.motionFunc)
        GLUT.glutTimerFunc(25, self.renderTimer, 1)
        self.initGL(*self.window_size)

        # Run
        GLUT.glutMainLoop()
Exemplo n.º 8
0
    def main(self): 
        self.location = np.array([0.0,0.0,1500.0])
        self.focus = np.array([0.0,0.0,0.0])
        self.up = np.array([1.0,0.0,0.0])

        self.mousex = 0
        self.mousey = 0
        self.mouse_drag = gl.GL_FALSE

        # Wire up GL
        glut.glutInit(sys.argv)

        glut.glutInitDisplayMode(glut.GLUT_RGB | glut.GLUT_DOUBLE | glut.GLUT_DEPTH)
        glut.glutInitWindowSize(500,500)
        glut.glutInitWindowPosition(10,10)
        glut.glutCreateWindow("Laspy+OpenGL Pointcloud")
        glut.glutDisplayFunc(self.display)
        glut.glutReshapeFunc(self.reshape)
        glut.glutMouseFunc(self.mouse)
        glut.glutMotionFunc(self.mouse_motion)
        glut.glutKeyboardFunc(self.keyboard)
        gl.glClearColor(0.0,0.0,0.0,1.0)
        glut.glutTimerFunc(10,self.timerEvent,1)

        glut.glutMainLoop()
        return 0
Exemplo n.º 9
0
    def __init__(self, wWidth, wHeight, filename):
        global g_rs, g_nx, g_ny, g_msecs

        g_rs = PVReadSparse(filename)
        g_nx = g_rs.nx
        g_ny = g_rs.ny

        glut.glutInit(sys.argv)
        glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DOUBLE
                                 | glut.GLUT_DEPTH)
        glut.glutInitWindowSize(wWidth, wHeight)
        glut.glutInitWindowPosition(0, 0)
        window = glut.glutCreateWindow("PetaVision Activity")
        gl.glTranslatef(-1.0, 1.0, -2.5)

        # register callbacks
        glut.glutReshapeFunc(reSizeGLScene)
        glut.glutTimerFunc(g_msecs, getNextRecord, 1)
        glut.glutDisplayFunc(drawGLScene)
        glut.glutKeyboardFunc(keyPressed)

        print "nx==", g_nx
        print "ny==", g_ny

        self.initGL(wWidth, wHeight)
Exemplo n.º 10
0
    def run(self):
        glut.glutInit(sys.argv)
        glut.glutInitWindowSize(500, 500)
        glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DOUBLE | glut.GLUT_DEPTH)
        self.win = glut.glutCreateWindow(b'Molecular visualizer')

        glut.glutDisplayFunc(self.display)
        glut.glutReshapeFunc(self.reshape)
        glut.glutKeyboardFunc(self.keyboard)
        glut.glutMotionFunc(self.rotate)
        glut.glutMouseFunc(self.mouse)

        gl.glClearColor(0, 0, 0, 1)
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glEnable(gl.GL_LIGHTING)
        gl.glEnable(gl.GL_LIGHT0)

        gl.glColorMaterial(gl.GL_FRONT, gl.GL_DIFFUSE)
        gl.glEnable(gl.GL_COLOR_MATERIAL)

        # very diffuse and dark specular highlights, to make black visible
        gl.glMaterial(gl.GL_FRONT, gl.GL_SPECULAR, (.1, .1, .1, 1))
        gl.glMaterial(gl.GL_FRONT, gl.GL_SHININESS, 5)

        self.displist = gl.glGenLists(1)
        gl.glNewList(self.displist, gl.GL_COMPILE)
        self.draw_atoms(self.molecule)
        gl.glEndList()

        glut.glutMainLoop()
Exemplo n.º 11
0
def visualizeGraph(V1, G1, C1, S1):

    #Assign
    global V
    global G
    global C
    global S
    V = V1
    G = G1
    C = C1
    S = S1

    #Take Log
    S = numpy.log(S + 1)

    #Init Glut
    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB
                             | glut.GLUT_DEPTH)
    glut.glutInitWindowSize(1024, 1024)
    glut.glutCreateWindow("Visualize (GLUT)")
    glut.glutDisplayFunc(on_display)
    glut.glutKeyboardFunc(on_keyboard)
    glut.glutReshapeFunc(on_reshape)

    #Lookat
    gluLookAt(0, 12, 0, 0, 0, 0, 0, 0, 1)

    #Idle function
    glut.glutIdleFunc(on_idle)
    glut.glutFullScreen()
    glut.glutMainLoop()
Exemplo n.º 12
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()
Exemplo n.º 13
0
def main():
    window_width = 600
    window_height = 600

    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(
        cast(int, glut.GLUT_RGB) | cast(int, glut.GLUT_SINGLE)
        | cast(int, glut.GLUT_DEPTH))
    glut.glutInitWindowSize(window_width, window_height)  # window size
    glut.glutInitWindowPosition(100, 100)  # window position
    glut.glutCreateWindow("mmdpy")  # show window
    glut.glutDisplayFunc(display)  # draw callback function
    # glut.glutIdleFunc(display)
    glut.glutReshapeFunc(reshape)  # resize callback function

    parser = argparse.ArgumentParser(description="MMD model viewer sample.")
    parser.add_argument("-p", type=str, help="MMD model file name.")
    parser.add_argument("-v", type=str, help="MMD motion file name.")
    parser.add_argument("--bone",
                        type=bool,
                        default=False,
                        help="Print bone informations.")
    args = parser.parse_args()

    model_name = args.p
    motion_name = args.v
    global bone_information
    bone_information = args.bone
    print(model_name)
    print(motion_name)
    init(window_width, window_height, model_name, motion_name)

    glut.glutTimerFunc(1000 // FPS, event, 0)
    glut.glutMainLoop()
Exemplo n.º 14
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()
Exemplo n.º 15
0
    def init(self):
        if not self.__is_initialized:
            self.__is_initialized = True
            sys.argv = glut.glutInit(sys.argv)
            glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH)
            self.__windowsize = (400,400)
            glut.glutInitWindowSize(self.__windowsize[0],self.__windowsize[1])
            glut.glutCreateWindow(self.__name)

            gl.glShadeModel(gl.GL_SMOOTH)
            gl.glEnable(gl.GL_CULL_FACE)
            gl.glEnable(gl.GL_DEPTH_TEST)
            gl.glEnable(gl.GL_LIGHTING)

            glut.glutDisplayFunc(self.__display)
            glut.glutMouseFunc(self.__onMouse)
            glut.glutMotionFunc(self.__onMouseMotion)
            glut.glutMouseWheelFunc(self.__onWheel)
            glut.glutReshapeFunc(self.__onReshape)

            self.__onReshape(400,400)
            def sleep_forever():
                self.__am_slow = False
                if not self._window_closed:
                    print('program complete, but still running visualization...')
                    while True:
                        glut.glutMainLoopEvent()
            atexit.register(sleep_forever)
Exemplo n.º 16
0
    def run(self):
        glut.glutInit(sys.argv)
        glut.glutInitWindowSize(500, 500)
        glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DOUBLE
                                 | glut.GLUT_DEPTH)
        self.win = glut.glutCreateWindow(b'Molecular visualizer')

        glut.glutDisplayFunc(self.display)
        glut.glutReshapeFunc(self.reshape)
        glut.glutKeyboardFunc(self.keyboard)
        glut.glutMotionFunc(self.rotate)
        glut.glutMouseFunc(self.mouse)

        gl.glClearColor(0, 0, 0, 1)
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glEnable(gl.GL_LIGHTING)
        gl.glEnable(gl.GL_LIGHT0)

        gl.glColorMaterial(gl.GL_FRONT, gl.GL_DIFFUSE)
        gl.glEnable(gl.GL_COLOR_MATERIAL)

        # very diffuse and dark specular highlights, to make black visible
        gl.glMaterial(gl.GL_FRONT, gl.GL_SPECULAR, (.1, .1, .1, 1))
        gl.glMaterial(gl.GL_FRONT, gl.GL_SHININESS, 5)

        self.displist = gl.glGenLists(1)
        gl.glNewList(self.displist, gl.GL_COMPILE)
        self.draw_atoms(self.molecule)
        gl.glEndList()

        glut.glutMainLoop()
Exemplo n.º 17
0
def main():
    global window
    # For now we just pass glutInit one empty argument. I wasn't sure what should or could be passed in (tuple, list, ...)
    # Once I find out the right stuff based on reading the PyOpenGL source, I'll address this.
    lutAsString = buildBitsLUT()
    GLUT.glutInit([])
    GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE
                             | GLUT.GLUT_ALPHA | GLUT.GLUT_DEPTH)

    # get a 640 x 480 window
    GLUT.glutInitWindowSize(800, 600)

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

    window = GLUT.glutCreateWindow(
        "Jeff Molofee's GL Code Tutorial ... NeHe '99")
    # glutFullScreen()
    #register callbacks
    GLUT.glutIdleFunc(DrawGLScene)
    GLUT.glutReshapeFunc(ReSizeGLScene)
    GLUT.glutKeyboardFunc(keyPressed)
    GLUT.glutDisplayFunc(DrawGLScene)

    InitGL(800, 600)

    GLUT.glutMainLoop()
Exemplo n.º 18
0
    def gl_init(self):
        # sys.stderr.write("Starting GLUTContext.gl_init\n")
        if self is not GLUTContext._default_instance:
            # sys.stderr.write("Making a GLUT window.\n")
            GLUT.glutInitWindowSize(self._width, self._height)
            GLUT.glutInitWindowPosition(0, 0)
            self.window = GLUT.glutCreateWindow(
                bytes(self._title, encoding="UTF-8"))
        GLUT.glutSetWindow(self.window)
        GLUT.glutMouseFunc(lambda button, state, x, y: self.
                           mouse_button_handler(button, state, x, y))
        GLUT.glutReshapeFunc(
            lambda width, height: self.resize2d(width, height))
        GLUT.glutDisplayFunc(lambda: self.draw())
        GLUT.glutVisibilityFunc(
            lambda state: self.window_visibility_handler(state))
        # Right now, the timer just prints FPS
        GLUT.glutTimerFunc(0, lambda val: self.timer(val), 0)
        GLUT.glutCloseFunc(lambda: self.cleanup())

        for coltype in object_collection.GLObjectCollection.collection_classes:
            self.object_collections.append(
                object_collection.GLObjectCollection.
                collection_classes[coltype](self))
        # self.object_collections.append(object_collection.SimpleObjectCollection(self))
        # self.object_collections.append(object_collection.CurveCollection(self))

        self.window_is_initialized = True
        GLUTContext._instances.append(self)
Exemplo n.º 19
0
def main():
    light_position = (7, 2, 1)    
    GLUT.glutInit(argv)
    GLUT.glutInitDisplayMode(GLUT.GLUT_DOUBLE | GLUT.GLUT_RGBA | GLUT.GLUT_DEPTH | GLUT.GLUT_MULTISAMPLE)
    larguraTela = GLUT.glutGet(GLUT.GLUT_SCREEN_WIDTH)
    alturaTela = GLUT.glutGet(GLUT.GLUT_SCREEN_HEIGHT)
    larguraJanela = round(2 * larguraTela / 3)
    alturaJanela = round(2 * alturaTela / 3)
    GLUT.glutInitWindowSize(larguraJanela, alturaJanela)
    GLUT.glutInitWindowPosition(round((larguraTela - larguraJanela) / 2), round((alturaTela - alturaJanela) / 2))
    GLUT.glutCreateWindow(janela)
    GLUT.glutReshapeFunc(reshape)
    GLUT.glutDisplayFunc(draw)
    GLUT.glutMouseFunc(clique)
    GL.glShadeModel(GL.GL_SMOOTH)
    GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, dados[0][0])
    GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, dados[0][1])
    GL.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, dados[0][2])
    GL.glMaterialfv(GL.GL_FRONT, GL.GL_SHININESS, dados[0][3])
    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(*corFundo)
    GLU.gluPerspective(45, larguraJanela / alturaJanela, 0.1, 50.0)
    GLUT.glutTimerFunc(50, timer, 1)
    GLUT.glutMainLoop()
Exemplo n.º 20
0
Arquivo: _glut.py Projeto: 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()
Exemplo n.º 21
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()
Exemplo n.º 22
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()
Exemplo n.º 23
0
    def __init__(self,
                 width: int,
                 height: int,
                 title: str,
                 camera: bool = False):
        self.__Daytime = True
        self.__enableCamera = camera

        glut.glutInit()
        glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
        glut.glutInitWindowSize(width, height)
        glut.glutInitWindowPosition(0, 0)
        glut.glutCreateWindow(title)
        glut.glutReshapeFunc(self.__window_resize)
        glut.glutDisplayFunc(self.__display)
        glut.glutKeyboardFunc(self.__keyboardDown)
        glut.glutKeyboardUpFunc(self.__keyboardUp)
        glut.glutMotionFunc(self.__mouse_look_clb)

        self._create_shader()
        self.setSky(True)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        self.__ElementsList = []
        self.__camera = Camera()
        self.__lastX = width / 2
        self.__lastY = height / 2
        self.__first_mouse = True
        self.__left = False
        self.__right = False
        self.__forward = False
        self.__backward = False
Exemplo n.º 24
0
def Visualization(title, drawScene=DrawGLScene, width=320, height=200,
        handleKey=None):
    global window, _DrawCurrentSceneFunc, _KeyHandlerFunc
    GLUT.glutInit(sys.argv)

    _DrawCurrentSceneFunc = drawScene

    if handleKey:
        _KeyHandlerFunc = handleKey

    # 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(640, 480)

    # the window starts at the upper left corner of the screen
    GLUT.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 = GLUT.glutCreateWindow(title)

    # 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.
    GLUT.glutDisplayFunc(DrawGLScene)

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

    # When we are doing nothing, redraw the scene.
    GLUT.glutIdleFunc(DrawGLScene)

    # Register the function called when our window is resized.
    GLUT.glutReshapeFunc(ReSizeGLScene)

    # Register the function called when the keyboard is pressed.
    GLUT.glutKeyboardFunc(keyPressed)

    # Register the function called when the mouse is pressed.
    GLUT.glutMouseFunc(mousePressed)

    # Register the function called when the mouse is pressed.
    GLUT.glutMotionFunc(mouseMoved)

    # Initialize our window.
    InitGL(640, 480)

    # Start Event Processing Engine
    GLUT.glutMainLoop()
Exemplo n.º 25
0
    def __init__(self, geos, vertex_code, fragment_code):
        self.time = time.time()
        num_vertices = np.sum([len(g) for g in geos])
        data = np.zeros(num_vertices, [("position", np.float32, 2),
                                       ("color", np.float32, 4)])
        cs = []
        vs = []
        for g in geos:
            for c in g.colors:
                cs.append(c)
            for v in g.vertices:
                vs.append(v)
        data["color"] = cs
        data["position"] = vs
        data["position"] = 0.5 * data["position"]
        self.data = data
        glut.glutInit()
        glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
        glut.glutCreateWindow("Hello world!")
        glut.glutReshapeWindow(512, 512)
        glut.glutReshapeFunc(self.reshape)
        glut.glutDisplayFunc(self.display)
        glut.glutIdleFunc(self.idle)
        glut.glutKeyboardFunc(self.keyboard)
        glut.glutMouseFunc(self.mouse)

        program = gl.glCreateProgram()
        vertex = gl.glCreateShader(gl.GL_VERTEX_SHADER)
        fragment = gl.glCreateShader(gl.GL_FRAGMENT_SHADER)
        gl.glShaderSource(vertex, vertex_code)
        gl.glShaderSource(fragment, fragment_code)
        gl.glCompileShader(vertex)
        gl.glCompileShader(fragment)
        gl.glAttachShader(program, vertex)
        gl.glAttachShader(program, fragment)
        gl.glLinkProgram(program)
        gl.glDetachShader(program, vertex)
        gl.glDetachShader(program, fragment)
        gl.glUseProgram(program)
        self.buffer = gl.glGenBuffers(1)
        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.buffer)
        gl.glBufferData(gl.GL_ARRAY_BUFFER, self.data.nbytes, self.data,
                        gl.GL_DYNAMIC_DRAW)
        stride = self.data.strides[0]
        offset = ctypes.c_void_p(0)
        loc = gl.glGetAttribLocation(program, "position")
        gl.glEnableVertexAttribArray(loc)
        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.buffer)
        gl.glVertexAttribPointer(loc, 2, gl.GL_FLOAT, False, stride, offset)

        offset = ctypes.c_void_p(self.data.dtype["position"].itemsize)
        loc = gl.glGetAttribLocation(program, "color")
        gl.glEnableVertexAttribArray(loc)
        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.buffer)
        gl.glVertexAttribPointer(loc, 4, gl.GL_FLOAT, False, stride, offset)
        loc = gl.glGetUniformLocation(program, "scale")
        gl.glUniform1f(loc, 1.0)
Exemplo n.º 26
0
def interaction(disp=display,resh=reshape, key=keyboard):    

    global mi
    mi=mouse.MouseInteractor(.01,0.02)
    mi.registerCallbacks( )

    glut.glutDisplayFunc(disp)
    glut.glutReshapeFunc(resh)
    glut.glutKeyboardFunc(key)
Exemplo n.º 27
0
def init_glut():
    glut.glutInit()
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
    glut.glutCreateWindow('')
    glut.glutReshapeWindow(RESOLUTION[0], RESOLUTION[1])
    glut.glutReshapeFunc(reshape)
    glut.glutDisplayFunc(display)
    glut.glutKeyboardFunc(keyboard)
    glut.glutTimerFunc(0, timer, 0)
Exemplo n.º 28
0
def main():
    glut.glutInit()
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
    glut.glutCreateWindow('Hello world!')
    glut.glutReshapeWindow(512, 512)
    glut.glutReshapeFunc(reshape)
    glut.glutDisplayFunc(display)
    glut.glutKeyboardFunc(keyboard)
    glut.glutMainLoop()
Exemplo n.º 29
0
def interaction(disp=display, resh=reshape, key=keyboard):

    global mi
    mi = mouse.MouseInteractor(.01, 0.02)
    mi.registerCallbacks()

    glut.glutDisplayFunc(disp)
    glut.glutReshapeFunc(resh)
    glut.glutKeyboardFunc(key)
Exemplo n.º 30
0
 def init_glut(self):
     glut.glutInit()
     glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
     glut.glutCreateWindow('')
     glut.glutReshapeWindow(self.resolution[0], self.resolution[1])
     glut.glutReshapeFunc(self.reshape)
     glut.glutDisplayFunc(self.display)
     glut.glutKeyboardFunc(self.keyboard)
     glut.glutTimerFunc(0, self.timer, 0)
Exemplo n.º 31
0
    def init(self):
        # Initialize display
        global global_init
        if not global_init:
            glut.glutInit()
            glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA
                                     | glut.GLUT_DEPTH | glut.GLUT_ALPHA)
            glut.glutCreateWindow(b'fbmatrix')
            global_init = True

        if self.preview or self.raw:
            glut.glutReshapeWindow(512, 512)
        elif self.emulate:
            glut.glutReshapeWindow(1024, 512)

        glut.glutReshapeFunc(lambda w, h: self.reshape(w, h))
        glut.glutDisplayFunc(lambda: self.display())
        glut.glutKeyboardFunc(lambda k, x, y: self.keyboard(k, x, y))

        # Primary offscreen framebuffer
        self.mainfbo = fbo.FBO(self.columns,
                               32,
                               mag_filter=gl.GL_NEAREST,
                               min_filter=gl.GL_NEAREST)

        # Initialize display shader
        layoutfile = 'layout.json'

        if self.displaytype == 'ws2811':
            self.signalgenerator = displays.ws2811.signalgenerator(
                layoutfile, supersample=self.supersample)
            self.signalgenerator.setTexture(self.mainfbo.getTexture())
        elif self.displaytype == 'hub75e':
            self.signalgenerator = displays.hub75e.signalgenerator(
                columns=self.columns,
                rows=self.rows,
                supersample=self.supersample,
                order=self.order,
                oe=self.oe,
                extract=self.extract)
            self.signalgenerator.setTexture(self.mainfbo.getTexture())

        # Emulation shader
        if self.emulate or self.preview:
            self.texquad = geometry.simple.texquad()
            self.texquad.setTexture(self.mainfbo.getTexture())

        # Tree emulator
        if self.emulate:
            self.tree = assembly.tree.tree(layoutfile)
            self.tree.setTexture(self.mainfbo.getTexture())

        # Render
        glut.glutSetCursor(glut.GLUT_CURSOR_NONE)
        if not self.raw and not self.preview and not self.emulate:
            glut.glutFullScreen()
Exemplo n.º 32
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)
Exemplo n.º 33
0
    def __init__(self, geos, vertex_code, fragment_code):
        self.time = time.time()
        num_vertices = np.sum([len(g) for g in geos])
        data = np.zeros(num_vertices, [("position", np.float32, 2),
                            ("color",    np.float32, 4)])
        cs = []
        vs = []
        for g in geos:
            for c in g.colors:
                cs.append(c)
            for v in g.vertices:
                vs.append(v)
        data["color"] = cs
        data["position"] = vs
        data["position"] = 0.5 * data["position"]
        self.data = data
        glut.glutInit()
        glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
        glut.glutCreateWindow("Hello world!")
        glut.glutReshapeWindow(512,512)
        glut.glutReshapeFunc(self.reshape)
        glut.glutDisplayFunc(self.display)
        glut.glutIdleFunc(self.idle)
        glut.glutKeyboardFunc(self.keyboard)
        glut.glutMouseFunc(self.mouse)

        program  = gl.glCreateProgram()
        vertex   = gl.glCreateShader(gl.GL_VERTEX_SHADER)
        fragment = gl.glCreateShader(gl.GL_FRAGMENT_SHADER)
        gl.glShaderSource(vertex, vertex_code)
        gl.glShaderSource(fragment, fragment_code)
        gl.glCompileShader(vertex)
        gl.glCompileShader(fragment)
        gl.glAttachShader(program, vertex)
        gl.glAttachShader(program, fragment)
        gl.glLinkProgram(program)
        gl.glDetachShader(program, vertex)
        gl.glDetachShader(program, fragment)
        gl.glUseProgram(program)
        self.buffer = gl.glGenBuffers(1)
        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.buffer)
        gl.glBufferData(gl.GL_ARRAY_BUFFER, self.data.nbytes, self.data, gl.GL_DYNAMIC_DRAW)
        stride = self.data.strides[0]
        offset = ctypes.c_void_p(0)
        loc = gl.glGetAttribLocation(program, "position")
        gl.glEnableVertexAttribArray(loc)
        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.buffer)
        gl.glVertexAttribPointer(loc, 2, gl.GL_FLOAT, False, stride, offset)

        offset = ctypes.c_void_p(self.data.dtype["position"].itemsize)
        loc = gl.glGetAttribLocation(program, "color")
        gl.glEnableVertexAttribArray(loc)
        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.buffer)
        gl.glVertexAttribPointer(loc, 4, gl.GL_FLOAT, False, stride, offset)
        loc = gl.glGetUniformLocation(program, "scale")
        gl.glUniform1f(loc, 1.0)
Exemplo n.º 34
0
 def initAndRunDevice(templateGlutSystem):
     glut.glutInit()
     glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
     glut.glutCreateWindow(b'raVEngine_py')
     glut.glutReshapeWindow(512, 512)
     glut.glutReshapeFunc(reshape)
     glut.glutDisplayFunc(templateGlutSystem.display)
     glut.glutKeyboardFunc(keyboard)
     glut.glutMotionFunc(mouse)
     glut.glutIdleFunc(templateGlutSystem.combineUpdateAndDisplay)
     glut.glutMainLoop()
Exemplo n.º 35
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()
Exemplo n.º 36
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)
Exemplo n.º 37
0
def main():
    glut.glutInit()

    glut.glutInitWindowSize(100, 100)
    glut.glutCreateWindow('Mehdi')

    init()
    glut.glutDisplayFunc(display)
    glut.glutReshapeFunc(resize(100, 100))

    glut.glutMainLoop()
Exemplo n.º 38
0
    def _init_glut(self, time):

        if type(time) != bytes:
            raise TypeError

        glut.glutInit()
        glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
        glut.glutCreateWindow(time)
        glut.glutReshapeWindow(700, 700)
        glut.glutReshapeFunc(self.set_window_size)
        glut.glutDisplayFunc(self._display)
        glut.glutKeyboardFunc(self._keyboard)
Exemplo n.º 39
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()
Exemplo n.º 40
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()
Exemplo n.º 41
0
    def handler(self, h):
        self._handler = h

        # mapping
        glt.glutMouseFunc(h.onMouseClicked)
        glt.glutReshapeFunc(h.onReshape)
        glt.glutKeyboardFunc(h.onKeyPress)

        # create menu
        glt.glutCreateMenu(h.onMenuClick)
        for k, v in h.menuItems.items():
            glt.glutAddMenuEntry(k, v)
        glt.glutAttachMenu(glt.GLUT_RIGHT_BUTTON)
Exemplo n.º 42
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()
Exemplo n.º 43
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()
Exemplo n.º 44
0
    def __init__(self, limit_fps=100, show_fps=True, window_name='GlutWindow', size=np.asarray([768, 512])):
        self.limit_fps = limit_fps
        self.show_fps = show_fps
        self.window_name = window_name
        self.window_size = size

        glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
        glut.glutInitWindowPosition(*GlutWindow.allocate_window_position(self.window_size))
        self.window_handle = glut.glutCreateWindow(self.window_name)
        glut.glutReshapeWindow(*self.window_size)
        glut.glutReshapeFunc(self.reshape)
        glut.glutDisplayFunc(self.display)
        glut.glutKeyboardFunc(self.keyboard)
Exemplo n.º 45
0
def initGlut():
    glut.glutInit()
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA
                             | glut.GLUT_DEPTH)
    glut.glutInitWindowSize(canvasWidth, canvasHeight)
    glut.glutInitWindowPosition(100, 100)
    glut.glutCreateWindow('Particles')
    glut.glutDisplayFunc(displayCallback)
    glut.glutIdleFunc(displayCallback)
    glut.glutReshapeFunc(reshapeCallback)
    glut.glutKeyboardFunc(keyboardCallback)
    logging.info("Finished Setting Up Glut Loop")
    glut.glutMainLoop()
Exemplo n.º 46
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
Exemplo n.º 47
0
    def initialize(self):
        glut.glutInit()
        glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DOUBLE | glut.GLUT_DEPTH)
        glut.glutInitWindowSize(self.width,self.height)
        glut.glutInitWindowPosition(300,300)
        glut.glutCreateWindow("super black hole sunshine party")
        glut.glutDisplayFunc(self.paintGL)
        glut.glutIdleFunc(self.paintGL)
        glut.glutReshapeFunc(self.resizeGL)
        self.initGL()

        self.inputHandler.attachGLUT()

        glut.glutMainLoop()
Exemplo n.º 48
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)
Exemplo n.º 49
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)
Exemplo n.º 50
0
Arquivo: scene.py Projeto: arokem/Fos
    def interaction(self):
        
        
        glut.glutDisplayFunc(self.disp)
        glut.glutReshapeFunc(self.resh)
        glut.glutKeyboardFunc(self.key)

        transl_scale,rotation_scale=self.mouse_scale
        self.mouse=mouse.MouseInteractor(transl_scale,rotation_scale)

        #registers both glutMouseFunc and glutMotionFunc
        
        self.mouse.registerCallbacks()
        if self.autostart_timer1:
            glut.glutTimerFunc(self.timer1Dt,self.timer1,1) 
        if self.autostart_timer2:
            glut.glutTimerFunc(self.timer2Dt,self.timer2,1) 
Exemplo n.º 51
0
  def __init__(
      self,
      update_callback = _EmptyOneArgCallback,
      display_callback = _EmptyZeroArgCallback,
      init_callback = _EmptyZeroArgCallback,
      key_callback = _EmptyThreeArgCallback,
      window_name = 'viewer',
      window_size = (640, 480),
      frame_rate = 60,
      clear_color = (0.0, 0.0, 0.0, 1.0),
      field_of_view = 45.0,
      ):
    self.update_callback = update_callback
    self.display_callback = display_callback
    self.key_callback = key_callback

    self.ms_per_frame = int(1000.0 / frame_rate)
    self.field_of_view = field_of_view

    GLUT.glutInit()
    GLUT.glutInitWindowSize(*window_size)
    GLUT.glutInitDisplayMode(GLUT.GLUT_DOUBLE | GLUT.GLUT_RGB | GLUT.GLUT_DEPTH)
    GLUT.glutCreateWindow(window_name)
    GLUT.glutDisplayFunc(self.Display)
    GLUT.glutKeyboardFunc(self.Key)
    GLUT.glutReshapeFunc(self.Reshape)
    GLUT.glutMouseFunc(self.Mouse)
    GLUT.glutMotionFunc(self.Motion)
    GLUT.glutPassiveMotionFunc(self.PassiveMotion)

    GL.glEnable(GL.GL_DEPTH_TEST)
    GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)
    GL.glClearColor(*clear_color)
    self.Reshape(*window_size)

    self.camera_theta = 0.0
    self.camera_phi = 0.0
    self.camera_r = 10.0
    self.camera_center = numpy.array((0.0, 0.0, 0.0))
    self.UpdateCameraRotationMatrix()

    self.mouse_drag_mode = None

    init_callback()
Exemplo n.º 52
0
    def init_glut(self, args):
        """Initialize the GLUT state."""

        # Initialize GLUT.
        GLUT.glutInit(args)

        GLUT.glutInitContextVersion(
            self.context_version[0], self.context_version[1])
        GLUT.glutInitContextFlags(GLUT.GLUT_FORWARD_COMPATIBLE)
        GLUT.glutInitContextProfile(GLUT.GLUT_CORE_PROFILE)

        GLUT.glutSetOption(
            GLUT.GLUT_ACTION_ON_WINDOW_CLOSE,
            GLUT.GLUT_ACTION_GLUTMAINLOOP_RETURNS)

        # Initialize and create the main window.
        GLUT.glutInitDisplayMode(
            GLUT.GLUT_DOUBLE | GLUT.GLUT_RGBA | GLUT.GLUT_DEPTH)
        GLUT.glutInitWindowSize(
            self.window_size[0], self.window_size[1])
        GLUT.glutInitWindowPosition(
            self.window_position[0], self.window_position[1])
        GLUT.glutCreateWindow(self.window_title)

        GLUT.glutDisplayFunc(self.render)
        GLUT.glutIdleFunc(self.idle)
        GLUT.glutReshapeFunc(self.resize)
        GLUT.glutKeyboardFunc(self.keyboard)
        GLUT.glutTimerFunc(0, self.timer, 0)
        GLUT.glutMouseFunc(self.mouse)
        GLUT.glutMotionFunc(self.motion)
        GLUT.glutCloseFunc(self.cleanup)

        aspects = [('Vendor', GL.GL_VENDOR),
                   ('Renderer', GL.GL_RENDERER),
                   ('Version', GL.GL_VERSION),]
        if self.context_version[0] > 1:
            aspects.append(('GLSL', GL.GL_SHADING_LANGUAGE_VERSION))

        for i in aspects:
            print('{}: {}'.format(i[0],
                                  GL.glGetString(i[1]).decode()),
                  file=sys.stderr, flush=True)
Exemplo n.º 53
0
 def run(self):
     glut.glutInit()
     glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DOUBLE
                                 | glut.GLUT_ALPHA | glut.GLUT_DEPTH)
     glut.glutInitWindowSize(self.window_width, self.window_height)
     
     self.window = glut.glutCreateWindow("Point cloud test")
     
     glut.glutDisplayFunc(self.display_base)
     glut.glutIdleFunc(self.display_base)
     glut.glutReshapeFunc(self.resize_event)
     glut.glutKeyboardFunc(self.keyboard_press_event)
     glut.glutKeyboardUpFunc(self.keyboard_up_event)
     glut.glutMouseFunc(self.mouse_button_event)
     glut.glutMotionFunc(self.mouse_moved_event)
     
     self.init_gl(self.window_width, self.window_height)
     
     glut.glutMainLoop()
Exemplo n.º 54
0
    def main(self, neuronObject, displaysize=(800, 600), radius=5, poly=True,
             fast=False, multisample=True, graph=True):

        self.poly = poly
        self.displaysize = displaysize
        self.graph = graph

        title = 'btmorph OpenGL Viewer'

        GLUT.glutInit(sys.argv)
        if multisample:
            GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE)
        else:
            GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA |
                                     GLUT.GLUT_DOUBLE |
                                     GLUT.GLUT_MULTISAMPLE)
        GLUT.glutInitWindowSize(self.displaysize[0], self.displaysize[1])
        GLUT.glutInitWindowPosition(50, 50)
        GLUT.glutCreateWindow(title)
        GLUT.glutDisplayFunc(self.display)
        GLUT.glutReshapeFunc(self.reshape)
        GLUT.glutMouseFunc(self.mouse)
        GLUT.glutMotionFunc(self.mouseMove)
        GLUT.glutMouseWheelFunc(self.mouseWheel)
        GLUT.glutKeyboardFunc(self.keyDown)
        GLUT.glutKeyboardUpFunc(self.keyUp)

        mb = modelbuilder()
        self.root, self.vertices_gl, self.colors_gl, self.Neuron = \
            mb.build(neuronObject, self.poly, 100, fast)
        if graph:
            self.gb = graphbuilder()
            self.Graph, mid = \
                self.gb.build(neuronObject, scalefactor=100)

        self.initGL(multisample)
        self.camera.rad = radius
        self.camera.focus = mid

        while self.running:
            GLUT.glutMainLoopEvent()

        GLUT.glutDestroyWindow(GLUT.glutGetWindow())
Exemplo n.º 55
0
    def init(self, w=None, h=None):
        if w:   self.width = w
        if h:   self.height = h

        try:
            glut.glutInit()
        except Exception as e:
            print(e)
            sys.exit()

        if pl.system() == 'Darwin': #Darwin: OSX
            glut.glutInitDisplayString('double rgba samples=8 core depth')
        else:   #Other: Linux
            try:
                glut.glutInitDisplayMode(
                        glut.GLUT_DOUBLE | \
                        glut.GLUT_RGBA | \
                        glut.GLUT_MULTISAMPLE | \
                        glut.GLUT_DEPTH)
            except Exception as e:
                print('Issue detected')
                print(e)
                sys.exit()
        glut.glutInitWindowSize (self.width, self.height)
        glut.glutCreateWindow (self.label)

        self.handler.init()

        glut.glutDisplayFunc(self.display)
        glut.glutKeyboardFunc(self.on_key_press)
        glut.glutMouseFunc(self.on_mouse_click)
        glut.glutMotionFunc(self.on_mouse_motion)
        glut.glutPassiveMotionFunc(self.on_mouse_motion)
        glut.glutReshapeFunc(self.on_resize)

        self.last_glut_idle_time = time.time()
        glut.glutIdleFunc(self.on_glut_idle)
        if self.streamed:
            # sakura core defines the main program loop,
            # so we have to run GLUT's own loop in another
            # greenlet.
            self.spawn_greenlet_loop()
Exemplo n.º 56
0
	def __init__( self, mesh, width=1024, height=768 ) :
		# Initialise OpenGL / GLUT
		glut.glutInit()
		glut.glutInitDisplayMode( glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH | glut.GLUT_MULTISAMPLE )
		glut.glutInitWindowSize( width, height )
		glut.glutInitWindowPosition( 100, 100 )
		glut.glutCreateWindow( mesh.name )
		# Mesh viewer
		self.meshviewer = mtk.MeshViewer()
		self.meshviewer.InitialiseOpenGL( width, height )
		self.meshviewer.LoadMesh( mesh )
		self.antialiasing = True
		# GLUT function binding
		glut.glutCloseFunc( self.meshviewer.Close )
		glut.glutDisplayFunc( self.Display )
		glut.glutIdleFunc( self.Idle )
		glut.glutKeyboardFunc( self.Keyboard )
		glut.glutMouseFunc( self.Mouse )
		glut.glutMotionFunc( self.meshviewer.trackball.MouseMove )
		glut.glutReshapeFunc( self.meshviewer.Resize )