def start(self): """Run main loop. Blocking operation. Should be executed after all initial actions. """ glutMainLoop()
def main(): moons = [Moon(pos) for pos in d12_input] glutInit(sys.argv) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(800, 800) glutInitWindowPosition(350, 200) glutCreateWindow('name') glClearColor(0., 0., 0., 1.) glShadeModel(GL_SMOOTH) glEnable(GL_CULL_FACE) glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) lightZeroPosition = [10., 4., 10., 1.] lightZeroColor = [0.8, 1.0, 0.8, 1.0] glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition) glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor) glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1) glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05) glEnable(GL_LIGHT0) glutDisplayFunc(lambda: display_scene(moons)) glutTimerFunc(0, timer, 0) glMatrixMode(GL_PROJECTION) gluPerspective(40., 1., 1., 40.) glMatrixMode(GL_MODELVIEW) gluLookAt(0, -10, 10, 0, 0, 0, 0, 1, 0) glPushMatrix() glutMainLoop()
def __init__(self, width=800, height=600, x=112, y=84): self.init_opengl(width=width, height=height, x=x, y=y) print("OpenGL Version: {0}".format(glGetString(GL_VERSION))) self.clock = Clock(speed=100) self.timer = Clock(snooze_interval=1/30) self.frame_index = 0 self.event_index = 0 self.is_recording = False VERTEX_SHADER = compileShader(""" void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }""", GL_VERTEX_SHADER) FRAGMENT_SHADER = compileShader(""" void main() { gl_FragColor = vec4(0.8, 0.8, 0.8, 1); }""", GL_FRAGMENT_SHADER) self.shader = compileProgram(VERTEX_SHADER, FRAGMENT_SHADER) self.coordsys = vbo.VBO( np.array([ [-1, 0, 0], [1, 0, 0], [0, -1, 0], [0, 1, 0], [0, 0, -1], [0, 0, 1] ], 'f') ) self.blob = None self.objects = [] self.shaded_objects = [] self.mouse_x = None self.mouse_y = None self.show_help = False self._help_string = None self.show_info = False self.spectrum = None self.detector = Detector('/Users/tamasgal/Data/KM3NeT/Detector/km3net_jul13_90m.detx') self.dom_positions = np.array([tuple(pos) for pos in self.detector.dom_positions], 'f') self.min_z = min([z for x, y, z in self.dom_positions]) self.max_z = max([z for x, y, z in self.dom_positions]) camera.target = Position((0, 0, (self.max_z - self.min_z) / 2)) self.dom_positions_vbo = vbo.VBO(self.dom_positions) self.pump = EvtPump(filename='/Users/tamasgal/Data/KM3NeT/Luigi/nueCC.evt') self.load_blob(0) self.clock.reset() self.timer.reset() glutMainLoop()
def init(self): glutInit(sys.argv) glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE) glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) glutCreateWindow('Main Window') glutDisplayFunc(self.display) glutKeyboardFunc(self.keyboard) glutMainLoop()
def __init__(self, infoGUI, GameLoop, world, extraArgs, colorList=cl_default): """infoGUI should be a dict, GameLoop a method, world a World object and extraArgs is a string which is passed to OpenGL""" # TODO there are a bit too many member variables. self.GameLoop = GameLoop self.wesend = infoGUI["wesend"] self.infoWorld = infoGUI["world"] self.infoWesen = infoGUI["wesen"] self.infoFood = infoGUI["food"] self.infoGui = infoGUI["gui"] self.world = world self.windowactive = True self.size = self.infoGui["size"] self.windowSize = [self.size, self.size] self.pause = False self.init = True self.frame = 0 self.lasttime = 0 self.lastturns = 0 # TODO restore after resume? self.fps = 0 self.tps = 0 # TODO maybe kill turns per second stats self.speed = 1.0 self.wait = 1 self.posX, self.posY = (0, 0) initxy = self.infoGui["pos"] self.initx = int(initxy[:initxy.index(",")]) self.inity = int(initxy[initxy.index(",") + 1:]) # TODO maybe repair step feature self.descriptor = [{}, []] self.bgcolor = [0.0, 0.0, 0.05] self.fgcolor = [0.0, 0.1, 0.2] self.colorList = colorList *\ int(1 + len(self.infoWesen["sources"]) / len(colorList)) self.graph = Graph(self, self.world, self.infoWesen["sources"], self.colorList) self.map = Map(self, self.infoWorld, self.infoWesen["sources"], self.colorList) self.world.setCallbacks(self.map.GetCallbacks()) self.text = Text(self, self.world) self.text.SetAspect(2, 1) # aspect ratio x:y is 2:1 self.objects = [self.map, self.text] self._initGL(extraArgs) self.menu = None self.initMenu() self.keybindings = dict() self.keyExplanation = dict() self.initKeyBindings() self.mouseFirst = [0, 0] self.mouseLast = [0, 0] glutMainLoop()
def main(): hat = Hat() if hat.lcd and hat.lcd.use_glut: from OpenGL.GLUT import glutMainLoop, glutIdleFunc glutIdleFunc(hat.poll) glutMainLoop() else: while True: hat.poll()
def main(path=None): glutInit(sys.argv) if sys.platform == 'darwin': if not path: path = dialog() if not path: sys.exit(0) glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE) glutInitWindowPosition(0, 0) glutInitWindowSize(730, 650) win = glutCreateWindow(b'MIDI Player') (width, height, img) = read_image(join(dirname(__file__), 'mixer.ppm')) glPixelStorei(GL_UNPACK_ALIGNMENT, 1) texture = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, texture) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, img) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glMatrixMode(GL_TEXTURE) glLoadIdentity() glScale(1 / width, 1 / height, 1) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0, 730, 0, 650, 0, 1) player = Player(win, path, width, height) glutDisplayFunc(player.display_func) glutKeyboardFunc(player.keyboard_func) glutMouseFunc(player.mouse_func) glutMotionFunc(player.motion_func) glutIdleFunc(player.process_events) submenus = [] for instrument in range(128): if instrument % 8 == 0: submenus.append([ families[instrument // 8], glutCreateMenu(player.change_instrument) ]) glutAddMenuEntry(instruments[instrument].encode('ascii'), instrument) glutCreateMenu(player.change_instrument) for family, submenu in submenus: glutAddSubMenu(family.encode('ascii'), submenu) glutAttachMenu(GLUT_RIGHT_BUTTON) glutMainLoop()
def main(path=None): glutInit(sys.argv) if sys.platform == 'darwin': if not path: path = dialog() if not path: sys.exit(0) glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE) glutInitWindowPosition(0, 0) glutInitWindowSize(730, 650) win = glutCreateWindow(b'MIDI Player') (width, height, img) = read_image('mixer.ppm') glPixelStorei(GL_UNPACK_ALIGNMENT, 1) rbo = c_uint(int(glGenRenderbuffersEXT(1))) glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rbo) glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, width, height) fbo = c_uint(int(glGenFramebuffersEXT(1))) glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, fbo) glFramebufferRenderbufferEXT(GL_READ_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, rbo) glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fbo) glClear(GL_COLOR_BUFFER_BIT) glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, img) glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0) player = Player(win, path, width, height) glutDisplayFunc(player.display_func) glutKeyboardFunc(player.keyboard_func) glutMouseFunc(player.mouse_func) glutMotionFunc(player.motion_func) glutIdleFunc(player.process_events) submenus = [] for instrument in range(128): if instrument % 8 == 0: submenus.append([families[instrument // 8], glutCreateMenu(player.change_instrument)]) glutAddMenuEntry(instruments[instrument].encode('ascii'), instrument) glutCreateMenu(player.change_instrument) for family, submenu in submenus: glutAddSubMenu(family.encode('ascii'), submenu) glutAttachMenu(GLUT_RIGHT_BUTTON) glutMainLoop()
def main(path=None): glutInit(sys.argv) if sys.platform == 'darwin': if not path: path = dialog() if not path: sys.exit(0) glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE) glutInitWindowPosition(0, 0) glutInitWindowSize(730, 650) win = glutCreateWindow(b'MIDI Player') (width, height, img) = read_image(join(dirname(__file__), 'mixer.ppm')) glPixelStorei(GL_UNPACK_ALIGNMENT, 1) texture = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, texture) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, img) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glMatrixMode(GL_TEXTURE) glLoadIdentity() glScale(1/width, 1/height, 1) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0, 730, 0, 650, 0, 1) player = Player(win, path, width, height) glutDisplayFunc(player.display_func) glutKeyboardFunc(player.keyboard_func) glutMouseFunc(player.mouse_func) glutMotionFunc(player.motion_func) glutIdleFunc(player.process_events) submenus = [] for instrument in range(128): if instrument % 8 == 0: submenus.append([families[instrument // 8], glutCreateMenu(player.change_instrument)]) glutAddMenuEntry(instruments[instrument].encode('ascii'), instrument) glutCreateMenu(player.change_instrument) for family, submenu in submenus: glutAddSubMenu(family.encode('ascii'), submenu) glutAttachMenu(GLUT_RIGHT_BUTTON) glutMainLoop()
def process(pipe, config): import lcd print('lcd process on', os.getpid()) self.lcd = lcd.LCD(self.hat.config) self.lcd.pipe = pipe if self.lcd.use_glut: from OpenGL.GLUT import glutMainLoop, glutIdleFunc glutIdleFunc(self.lcd.poll) glutMainLoop() else: while True: self.lcd.poll()
def main(): #Load up the local settings game_settings = load_settings() #Network starts first since it gives us many of the parameters we need to initialize our game grid. network = MasterNetworkMode(game_settings) network.startNetwork() #Client-side game related stuffs below #This function will wait until the network thread either connects or times out #This really shouldn't take more than a few hundred milliseconds at worst on a local connection game_grid_params = network.getParameters() if game_grid_params is None: #YOU DUN GOOFED UP NOW print "Failed to initialize network thread. Quitting..." exit(1) ''' if game_settings["net_mode"] == "ClientMode": print "Client recv params:" print game_grid_params ''' #Update our globals update_params(game_grid_params) #Get our player init data from the client thread. init_player_data = network.getInitPlayerData() client_connection_id = network.getConnectionID() #initilize our game grid and SnakeManager objects using the data gathered above. snakepit = SnakeManager(client_connection_id, init_player_data) Game_Grid = Grid(snakepit, game_grid_params["GRID_SIDE_SIZE_PX"], game_grid_params["WINDOW_SIZE"]) #Update our network side with the SnakeManager and Grid references network.setSnakeReference(snakepit) network.setGridReference(Game_Grid) #class to handle the drawing of our various elements #This has turned into more of a driver class for everything. renderman = RenderManager(Game_Grid) #Gl/Glut stuffs below glinit("PyGLSnake-Multiplayer :: Connection ID: %s" % client_connection_id) glutSpecialFunc(snakepit.keypressCallbackGLUT) #glutDisplayFunc is the main callback function opengl calls when GLUT determines that the display must be redrawn glutDisplayFunc(renderman.render_all_shapes) glutTimerFunc(TICKRATE_MS, renderman.calc_movement_all_shapes, 0) #Might want to get rid of this unless we plan to run it through the komodo profiler glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION) #Start everything up glutMainLoop()
def run(): global window glutInit(sys.argv) # Select type of Display mode: # Double buffer # RGBA color # Alpha components supported # Depth buffer glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) # get a 640 x 480 window resolution = get_state()["camera"]["resolution"] glutInitWindowSize(int(resolution[0]), int(resolution[1])) # the window starts at the upper left corner of the screen glutInitWindowPosition(0, 0) # Okay, like the C version we retain the window id to use when closing, but for those of you new # to Python (like myself), remember this assignment would make the variable local and not global # if it weren't for the global declaration at the start of main. window = glutCreateWindow("Waffle") # Register the drawing function with glut, BUT in Python land, at least using PyOpenGL, we need to # set the function pointer and invoke a function to actually register the callback, otherwise it # would be very much like the C version of the code. glutDisplayFunc(DrawGLScene) # Uncomment this line to get full screen. # glutFullScreen() # When we are doing nothing, redraw the scene. glutIdleFunc(idleFunc) # Register the function called when our window is resized. glutReshapeFunc(ReSizeGLScene) # Register the function called when the keyboard is pressed. glutKeyboardFunc(keyDown) glutKeyboardUpFunc(keyUp) glutMouseFunc(onMouseClick) glutMotionFunc(onMouseClickMove) glutPassiveMotionFunc(onMouseMove) # Initialize our window. InitGL() init_world() init_interface() # Start Event Processing Engine glutMainLoop()
def show_OpenGL(csg): if not _have_OpenGL: raise RuntimeError("PyOpenGL not available") renderable = TestRenderable(csg) glutInit() glutInitWindowSize(640, 480) renderable.win_id = glutCreateWindow("CSG Test") glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION) glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA) glutDisplayFunc(renderable.display) glutKeyboardFunc(renderable.keypress) glutSpecialFunc(renderable.special_keypress) renderable.init() glutMainLoop()
def main(): glutInit(sys.argv) glutInitDisplayMode(GLUT_DOUBLE) glutInitWindowSize(800, 600) glutInitWindowPosition(100, 100) glutCreateWindow('Particle System') fountains = Context() glutDisplayFunc(fountains.display) glutReshapeFunc(fountains.reshape) glEnable(GL_POINT_SMOOTH) glutMainLoop()
def run(self): """Turns control of the current thread over to the OpenGL viewer """ self._main_window.initialize(self._on_window_update) self._view_controller.initialize() self._vector_view_manifest.load_assets() # use a non-blocking update loop if possible to make exit conditions # easier (not supported on all GLUT versions). if bool(glutCheckLoop): while not self._close_event.is_set(): glutCheckLoop() else: # This blocks until quit glutMainLoop() if not self._close_event.is_set(): # Pass the keyboard interrupt on to SDK so that it can close cleanly raise KeyboardInterrupt
def main(): from OpenGL.GLUT import glutInit, glutInitDisplayMode, \ glutMainLoop, GLUT_DOUBLE, GLUT_RGBA from ModelViewWindow import View, GLUTWindow glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA) cam_spec = {'eye' : [2, 2, 2], 'center' : [0, 0, 0], 'up' : [0, 1, 0], 'fovy': 30, 'aspect': 1.0, 'near' : 0.01, 'far' : 200.0} data_points = np.zeros((16, 3)) data_points[:,0] = np.transpose([0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) data_points[:,1] = np.transpose([0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]) data_points[:,2] = np.transpose([0, -2, 2, -3, 0, -2, 2, -3, 0, -2, 2, -3, 0, -2, 2, -3]) BCPatch = BicubicPatch(data_points) cam = View(BCPatch, cam_spec) GLUTWindow('Bicubic Patch', cam, window_size = (512, 512), window_pos =(520, 0)) glutMainLoop()
def main(): lcd = LCD(False) def idle(): lcd.poll() if lcd.glutkeytime: k, t = lcd.glutkeytime dt = gettime() - t if dt > .5: lcd.keypad[k].update(False) lcd.glutkeytime = False time.sleep(.1) if lcd.use_glut: from OpenGL.GLUT import glutMainLoop, glutIdleFunc glutIdleFunc(idle) glutMainLoop() else: while True: lcd.poll() time.sleep(.1)
def activate(self, width, height): glutInit(['mesh_viewer']) glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH) glutInitWindowSize(width, height) glutInitWindowPosition(0, 0) self.root_window_id = glutCreateWindow(self.titlebar) glutDisplayFunc(self.on_draw) glutTimerFunc(100, self.checkQueue, 0) glutReshapeFunc(self.on_resize_window) glutKeyboardFunc(self.on_keypress) glutMouseFunc(self.on_click) glutMotionFunc(self.on_drag) # for r, lst in enumerate(self.mesh_viewers): # for c, mv in enumerate(lst): # mv.glut_window_id = glutCreateSubWindow(self.root_window_id, c*width/len(lst), r*height/len(self.mesh_viewers), width/len(lst), height/len(self.mesh_viewers)) glutDisplayFunc(self.on_draw) self.init_opengl() glutMainLoop() # won't return until process is killed
def mainloop(self): '''Main loop is done by GLUT itself.''' # callback for ticking def _glut_redisplay(): evloop = getEventLoop() # hack, glut seem can't handle the leaving on the mainloop # so... leave with sys.exit() :[ try: evloop.idle() except KeyboardInterrupt: evloop.quit = True if evloop.quit: sys.exit(0) glutPostRedisplay() # install handler glutDisplayFunc(_glut_redisplay) # run main loop glutMainLoop()
def ContextMainLoop(cls, *args, **named): """Mainloop for the GLUT testing context""" from OpenGL.GLUT import glutInit, glutMainLoop # initialize GLUT windowing system import sys try: glutInit(sys.argv) except TypeError: glutInit(' '.join(sys.argv)) render = cls(*args, **named) if hasattr(render, 'createMenus'): render.createMenus() return glutMainLoop()
def main(): init() Game_Grid = Grid() snake = Snake(Game_Grid) #I didnt really want to use GLUT much but eh, I will work this out with standard libraries later glutSpecialFunc(snake.keypress_callback_GLUT) renderman = RenderManager(Game_Grid, snake) glutDisplayFunc(renderman.render_all_shapes) glutTimerFunc(TICKRATE_MS, renderman.calc_movement_all_shapes, 0) #Tell Glut to continue execution after we exit the main loop #Komodo's code profiler will not return any results unless you shut down just right glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION) #set vsync swap_control.wglSwapIntervalEXT(VSYNC) #Start everything up glutMainLoop()
def ContextMainLoop( cls, *args, **named ): """Mainloop for the GLUT testing context""" from OpenGL.GLUT import glutInit, glutMainLoop # initialize GLUT windowing system import sys try: glutInit( sys.argv) except TypeError: import string glutInit( ' '.join(sys.argv)) render = cls( *args, **named) if hasattr( render, 'createMenus' ): render.createMenus() return glutMainLoop()
def main(): print 'init...' screen = None for arg in sys.argv: if 'nokia5110' in arg: sys.argv.remove(arg) print 'using nokia5110' screen = ugfx.nokia5110screen() if not screen: if use_glut: screen = glut.screen((120, 210)) #screen = glut.screen((64, 128)) #screen = glut.screen((48, 84)) else: screen = ugfx.screen("/dev/fb0") if screen.width == 416 and screen.height == 656: # no actual device or display print 'no actual screen, running headless' screen = None if screen.width > 480: screen.width = 480 screen.height= min(screen.height, 640) lcdclient = LCDClient(screen) if screen: # magnify to fill screen mag = min(screen.width / lcdclient.surface.width, screen.height / lcdclient.surface.height) if mag != 1: print "magnifying lcd surface to fit screen" magsurface = ugfx.surface(screen) invsurface = ugfx.surface(lcdclient.surface) def idle(): if screen: lcdclient.display() surface = lcdclient.surface if lcdclient.config['invert']: invsurface.blit(surface, 0, 0) surface = invsurface surface.invert(0, 0, surface.width, surface.height) if mag != 1: magsurface.magnify(surface, mag) surface = magsurface # mag = 2 #surface.magnify(mag) screen.blit(surface, 0, 0, lcdclient.config['flip']) screen.refresh() if 'contrast' in lcdclient.config: screen.contrast = int(lcdclient.config['contrast']) lcdclient.idle() if use_glut: from OpenGL.GLUT import glutMainLoop from OpenGL.GLUT import glutIdleFunc from OpenGL.GLUT import glutKeyboardFunc from OpenGL.GLUT import glutKeyboardUpFunc from OpenGL.GLUT import glutSpecialFunc from OpenGL.GLUT import glutSpecialUpFunc glutKeyboardFunc(lcdclient.glutkeydown) glutKeyboardUpFunc(lcdclient.glutkeyup) glutSpecialFunc(lcdclient.glutspecialdown) glutSpecialUpFunc(lcdclient.glutspecialup) glutIdleFunc(idle) # glutIgnoreKeyRepeat(True) glutMainLoop() else: while True: idle()
def main_loop(self): glutMainLoop()
def main_loop(): """ starts the glut main loop """ glutMainLoop()
def __init__(self): print(str(bool(glutInit))) print("hello and weolcome") print( "if you see an error next try the unofficial binaries of pyopengl") print("initializing glut etc") glutInit(sys.argv) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH) glutInitWindowSize(640, 480) glutCreateWindow(name) print("set blend function") glBlendFunc(GL_SRC_ALPHA, GL_ONE) print("set colours and lights") glClearColor(0., 0., 0., 1.) glShadeModel(GL_SMOOTH) glEnable(GL_CULL_FACE) glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) print("set light 1") lightZeroPosition = [10., 4., 10., 1.] lightZeroColor = [0.9, 1.0, 0.9, 1.0] #green tinged glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition) glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor) glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.2) glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05) glEnable(GL_LIGHT0) print("set light 2") lightZeroPosition2 = [-10., -4., 10., 1.] lightZeroColor2 = [1.0, 0.9, 0.9, 1.0] #green tinged glLightfv(GL_LIGHT1, GL_POSITION, lightZeroPosition2) glLightfv(GL_LIGHT1, GL_DIFFUSE, lightZeroColor2) glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.2) glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.05) glEnable(GL_LIGHT1) #initialization of letters print("initialzing letters") self.letters = Letters.Letters() #for game models print("making model lists") MakeLists() print("ignore key repeat") glutIgnoreKeyRepeat(1) print("attach glut events to functions") glutSpecialFunc(self.keydownevent) glutSpecialUpFunc(self.keyupevent) glutReshapeFunc(self.reshape) glutKeyboardFunc(self.keydownevent) glutKeyboardUpFunc(self.keyupevent) glutDisplayFunc(self.display) #glutIdleFunc(self.display) print("initial projection") glMatrixMode(GL_PROJECTION) gluPerspective(60.0, 640.0 / 480., 1., 50.) glMatrixMode(GL_MODELVIEW) glPushMatrix() print("generating level") self.level = generateLevel(0) print("keys set up") self.initkey("zxdcfvqaopm") self.animate() print("about to loop...") glutMainLoop() return
def main_loop(self): """ 程序主循环开始 """ glutMainLoop()
def main_loop(): glutMainLoop()
def run(self, delegate_function: callable): """Turns control of the main thread over to the OpenGL viewer .. testcode:: import anki_vector from anki_vector import opengl_viewer import asyncio async def my_function(robot): await asyncio.sleep(20) print("done") with anki_vector.Robot(show_viewer=True, enable_camera_feed=True, enable_face_detection=True, enable_custom_object_detection=True, enable_nav_map_feed=True) as robot: viewer = anki_vector.opengl_viewer.OpenGLViewer(robot=robot) viewer.run(my_function) :param delegate_function: external function to spin up on a seperate thread to allow for sdk code to run while the main thread is owned by the viewer. """ abort_future = concurrent.futures.Future() # Register for robot state events robot = self._robot robot.events.subscribe(self._on_robot_state_update, Events.robot_state) robot.events.subscribe(self._on_nav_map_update, Events.nav_map_update) # Determine how many arguments the function accepts function_args = [] for param in inspect.signature(delegate_function).parameters: if param == 'robot': function_args.append(robot) elif param == 'viewer': function_args.append(self) else: raise ValueError("the delegate_function injected into OpenGLViewer.run requires an unrecognized parameter, only 'robot' and 'viewer' are supported") try: robot.conn.run_coroutine(delegate_function(*function_args)) # @TODO: Unsubscribe and shut down when the delegate function finishes # This became an issue when the concurrent.future changes were added. self._main_window.initialize(self._on_window_update) self._view_controller.initialize() self._vector_view_manifest.load_assets() # use a non-blocking update loop if possible to make exit conditions # easier (not supported on all GLUT versions). if bool(glutCheckLoop): while not self._exit_requested: glutCheckLoop() else: # This blocks until quit glutMainLoop() if self._exit_requested and not self._internal_function_finished: # Pass the keyboard interrupt on to SDK so that it can close cleanly raise KeyboardInterrupt except BaseException as e: abort_future.set_exception(VectorException(repr(e))) raise global opengl_viewer # pylint: disable=global-statement opengl_viewer = None
def main_loop(self): #程序主循环开始 glutMainLoop()
def show(): glutMainLoop()
def start(self, fitter): """Start main application loop.""" self.__fitter = fitter glutMainLoop()
f_color = vec4(v_color, 1.0); } '''), ]) window_size = prog.uniforms['WindowSize'] vbo = ctx.buffer(struct.pack( '15f', 0.0, 100.0, 1.0, 0.0, 0.0, -86.0, -50.0, 0.0, 1.0, 0.0, 86.0, -50.0, 0.0, 0.0, 1.0, )) vao = ctx.simple_vertex_array(prog, vbo, ['in_vert', 'in_color']) def display(): ctx.viewport = (0, 0, width, height) ctx.clear(0.9, 0.9, 0.9) ctx.enable(ModernGL.BLEND) window_size.value = (width, height) vao.render() glutSwapBuffers() glutDisplayFunc(display) glutIdleFunc(display) glutMainLoop()
glBegin(GL_LINE_LOOP) glVertex2iv(p1) glVertex2iv(p2) glVertex2iv(p3) glVertex2iv(p4) glVertex2iv(p5) glEnd() glBegin(GL_POLYGON) glVertex2i(50, 50) glVertex2i(75, 25) glVertex2i(125, 25) glVertex2i(150, 50) glVertex2i(125, 75) glVertex2i(75, 75) glEnd() glFlush() if __name__ == '__main__': glutInit() glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) glutInitWindowPosition(50, 100) glutInitWindowSize(400, 300) glutCreateWindow("OpenGL") init() glutDisplayFunc(plot_func) glutMainLoop()
def __init__(self, detector_file=None, event_file=None, min_tot=None, skip_to_blob=0, width=1000, height=700, x=50, y=50): self.camera = Camera() self.camera.is_rotating = True self.colourist = Colourist() current_path = os.path.dirname(os.path.abspath(__file__)) if not detector_file: detector_file = os.path.join(current_path, 'data/km3net_jul13_90m_r1494_corrected.detx') self.load_logo() self.init_opengl(width=width, height=height, x=x, y=y) print("OpenGL Version: {0}".format(glGetString(GL_VERSION))) self.clock = Clock(speed=100) self.timer = Clock(snooze_interval=1/30) self.frame_index = 0 self.event_index = skip_to_blob self.is_recording = False self.min_tot = min_tot VERTEX_SHADER = compileShader(""" void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }""", GL_VERTEX_SHADER) FRAGMENT_SHADER = compileShader(""" void main() { gl_FragColor = vec4(0.5, 0.5, 0.5, 1); }""", GL_FRAGMENT_SHADER) self.shader = compileProgram(VERTEX_SHADER, FRAGMENT_SHADER) self.blob = None self.objects = {} self.shaded_objects = [] self.mouse_x = None self.mouse_y = None self.show_secondaries = True self.show_help = False self._help_string = None self.show_info = True self.spectrum = None self.current_spectrum = 'default' self.cmap = self.colourist.default_cmap self.min_hit_time = None self.max_hit_time = None self.detector = Detector(detector_file) dom_positions = self.detector.dom_positions min_z = min([z for x, y, z in dom_positions]) max_z = max([z for x, y, z in dom_positions]) z_shift = (max_z - min_z) / 2 self.dom_positions = np.array([tuple(pos) for pos in dom_positions], 'f') self.camera.target = Position((0, 0, z_shift)) self.dom_positions_vbo = vbo.VBO(self.dom_positions) if event_file: self.pump = EvtPump(filename=event_file) try: self.load_blob(skip_to_blob) except IndexError: print("Could not load blob at index {0}".format(skip_to_blob)) print("Starting from the first one...") self.load_blob(0) else: print("No event file specified. Only the detector will be shown.") self.clock.reset() self.timer.reset() glutMainLoop()
def main_loop(cls): glutMainLoop()