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()
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()
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()
def visibility_cb(vis): # stop drawing if window not visible if vis: game.reset_timer() GLUT.glutIdleFunc(idle_cb) else: GLUT.glutIdleFunc(None)
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()
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()
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()
def initOpenGLMatrix(self): # FROM http://code.activestate.com/recipes/325391-open-a-glut-window-and-draw-a-sphere-using-pythono/ glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DOUBLE | glut.GLUT_DEPTH) glut.glutInitWindowSize(400, 400) glut.glutCreateWindow(b'PyTowerDefense') gl.glClearColor(0., 0., 0., 1.) gl.glShadeModel(gl.GL_SMOOTH) gl.glEnable(gl.GL_CULL_FACE) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_LIGHTING) gl.lightZeroPosition = [100., 40., 100., 1.] gl.lightZeroColor = [0.8, 1.0, 0.8, 1.0] #green tinged gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, gl.lightZeroPosition) gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, gl.lightZeroColor) gl.glLightf(gl.GL_LIGHT0, gl.GL_CONSTANT_ATTENUATION, 0.01) gl.glLightf(gl.GL_LIGHT0, gl.GL_LINEAR_ATTENUATION, 0.005) gl.glEnable(gl.GL_LIGHT0) glut.glutDisplayFunc(self.paint) glut.glutIdleFunc(self.repaint) gl.glMatrixMode(gl.GL_PROJECTION) glu.gluPerspective(30., 1., 1., 1000.) gl.glMatrixMode(gl.GL_MODELVIEW) self._eyePosition = Point3D("Camera Eye Location").translate(0, 0, 400) self._watchingPosition = Point3D("Camera Watching Position") self._upVector = Point3D("Camera Up Vector").translate(0, 1, 0) glu.gluLookAt(self._eyePosition.x, self._eyePosition.y, self._eyePosition.z, self._watchingPosition.x, self._watchingPosition.y, self._watchingPosition.z, self._upVector.x, self._upVector.y, self._upVector.z) gl.glPushMatrix() return
def thread_main(instance): # sys.stderr.write("Starting thread_main\n") GLUT.glutInit(sys.argv) GLUT.glutInitContextVersion(3, 3) 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) GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH) # sys.stderr.write("Making default GLUT window.\n") GLUT.glutInitWindowSize(instance.width, instance.height) GLUT.glutInitWindowPosition(0, 0) instance.window = GLUT.glutCreateWindow( bytes(instance._title, encoding='UTF-8')) # Urgh.... according to the docs, I'm MUST register a display function # for any GLUT window I create. But... I don't want to do this until # later (in self.__init__). So, register a null function now, # and hope that registering a new function is an OK thing to do. GLUT.glutDisplayFunc(lambda: None) # Not sure if I want this as a timer or an idle func GLUT.glutIdleFunc(lambda: GLUTContext.class_idle()) # GLUT.glutTimerFunc(10, lambda val : GLUTContext.class_idle(), 0) sys.stderr.write("Going into GLUT.GLUT main loop.\n") GLUTContext._class_init = True GLUT.glutMainLoop()
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()
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()
def start(self): ''' Starts main loop. ''' # Start timers for i in range(len(self._timer_stack)): def func(index): handler, fps = self._timer_stack[index] t = glut.glutGet(glut.GLUT_ELAPSED_TIME) dt = (t - self._timer_date[index])/1000.0 self._timer_date[index] = t handler(dt) glut.glutTimerFunc(int(1000./fps), func, index) self._timer_date[index] = glut.glutGet(glut.GLUT_ELAPSED_TIME) fps = self._timer_stack[i][1] glut.glutTimerFunc(int(1000./fps), func, i) # Start idle only if necessary for item in self._event_stack: if 'on_idle' in item.keys(): glut.glutIdleFunc(self._idle) # Dispatch init event self.dispatch_event('on_init') if not self._interactive: glut.glutMainLoop()
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()
def initGLUT(vertex_shade_code, fragment_shader_code, texture_image): GLUT.glutInit(sys.argv) # argv,argcを渡す # 表示モード if texture_image.mode == 'RGB': GLUT.glutInitDisplayMode(GLUT.GLUT_RGB | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH) elif texture_image.mode == 'RGBA': GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH) else: # 謎のモード print(texture_image.mode) exit() window_width, window_height = texture_image.size # テクスチャサイズ = ウィンドウサイズ GLUT.glutInitWindowSize( window_width, window_height ) # the window starts at the upper left corner of the screen GLUT.glutInitWindowPosition(0, 0) GLUT.glutCreateWindow( sys.argv[0] ) ## The main drawing function. def draw(): GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glEnable( GL.GL_TEXTURE_2D ) GL.glDrawElements( GL.GL_TRIANGLES, 6, GL.GL_UNSIGNED_SHORT, np.array( indices, np.uint16 ) ) GL.glDisable(GL.GL_TEXTURE_2D) GLUT.glutSwapBuffers() GLUT.glutDisplayFunc(draw) GLUT.glutIdleFunc(drawGLScene) # When we are doing nothing, redraw the scene. initGL( vertex_shade_code, fragment_shader_code, texture_image ) # Initialize our window. GLUT.glutMainLoop() # Start Event Processing Engine
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()
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)
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 __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)
def mainloop(self, interactive=False, namespace=globals()): '''Starts main loop ''' # Start timers for i in range(len(self._timer_stack)): def func(index): handler, fps = self._timer_stack[index] t = glut.glutGet(glut.GLUT_ELAPSED_TIME) dt = (t - self._timer_date[index])/1000.0 self._timer_date[index] = t handler(dt) glut.glutTimerFunc(int(1000./fps), func, index) self._timer_date[index] = glut.glutGet(glut.GLUT_ELAPSED_TIME) fps = self._timer_stack[i][1] glut.glutTimerFunc(int(1000./fps), func, i) # Start idle only if necessary for item in self._event_stack: if 'on_idle' in item.keys(): glut.glutIdleFunc(self._idle) self.dispatch_event('on_init') # Starts non-interactive mode if not interactive: glut.glutMainLoop() sys.exit() # Starts interactive mode # Save tty mode on linux/darwin if sys.platform in ['linux2', 'darwin']: self.term_state = termios.tcgetattr(sys.stdin) namespace = namespace.copy() for key in namespace.keys(): f = namespace[key] if key[:2] == 'gl' and isinstance(namespace[key], _ctypes.CFuncPtr): namespace[key] = proxy.Proxy(f,self) def session_start(): self.shell = IPython.ipapi.make_session(namespace) self.shell.IP.interact() #mainloop() sys.exit() self.session = threading.Thread(target=session_start) self.session.start() @atexit.register def goodbye(): self.shell.IP.ask_exit() # Restore tty state on linux/darwin if sys.platform in ['linux2', 'darwin']: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, self.term_state) sys.stdout.write('\n') glut.glutTimerFunc(100, self._pop, 0) glut.glutMainLoop()
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()
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)
def init_glut(self): """ Set up window and main callback functions """ GLUT.glutInit(['Galaxy Renderer']) GLUT.glutInitDisplayMode(GLUT.GLUT_DOUBLE | GLUT.GLUT_RGB) GLUT.glutInitWindowSize(_WINDOW_SIZE[0], _WINDOW_SIZE[1]) GLUT.glutInitWindowPosition(_WINDOW_POSITION[0], _WINDOW_POSITION[1]) GLUT.glutCreateWindow(str.encode("Galaxy Renderer")) GLUT.glutDisplayFunc(self.render) GLUT.glutIdleFunc(self.update_positions)
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()
def enable(self, app=None): """DEPRECATED since IPython 5.0 Enable event loop integration with GLUT. Parameters ---------- app : ignored Ignored, it's only a placeholder to keep the call signature of all gui activation methods consistent, which simplifies the logic of supporting magics. Notes ----- This methods sets the PyOS_InputHook for GLUT, which allows the GLUT to integrate with terminal based applications like IPython. Due to GLUT limitations, it is currently not possible to start the event loop without first creating a window. You should thus not create another window but use instead the created one. See 'gui-glut.py' in the docs/examples/lib directory. The default screen mode is set to: glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH """ warn( "This function is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) import OpenGL.GLUT as glut from IPython.lib.inputhookglut import glut_display_mode, \ glut_close, glut_display, \ glut_idle, inputhook_glut if GUI_GLUT not in self.manager.apps: glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut_display_mode) # This is specific to freeglut if bool(glut.glutSetOption): glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE, glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS) glut.glutCreateWindow(sys.argv[0]) glut.glutReshapeWindow(1, 1) glut.glutHideWindow() glut.glutWMCloseFunc(glut_close) glut.glutDisplayFunc(glut_display) glut.glutIdleFunc(glut_idle) else: glut.glutWMCloseFunc(glut_close) glut.glutDisplayFunc(glut_display) glut.glutIdleFunc(glut_idle) self.manager.set_inputhook(inputhook_glut)
def initGLWindow(width, height): # init GL window GLUT.glutInit(sys.argv) GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_ALPHA | GLUT.GLUT_DEPTH) GLUT.glutInitWindowSize(width, height) GLUT.glutInitWindowPosition(0, 0) GLUT.glutCreateWindow("Hyper Dimensions v1.0 (beta)") # set callback functions GLUT.glutDisplayFunc(drawGLScene) # rendering function GLUT.glutIdleFunc(drawGLScene) # idle function GLUT.glutTimerFunc(10, updateScene, 1); GLUT.glutPassiveMotionFunc(mousePassiveMotion)
def enable(self, app=None): """DEPRECATED since IPython 5.0 Enable event loop integration with GLUT. Parameters ---------- app : ignored Ignored, it's only a placeholder to keep the call signature of all gui activation methods consistent, which simplifies the logic of supporting magics. Notes ----- This methods sets the PyOS_InputHook for GLUT, which allows the GLUT to integrate with terminal based applications like IPython. Due to GLUT limitations, it is currently not possible to start the event loop without first creating a window. You should thus not create another window but use instead the created one. See 'gui-glut.py' in the docs/examples/lib directory. The default screen mode is set to: glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH """ warn( "This function is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2, ) import OpenGL.GLUT as glut from IPython.lib.inputhookglut import glut_display_mode, glut_close, glut_display, glut_idle, inputhook_glut if GUI_GLUT not in self.manager.apps: glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut_display_mode) # This is specific to freeglut if bool(glut.glutSetOption): glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE, glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS) glut.glutCreateWindow(sys.argv[0]) glut.glutReshapeWindow(1, 1) glut.glutHideWindow() glut.glutWMCloseFunc(glut_close) glut.glutDisplayFunc(glut_display) glut.glutIdleFunc(glut_idle) else: glut.glutWMCloseFunc(glut_close) glut.glutDisplayFunc(glut_display) glut.glutIdleFunc(glut_idle) self.manager.set_inputhook(inputhook_glut)
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()
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()
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()
def enable_glut(self, app=None): """ Enable event loop integration with GLUT. Parameters ---------- app : ignored Ignored, it's only a placeholder to keep the call signature of all gui activation methods consistent, which simplifies the logic of supporting magics. Notes ----- This methods sets the PyOS_InputHook for GLUT, which allows the GLUT to integrate with terminal based applications like IPython. Due to GLUT limitations, it is currently not possible to start the event loop without first creating a window. You should thus not create another window but use instead the created one. See 'gui-glut.py' in the docs/examples/lib directory. The default screen mode is set to: glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH """ import OpenGL.GLUT as glut # @UnresolvedImport from pydev_ipython.inputhookglut import glut_display_mode, \ glut_close, glut_display, \ glut_idle, inputhook_glut if GUI_GLUT not in self._apps: argv = getattr(sys, 'argv', []) glut.glutInit(argv) glut.glutInitDisplayMode(glut_display_mode) # This is specific to freeglut if bool(glut.glutSetOption): glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE, glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS) glut.glutCreateWindow(argv[0] if len(argv) > 0 else '') glut.glutReshapeWindow(1, 1) glut.glutHideWindow() glut.glutWMCloseFunc(glut_close) glut.glutDisplayFunc(glut_display) glut.glutIdleFunc(glut_idle) else: glut.glutWMCloseFunc(glut_close) glut.glutDisplayFunc(glut_display) glut.glutIdleFunc(glut_idle) self.set_inputhook(inputhook_glut) self._current_gui = GUI_GLUT self._apps[GUI_GLUT] = True
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()
def quit(self): print('close window') # glut displayfunc seems to mess up stdout in pytest # GLUT.glutDisplayFunc(None) GLUT.glutIdleFunc(None) # Hide the window, glut destroy does not instantly remove the window # it adds the window to a list to be removed later # GLUT.glutHideWindow(self.window) GLUT.glutDestroyWindow(self.window) # handle remaining events so the window is closed correctly GLUT.glutMainLoopEvent() # self.window = None # time.sleep(0.1) super(context, self).quit()
def createGLUTWindow(windowTitle): GLUT.glutInit(sys.argv) GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH) GLUT.glutInitWindowSize(1024, 768) GLUT.glutInitWindowPosition(120, 120) GLUT.glutCreateWindow(windowTitle) GLUT.glutDisplayFunc(onDrawGL) GLUT.glutIdleFunc(onDrawGL) GLUT.glutReshapeFunc(resizeGL) GLUT.glutKeyboardFunc(keyPressed) initGL() createShaderGL()
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()
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()
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()
def __init__(self, app_id, fullscreen=False): glut.glutInit() glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA) if fullscreen: glut.glutGameModeString('1920x1080:32@60') glut.glutEnterGameMode() else: glut.glutInitWindowPosition(100, 100) glut.glutInitWindowSize(1024, 768) glut.glutCreateWindow('steampak demo') glut.glutDisplayFunc(self.redraw) glut.glutIdleFunc(self.redraw) glut.glutKeyboardFunc(self.keypress) self.api = SteamApi(LIBRARY_PATH, app_id=app_id)
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)
def __init__( self, source, duration, width=250, height=100 ): self.source = source self.duration = duration self.width = width self.height = height self.points = [] GLUT.glutInit( sys.argv ) GLUT.glutInitDisplayMode( GLUT.GLUT_DOUBLE ) self.window = GLUT.glutCreateWindow( "fft!" ) GLUT.glutReshapeWindow( width, height ) GLUT.glutIdleFunc( self.idle ) GLUT.glutDisplayFunc( self.display ) self.framecount = 0
def mouse(button, state, x, y): if button == GLUT.GLUT_LEFT_BUTTON: if (state == GLUT.GLUT_DOWN): GLUT.glutIdleFunc(forward) elif (state == GLUT.GLUT_UP): GLUT.glutIdleFunc(Calculations) elif button == GLUT.GLUT_RIGHT_BUTTON: if (state == GLUT.GLUT_DOWN): GLUT.glutIdleFunc(backward) elif (state == GLUT.GLUT_UP): GLUT.glutIdleFunc(Calculations)
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()
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()
def visualizeGraph(): #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()
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)
def keyboard(key, x, y): #global day,year,zdist if key == chr(27): sys.exit(0) if key == 'a': glut.glutIdleFunc(spin) if key == 'p' or key == 'P': # picking viewport=gl.glGetIntegerv(gl.GL_VIEWPORT) #print viewport w=viewport[2]-viewport[0] h=viewport[3]-viewport[1] #print 'SBS',SELECT_BUFFER_SIZE gl.glSelectBuffer(SELECT_BUFFER_SIZE) gl.glRenderMode(gl.GL_SELECT) gl.glInitNames() gl.glPushName(0) gl.glMatrixMode(gl.GL_PROJECTION) gl.glPushMatrix() gl.glLoadIdentity() glu.gluPickMatrix(x,viewport[3]-y,.1, .1, viewport) glu.gluPerspective(60.0, w/ h , 1.0, 20.0) #gl.glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5); drawRects(gl.GL_SELECT) gl.glPopMatrix() gl.glFlush() buffer = gl.glRenderMode(gl.GL_RENDER) glut.glutPostRedisplay() #print buffer for hit_record in buffer: min_depth, max_depth, names = hit_record print min_depth, max_depth, names
def __init__(self, cam_model_files, tracked_cam_parameters, cam_track, point_cloud): point_cloud_ids, point_cloud_points, point_cloud_colors = point_cloud if point_cloud_colors is None: point_cloud_colors = np.ones(point_cloud_points.shape, dtype=np.float32) point_cloud_scale = _detect_point_cloud_scale(point_cloud_points) point_cloud_target_scale = 3 point_cloud_points = _rescale_point_cloud( point_cloud_points, point_cloud_target_scale / point_cloud_scale) cam_track = _rescale_track( cam_track, point_cloud_target_scale / point_cloud_scale) self._tracked_cam_track_len = len(cam_track) self._tracked_cam_track_pos_float = 0.0 self._camera = recordclass('CameraPoseAndParameters', 'yaw pitch pos fov_y')( 0.0, 0.0, np.array([0, 0, 10.0]), self._camera_fov_y_range.default) GLUT.glutInit() GLUT.glutInitWindowSize(600, 400) GLUT.glutInitWindowPosition(0, 0) self._data = recordclass('AnimationData', 'prev_time key_states last_xy')( GLUT.glutGet(GLUT.GLUT_ELAPSED_TIME), np.array([False] * 256), None) GLUT.glutCreateWindow(b'Camera track renderer') GLUT.glutDisplayFunc(self.display) GLUT.glutKeyboardFunc(self.key_pressed) GLUT.glutKeyboardUpFunc(self.key_up) GLUT.glutIdleFunc(self.animate) GLUT.glutMouseFunc(self.mouse_event) GLUT.glutMotionFunc(self.mouse_move) self._renderer_impl = CameraTrackRenderer( cam_model_files, tracked_cam_parameters, cam_track, PointCloud(point_cloud_ids, point_cloud_points, point_cloud_colors))
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()
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 )
def main_parallel(): """ parallel SHUTTER | ANAGLYPH | NONE """ global sC global stereoMode sC = StereoCamera() GLUT.glutInit([b'anaglyph.py', b"ANAGLYPH"]) stereoMode = "ANAGLYPH" GLUT.glutInitDisplayMode(GLUT.GLUT_DOUBLE | GLUT.GLUT_RGB | GLUT.GLUT_DEPTH) GLUT.glutInitWindowSize(800, 600) GLUT.glutInitWindowPosition(100, 100) GLUT.glutCreateWindow(b'anaglyph.py') init() GLUT.glutDisplayFunc(display) GLUT.glutIdleFunc(animationStep) GLUT.glutMainLoop() pdb.set_trace()
def visualizeGraph(): #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()
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 )
def __init__(self,layers,layers_lock): """ Инициализирует экран и запускает его, потом всю программу """ Screen.__init__(self,"OpenGL",layers,layers_lock) self.window = 0 self.quad = None self.keypress = [] print("F**k") # self.infoScreen = ScreenCursesInfo() self.infoScreen = ScreenStandartInfo() GLUT.glutInit(sys.argv) GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_ALPHA | GLUT.GLUT_DEPTH) GLUT.glutInitWindowSize(640, 480) GLUT.glutInitWindowPosition(400, 400) self.window = GLUT.glutCreateWindow(b"Project Evoluo alpha") GLUT.glutDisplayFunc(self._loop) # Функция, отвечающая за рисование GLUT.glutIdleFunc(self._loop) # При простое перерисовывать GLUT.glutReshapeFunc(self._resize) # изменяет размеры окна GLUT.glutKeyboardFunc(self._keyPressed) # Обрабатывает нажатия self._initGL(640, 480) field_params(640, 480) print("F**k")
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)
def __init__(self, vispy_timer): BaseTimerBackend.__init__(self, vispy_timer) self._schedule = list() glut.glutIdleFunc(self._idle_callback) # tell application instance about existence vispy_timer._app._backend._add_timer(self)
if __name__ == '__main__': import sys import OpenGL.GLUT as glut from glagg import curve4_bezier from glagg import PathCollection t0, frames = glut.glutGet(glut.GLUT_ELAPSED_TIME), 0 glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH) glut.glutCreateWindow("Shapes") glut.glutReshapeWindow(800, 800) glut.glutDisplayFunc(on_display) glut.glutReshapeFunc(on_reshape) glut.glutKeyboardFunc(on_keyboard) glut.glutIdleFunc(on_idle) collection = PathCollection() def heart(): vertices = curve4_bezier( (0.0,-0.5), (0.75,+0.25), (.75,+1.0), (0.0,+0.5) ) n = len(vertices) V = np.zeros((2*n,2)) V[:n] = vertices V[n:] = vertices[::-1] V[n:,0] *=-1 V[n:,0] -= .0001 return V vertices = heart() for i in range(2000): color = np.random.uniform(0,1,4)
gl.glOrtho (-2.0*ratio,2.0*ratio, -2.0,2.0, -1.0, 1.0) else: gl.glOrtho (-2.0,2.0, -2.0/ratio,2.0/ratio, -1.0, 1.0) gl.glMatrixMode(gl.GL_MODELVIEW) glut.glutInit() # Indicamos como ha de ser la nueva ventana glut.glutInitWindowPosition (100,100) glut.glutInitWindowSize (W_WIDTH, W_HEIGHT) glut.glutInitDisplayMode (glut.GLUT_RGBA | glut.GLUT_DOUBLE) glut.glutCreateWindow ("Etapa 2") # Indicamos cuales son las funciones de redibujado e idle glut.glutDisplayFunc(Display) glut.glutIdleFunc(Idle) glut.glutReshapeFunc(Reshape) #El color de fondo sera el negro (RGBA, RGB + Alpha channel) gl.glClearColor (1.0, 1.0, 1.0, 1.0) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho (-1.0, 1.0, -1.0, 1.0, -1.0, 1.0) gl.glMatrixMode(gl.GL_MODELVIEW) #Comienza la ejecucion del core de GLUT glut.glutMainLoop()