def run(host=None, port=None, width=1024, height=768, doReturn=False): # Setup connection print "Setting up connection" f = UserGeneratedInputClientFactory() f.setVerbose(True) #f.setVerbose(options.verbose) #f.setLoopFreq(options.msgsPerSec) #f.setSendButtonEvents(options.sendButtonEvents) print "Connecting to:", host, port reactor.connectTCP(host, port, f) # -------- print "setting up UI" windowWidth = width #1000# 320 windowHeight = height # 800 # 280 app = App(windowWidth, windowHeight) renderer = glRenderer2D() renderer.addFrameSetupObj(ScreenClearer()) app.setRenderer(renderer) app.initialize() renderer.init(windowWidth, windowHeight) mouseHandler = MouseEventHandler(f, app=app) app.addDynamicObject(Pointer(mouseHandler)) app.addTriggerResponse( TriggerOnMouseEvent(), ruleSystem.Response("HandleMouseEvent", mouseHandler.mouseEvent, [])) app.addTriggerResponse( TriggerOnMouseMotionEvent(), ruleSystem.Response("HandleMouseMotionEvent", mouseHandler.mouseMotionEvent, [])) app.addTriggerResponse( TriggerWhenAnyKeyPressed(), ruleSystem.Response("HandleKeyPress", mouseHandler.keyPress, [])) app.addTriggerResponse( TriggerWhenAnyKeyReleased(), ruleSystem.Response("HandleKeyRelease", mouseHandler.keyRelease, [])) #box = glBox() #app.addDynamicObject(box) #glEnable(GL_TEXTURE_2D) if doReturn: return app else: app.runWithTwisted() print "Exiting."
def run(): windowWidth = 320 windowHeight = 280 app = App(windowWidth, windowHeight) app.setRenderer(glRenderer2D()) app.initialize() glDisable(GL_DEPTH_TEST) #use our zbuffer glDisable(GL_LIGHTING) #use our zbuffer glMatrixMode(GL_PROJECTION) glLoadIdentity() gluOrtho2D(0, windowWidth, 0, windowHeight) #gluPerspective(45.0,float(windowWidth/windowHeight).0,0.1,100.0) print "after gluOrtho2D" glColor3f(0,1,0) print "after glColor" class glBox: def __init__(self): self.hasDrawFunc=True self.hasEraseDrawFunc=True self.visible = True def update(self, app, secs): pass def eraseDraw(self, app): pass def draw(self, renderer): glClearColor(.8, .8, .8, 1.0) glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() box = glBox() print "after make box" app.addDynamicObject(box) print "after adddyn" app.drawBounds = 0 app.appDoesCollisionChecks = False print "Running app" app.run()
def run(): windowWidth = 320 windowHeight = 280 app = App(windowWidth, windowHeight) app.setRenderer(glRenderer2D()) app.initialize() glDisable(GL_DEPTH_TEST) #use our zbuffer glDisable(GL_LIGHTING) #use our zbuffer glMatrixMode(GL_PROJECTION) glLoadIdentity() gluOrtho2D(0, windowWidth, 0, windowHeight) #gluPerspective(45.0,float(windowWidth/windowHeight).0,0.1,100.0) print "after gluOrtho2D" glColor3f(0, 1, 0) print "after glColor" class glBox: def __init__(self): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True def update(self, app, secs): pass def eraseDraw(self, app): pass def draw(self, renderer): glClearColor(.8, .8, .8, 1.0) glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() box = glBox() print "after make box" app.addDynamicObject(box) print "after adddyn" app.drawBounds = 0 app.appDoesCollisionChecks = False print "Running app" app.run()
def run(host=None, port=None, width=1024, height=768, doReturn=False): # Setup connection print "Setting up connection" f = UserGeneratedInputClientFactory() f.setVerbose(True) #f.setVerbose(options.verbose) #f.setLoopFreq(options.msgsPerSec) #f.setSendButtonEvents(options.sendButtonEvents) print "Connecting to:", host, port reactor.connectTCP(host, port, f) # -------- print "setting up UI" windowWidth = width #1000# 320 windowHeight = height # 800 # 280 app = App(windowWidth, windowHeight) renderer = glRenderer2D() renderer.addFrameSetupObj(ScreenClearer()) app.setRenderer(renderer) app.initialize() renderer.init(windowWidth, windowHeight) mouseHandler = MouseEventHandler(f, app=app) app.addDynamicObject(Pointer(mouseHandler)) app.addTriggerResponse(TriggerOnMouseEvent(), ruleSystem.Response("HandleMouseEvent", mouseHandler.mouseEvent, []) ) app.addTriggerResponse(TriggerOnMouseMotionEvent(), ruleSystem.Response("HandleMouseMotionEvent", mouseHandler.mouseMotionEvent, []) ) app.addTriggerResponse(TriggerWhenAnyKeyPressed(), ruleSystem.Response("HandleKeyPress", mouseHandler.keyPress, []) ) app.addTriggerResponse(TriggerWhenAnyKeyReleased(), ruleSystem.Response("HandleKeyRelease", mouseHandler.keyRelease, []) ) #box = glBox() #app.addDynamicObject(box) #glEnable(GL_TEXTURE_2D) if doReturn: return app else: app.runWithTwisted() print "Exiting."
def run(): windowWidth = 1000# 320 windowHeight = 800 # 280 app = App(windowWidth, windowHeight) renderer = glRenderer2D() app.setRenderer(renderer) app.initialize() renderer.init(windowWidth, windowHeight) #GLint texSize; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize); print print "Max Texture Size:", glGetIntegerv(GL_MAX_TEXTURE_SIZE); print print "Check specific: 4096x4096, GL_RGBA:", CheckSpecificTextureSize(width=4096, height=4096, internalFormat=GL_RGB) print "Check specific: 4097x4096, GL_RGBA:", CheckSpecificTextureSize(width=4097, height=4096, internalFormat=GL_RGBA) print "Check specific: 4097x4096, GL_L:", CheckSpecificTextureSize(width=4097, height=4096, internalFormat=GL_LUMINANCE) print
def run(): windowWidth = 1000 # 320 windowHeight = 800 # 280 app = App(windowWidth, windowHeight) renderer = glRenderer2D() app.setRenderer(renderer) app.initialize() renderer.init(windowWidth, windowHeight) #GLint texSize; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize); print print "Max Texture Size:", glGetIntegerv(GL_MAX_TEXTURE_SIZE) print print "Check specific: 4096x4096, GL_RGBA:", CheckSpecificTextureSize( width=4096, height=4096, internalFormat=GL_RGB) print "Check specific: 4097x4096, GL_RGBA:", CheckSpecificTextureSize( width=4097, height=4096, internalFormat=GL_RGBA) print "Check specific: 4097x4096, GL_L:", CheckSpecificTextureSize( width=4097, height=4096, internalFormat=GL_LUMINANCE) print
def run(): windowWidth = 1000# 320 windowHeight = 800 # 280 app = App(windowWidth, windowHeight) renderer = glRenderer2D() app.setRenderer(renderer) app.initialize() renderer.init(windowWidth, windowHeight) class glBox: def __init__(self): self.hasDrawFunc=True self.hasEraseDrawFunc=True self.visible = True def update(self, app, secs): pass def draw(self, renderer): glClearColor(.8, .8, .8, 1.0) glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self): self.hasDrawFunc=True self.hasEraseDrawFunc=True self.visible = True #self.texture = Texture( "../data/test1.png") self.easyTexture = EasyTexture( "../data/test1.png") #self.easyTexture.width = renderer.width * 0.8 self.easyTexture.setWidth(renderer.width * 0.1) self.easyTexture.setHeight(renderer.height * 0.1) self.useDrawPixel = False # For comparison debugging def update(self, app, secs): length = self.easyTexture.texture.image.size[0] * self.easyTexture.texture.image.size[1] * self.easyTexture.texture.numChannels self.easyTexture.texture.imagestr = [random.randrange(0,255) for x in xrange(length)] self.easyTexture.texture.reloadGLTextureFromData() def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) self.easyTexture.draw() box = glBox() app.addDynamicObject(box) glEnable(GL_TEXTURE_2D) box2 = glTxtrBox() # Change the size #box2.easyTexture.texture.image.size = (200,200) #box2.easyTexture.setOffsetX(400) #box2.easyTexture.setOffsetY(400) box2.easyTexture.setWidth(800) box2.easyTexture.setHeight(600) app.addDynamicObject(box2) app.drawBounds = 0 print "Running app" app.run()
def run(): os.environ['SDL_VIDEO_WINDOW_POS']="-400,300" #os.environ['SDL_VIDEO_WINDOWPOS']="400,0" #windowWidth = 2560# 320 windowWidth = 2000# 320 windowHeight = 100 # 280 app = App(windowWidth, windowHeight) renderer = glRenderer2D() app.setRenderer(renderer) app.initialize() renderer.init(windowWidth, windowHeight) class glBox: def __init__(self): self.hasDrawFunc=True self.hasEraseDrawFunc=True self.visible = True def update(self, app, secs): pass def draw(self, renderer): glClearColor(.8, .8, .8, 1.0) glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self): self.hasDrawFunc=True self.hasEraseDrawFunc=True self.visible = True #self.texture = Texture( "../data/test1.png") self.easyTexture = EasyTexture( "../data/test1.png") self.easyTexture.width = renderer.width * 0.8 self.easyTexture.height = renderer.height * 0.8 self.useDrawPixel = False # For comparison debugging def update(self, app, secs): pass def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) self.easyTexture.draw() box = glBox() app.addDynamicObject(box) glEnable(GL_TEXTURE_2D) box2 = glTxtrBox() app.addDynamicObject(box2) app.drawBounds = 0 print "Running app" app.run()
def run(): # not really working #sys.stdout = open( "output/%s.stdout" % mpi.rank, "w" ) #sys.stderr = open( "output/%s.stderr" % mpi.rank, "w" ) #debugFile.openfile("output/%s" % mpi.rank, "w") # of = open( "output/%s" % mpi.rank, "w" ) #debugFile.write("begin\n") #debugFile.flush() #debugFile.write("%s\n"% sys.argv ) #debugFile.flush() global tileConfig print "args:", sys.argv #streamProtocol = StreamProtocols.FLX_H261 streamProtocol = StreamProtocols.CELERITAS_TCP_RAW # Parse options: parser = OptionParser() parser.add_option("-c", "--config", dest="config", default=None, help="Specify a tiled display config file.") parser.add_option("", "--loadAllMovieTiles", action="store_true", dest="loadAllMovieTiles", default=False, help="Have all tiles load all movie tiles so movie can be dragged around.") parser.add_option("", "--allowFrameSkip", action="store_false", dest="allowFrameSkip", default=True, help="Allow movies to skip frames (automatic with --loadAllTiles).") parser.add_option("--stream", action="append", dest="stream", default=None, help="Specify a stream to receive.") parser.add_option("--groupedStream", action="append", dest="groupedStream", default=None, help="Specify a stream to receive.") parser.add_option("--hostnames", dest="hostnames", default=None, help="Force list of hostnames/confignames. mpi id used to index the list.") parser.add_option("--streamColsRows", dest="streamColsRows", default=None, help="Specify columns and rows for streams (in one/each network location).") parser.add_option("--streamGroupsColsRows", dest="streamGroupsColsRows", default=None, help="Specify columns and rows for network locations.") parser.add_option("--scale", dest="movieScale", default=None, help="Specify scale for movie playback.") parser.add_option("--sequence", action="append", dest="sequences", default=None, help="Specify sequence of movies. (comma separated)") parser.add_option("--plant", dest="plant", action="store_true", default=False, help="Plant a stream so it can't move (allows streaming optimizations).") parser.add_option("--streamSize", action="append", dest="streamSize", default=None, help="Specify a stream size.") parser.add_option("--pos", action="append", dest="positions", default=None, help="Specify an object position.") parser.add_option("--layout", action="append", dest="layouts", default=None, help="Specify layout of objects.") parser.add_option("--movieLayout", action="append", dest="movieLayouts", default=None, help="Specify layout of tiles in a movie.") parser.add_option("--inputhost", dest="inputHost", default="localhost", help="Airstream server hostname.") parser.add_option("--inputport", dest="inputPort", default=11000, help="Airstream server port.") #parser.add_option("--streamRects", action="append", dest="streamRects", # default=None, # help="Specify streamRects.") options, sysArgs = parser.parse_args() allowFrameSkip=False if options.allowFrameSkip or options.loadAllMovieTiles: allowFrameSkip = True movieScale = None if options.movieScale != None: movieScale = options.movieScale.split("x")[:2] if len(movieScale) < 2: raise Exception("--scale option should be in this format: --scale=2.0x2.0") movieScale = float(movieScale[0]), float(movieScale[1]) movieSequences = [] if options.sequences != None: for sequence in options.sequences: paths = sequence.split(",") movieSequences.append(paths) if options.streamColsRows != None: options.streamColsRows = options.streamColsRows.split("x") options.streamColsRows = [ int(i) for i in options.streamColsRows ] if len(options.streamColsRows) < 2: raise Exception("--streamColsRows needs to be in the format \"3x2\"") #print "COLS ROWS:", options.streamColsRows, type(options.streamColsRows[0]) #raise if options.streamGroupsColsRows != None: options.streamGroupsColsRows = options.streamGroupsColsRows.split("x") options.streamGroupsColsRows = [ int(i) for i in options.streamGroupsColsRows ] if len(options.streamGroupsColsRows) < 2: raise Exception("--streamGroupsColsRows needs to be in the format \"3x2\"") if options.streamSize != None: tmp = [] for pair in options.streamSize: if len(pair.split("x")) != 2: raise Exception("--streamSize needs to be in the format \"600x400\" or \"600x400\",\"500x300\"") x,y = pair.split("x") tmp.append( (int(x),int(y)) ) options.streamSize = tmp if options.positions != None: tmp = [] for p in options.positions: if len(p.split("x")) != 2: raise Exception("--pos needs to be in the format \"100x200\" or \"200x300\",\"100x300\"") x,y = p.split("x") tmp.append( (int(x),int(y)) ) options.positions = tmp global gPositionsIndex gPositionsIndex = 0 if (gFlxStreamingSupported and not gCeleritasStreamingSupported): options.streamSizes = [(352,288)] # H.261 for now. print dir(options), type(options), options.__class__ if hasattr(options, "config") and getattr(options, "config"): from configLoader import LoadConfigPy tileConfig = LoadConfigPy(getattr(options,"config")) else: raise Exception("Please specify the config file on the cmd-line with -c") # Older method: #if mpi.procs == 2: # tileConfig = CreateLocal2TestConfig() #else: # tileConfig = CreateLocalTestConfig() # SaveConfig(tileConfig, "amConfigTmp.txt") # tileConfig = LoadConfig("amConfigTmp.txt") # important to load from file so all nodes have the same tileIds. setupLocalConfig(tileConfig, options) print gethostname(), machineDesc.hostname, localRects, absoluteRects #rects = [Rect(0,0,1280,1024), Rect(1280,0, 1280,1024)] #rects = [Rect(0,0,1280,1024)] if len(localWindows) == 0: os.environ["DISPLAY"] = ":0.0" os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0" #windowWidth = 2560 # 1280# 320 #windowWidth = 3840 # 1280# 320 windowWidth = 2560 # 1280# 320 windowHeight = 1024 # 1024 # 280 #windowWidth = 1280 # 1280# 320 #windowHeight = 1024 # 1024 # 280 print "POSA:", os.environ['SDL_VIDEO_WINDOW_POS'] else: # There is currently only one "localWindow" per process. # All tiles are within the same localWindow. We can get get # this window simply from any tile's config for a machine. os.environ["DISPLAY"] = localWindows[0].getDisplayStr() print "Local windows offset:", localWindows[0].getOffset() os.environ['SDL_VIDEO_WINDOW_POS'] = "%s,%s" % (localWindows[0].getOffset()) print "POS:", os.environ['SDL_VIDEO_WINDOW_POS'] windowWidth = localWindows[0].rect.width windowHeight = localWindows[0].rect.height # print gethostname(), mpi.rank, "DISPLAY SIZE:", windowWidth, windowHeight fullRightBoundary = fullRect.width #imageFilename = sys.argv[1] app = App(windowWidth, windowHeight) # app state contains a few things such as the exitFlag that # will be synced from the master state. app.state=AppState() app.state.exitNextFrame = False visualsManager = VisualsManager() ### Setup Renderers renderers = [] for i in range(len(localRects)): displayRect = localRects[i] if i == 0: renderer = glRenderer2D(multipleRenderers=True, firstRenderer=True) #renderer.addFrameSetupObj(ScreenClearer(color=(.9, .4, .4), clearDepth=False)) renderer.addFrameSetupObj(ScreenClearer(color=(.0, .0, .0), clearDepth=False)) else: renderer = glRenderer2D(multipleRenderers=True) #renderer.addFrameSetupObj(ScreenClearer(color=(.4, .9, .4), clearDepth=False)) renderer.addFrameSetupObj(ScreenClearer(color=(.0, .0, .0), clearDepth=False)) renderers.append(renderer) app.addRenderer(renderer) app.initialize(windowBorder=False) #app.initialize(windowBorder=True) pygame.mouse.set_visible(False) for i in range(len(localRects)): print "SETTING RECT:", localRects[i] renderers[i].init(app.width, app.height, viewportRect=localRects[i]) visualsManager.setRenderers(renderers) #box = glBox() #app.addDynamicObject(box) glEnable(GL_TEXTURE_2D) masterObjects = [] objectsListList = [] # first object in each tuple on master node is source for all others #for i in range(len(renderers)): def CreateObj(imageFilename, imagePos=(2000,500), obj=None, scale=None, objDesc=None, gridColsRows=None, netGridColsRows=None, plant=False): if None == objDesc: objDesc = ObjDesc(ObjType.UNSPECIFIED) boxes = [] for i in range(len(renderers)): absRect = absoluteRects[i] locRect = localRects[i] renderer = renderers[i] if obj == None: if objDesc.type == ObjType.STREAM: #box = CreateTileDisplayStreamObject(imageFilename, screenRect=Rect(0,0,locRect.width, locRect.height), pos=imagePos, absRect= absRect, fullRect=fullRect, blend=True, scale=scale) box = CreateGroupTileDisplayStreamObject(imageFilename, objDesc, screenRect=Rect(0,0,locRect.width, locRect.height), pos=imagePos, absRect= absRect, fullRect=fullRect, blend=True, scale=scale, gridColsRows=gridColsRows) elif objDesc.type == ObjType.GROUPED_STREAM: try: box = CreateMultiNetGroupTileDisplayStreamObject(imageFilename, objDesc, screenRect=Rect(0,0,locRect.width, locRect.height), pos=imagePos, absRect= absRect, fullRect=fullRect, blend=True, scale=scale, gridColsRows=gridColsRows, netGridColsRows=netGridColsRows, plant=plant ) except: traceback.print_exc() sys.exit() elif objDesc.type == ObjType.TILED_MOVIE_WITH_LAYOUT: try: box = CreateTiledMovieObjectFromLayout(imageFilename, screenRect=Rect(0,0,locRect.width, locRect.height), pos=imagePos, absRect= absRect, fullRect=fullRect, loadAllMovieTiles=options.loadAllMovieTiles, scale=scale, allowFrameSkip=allowFrameSkip) except: import traceback traceback.print_exc() sys.exit() else: # objDesc.type.UNSPECIFIED #box = glTxtrBox(imageFilename, screenRect=Rect(0,0,locRect.width, locRect.height), imagePos=imagePos, absRect= absRect, fullRect=fullRect, blend=True) box = CreateTileDisplayObject(imageFilename, screenRect=Rect(0,0,locRect.width, locRect.height), pos=imagePos, absRect= absRect, fullRect=fullRect, blend=True, loadAllMovieTiles=options.loadAllMovieTiles, scale=scale, allowFrameSkip=allowFrameSkip) else: box = obj # to scale, change the geometry and the txtr coords: imageSize and #box.imageSize = (box.imageSize[0]*2, box.imageSize[1]*2) #box.easyTexture.zoom(5,1) #box.easyTexture.setOffset( (absRect.x % float(box.easyTexture.getWidth())) / box.easyTexture.getWidth(), # (absRect.y % float(box.easyTexture.getHeight())) / box.easyTexture.getHeight() ) # box.easyTexture.setWidth( float(locRect.width) / float(box.easyTexture.getHeight()) ) #zoom = (0.5,1) #box.easyTexture.setZoom(zoom[0], zoom[1]) #box.easyTexture.setOffset(absRect.x * zoom[0] ,absRect.y * zoom[1]) #box.easyTexture.setZoom(float(box.easyTexture.getWidth()) / localRect.width, # float(box.easyTexture.getHeight()) / localRect.height ) # scale offset back by zoom (offset is between 0 and 1) #box.easyTexture.setOffset( float(rect.x) / fullRect.width * box.easyTexture.getWidth(), # float(rect.y) / fullRect.height * box.easyTexture.getHeight()) app.addDynamicObject(box, addToRenderer=False) renderers[i].addDynamicObject(box) boxes.append(box) if i == 0 and mpi.rank == 0: masterObjects.append(box) if objDesc.type==ObjType.STREAM: # setup network reception for one machine if StreamProtocols.FLX_H261 == streamProtocol: from streamView import StreamView, StartStreamViewLoop, StreamState elif StreamProtocols.CELERITAS_TCP_RAW == streamProtocol: from streamViewCeleritas import StreamView, StartStreamViewLoop, StreamState else: raise Exception("Unhandled stream format: %s" % streamProtocol) numStreamStates = boxes[0].getNumStreams() streamStateList = [] for i in range(numStreamStates): streamState = StreamState() streamState.printInterval = 0 # disable extra prints for now streamStateList.append(streamState) def nop(nameList): pass #streamStateList = [streamState] address = imageFilename if StreamProtocols.FLX_H261 == streamProtocol: StartStreamViewLoop(address, streamStateList, [ x.reorder for x in boxes ]) #call reorder on each group stream obj else: # CELERITAS_RAW_TCP for now address, streamPort = address.split("/") streamPort = int(streamPort) StartStreamViewLoop(address, streamPort, objDesc.streamWidth, objDesc.streamHeight, streamStateList, [ x.reorder for x in boxes ]) #call reorder on each group stream obj for box in boxes: # add the gui objects for each display on the machine. box.setStreamState(streamStateList) elif objDesc.type==ObjType.GROUPED_STREAM: # setup network reception for one machine if StreamProtocols.FLX_H261 == streamProtocol: from streamView import StreamView, StartStreamViewLoop, StreamState elif StreamProtocols.CELERITAS_TCP_RAW == streamProtocol: from streamViewCeleritas import StreamView, StartStreamViewLoop, StreamState else: raise Exception("Unhandled stream format: %s" % streamProtocol) # Want to avoid creating duplicate streamStates for the same address # keep a dict of address -> streamState print "ADDRESS:", imageFilename addressStateDict = {} # address: streamStateList addressReorderCallbacks = {} # address: [callbacks] for box in boxes: # add the gui objects for each display on the machine. for child in box.getChildren(): #box is a GroupObject holding GroupTiledStreamObject # creating stream states for children if isinstance(child, GroupTiledStreamObject): numStreamStatesForChild = child.getNumStreams() # num streams per net conn. if child.address not in addressStateDict: streamStateList = [] for i in range(numStreamStatesForChild): streamState = StreamState() streamState.printInterval = 0 # disable extra prints for now streamStateList.append(streamState) def nop(nameList): pass # store streamStateList for network address addressStateDict[child.address] = streamStateList if child.address not in addressReorderCallbacks: addressReorderCallbacks[child.address] = [] else: streamStateList = addressStateDict[child.address] # store reorder callback for this object addressReorderCallbacks[child.address].append(child.reorder) #else: # pass # Null placeholder object, don't setup a stream #for address,streamStateList in addressStateDict.items(): for address in imageFilename: # import to iterate through addresses in this order if address in addressStateDict: streamStateList = addressStateDict[address] reorderCallbacks = addressReorderCallbacks[address] print "***** STARTING:|%s|"% address, type(address) #time.sleep(0.1) # FIXME, intead, need add a "ready" callback from # pyRTP once thread is setup. #time.sleep(0.1) address, streamPort = address.split("/") streamPort = int(streamPort) StartStreamViewLoop(address, streamPort, objDesc.streamWidth, objDesc.streamHeight, streamStateList, reorderCallbacks) #call reorder on each group stream obj for box in boxes: for child in box.getChildren(): if isinstance(child, GroupTiledStreamObject): streamStateList = addressStateDict[child.address] child.setStreamState(streamStateList) print "CREATED OBJS:", len(boxes), boxes return boxes """ obj = CreateObj(imageFilename, (0,0)) objectsListList.append(obj) obj = CreateObj("/home/eolson/public_html/vl3/20071116/B/Screenshot-VL3 Application-B0250.png", imagePos=(3200,400)) objectsListList.append(obj) obj = CreateObj("/home/eolson/public_html/vl3/20071116/A/Screenshot-VL3 Application-600.png", imagePos=(800,1700)) objectsListList.append(obj) obj = CreateObj("/home/eolson/public_html/vl3/20070123/vl3_20070123_142002.png", imagePos=(100,800)) objectsListList.append(obj) obj = CreateObj("/home/eolson/public_html/vl3/20061109/vl3_20061109_161226.png", imagePos=(4500,2000)) objectsListList.append(obj) obj = CreateObj("/home/eolson/public_html/vl3/20080402paper/vl3_nodes.png", imagePos=(0,0)) objectsListList.append(obj) obj = CreateObj("/home/eolson/am-macs/data/pic8.png", imagePos=(4200,0)) #obj = CreateObj("/home/eolson/am-macs/data/trim.png", imagePos=(4200,0)) objectsListList.append(obj) """ #imageDir = '/homes/turam/tiledDisplayImages' #imageDir = '/homes/eolson/am-macs/data/images' #defaultImageDir = '/homes/eolson/am-macs/data/largeImages' defaultImageDir = '/homes/eolson/data/largeImages' #imageDir = '/home/eolson/am-macs/data/kuhlmann' imageDir=None # let command line arg override the image path. #if len(sys.argv) > 1 and os.path.exists(sys.argv[1]): # and os.path.isdir(sys.argv[1]): # imageDir = sys.argv[1] if len(sysArgs) > 0 and os.path.exists(sysArgs[0]): # and os.path.isdir(sys.argv[1]): imageDir = sysArgs[0] if options.stream == None and options.groupedStream == None and imageDir == None: imageDir = defaultImageDir # make sure we try to show something on the screen. print "image path to load:", imageDir def IsValidDataType(path): recognizedExtensions = ["png", "jpg", "jpeg", "tif", "tiff", "tga", "gif", "rgb", "rgba", "sgi", "mpg", "mp4", "mov", "vob", "ogv", "avi", "tdmovie"] extension = (path.split(".")[-1]).lower() if extension in recognizedExtensions and not path.startswith("._"): return True else: return False def loadImageOrMovie(objPath, pos=None): if None == objPath: return None thisObjScale = movieScale if "NOAA_TEST.tdmovie" in objPath: # FIXME, add per object scale options thisObjScale = [2.0, 2.0] elif "HeadHeartLiver2.tdmovie" in objPath: thisObjScale = [1.2, 1.2] elif "jai-head2.mp4" in objPath: thisObjScale = [3.0, 3.0] elif "FOAM.tdmovie" in objPath: thisObjScale = [1.8, 1.8] #elif "NEW_DWARF.tdmovie" in objPath: # thisObjScale = [2.0, 2.0] #elif "VORTICITY.tdmovie" in objPath: # thisObjScale = [2.0, 2.0] elif "FUZZY.tdmovie" in objPath: thisObjScale = [2.0, 2.0] #elif "FISCHER.tdmovie" in objPath: # thisObjScale = [2.0, 2.0] #elif "DWARF.tdmovie" in objPath: # thisObjScale = [2.0, 2.0] elif "BGL.tdmovie" in objPath: thisObjScale = [2.0, 2.0] elif "enzo-b4096_2.tdmovie" in objPath: thisObjScale = [1.4, 1.4] elif "Enzo-4096-Evo-res4096x2304.tdmovie" in objPath: thisObjScale = [1.4, 1.4] elif "Enzo-4096-SC09-res4096x2304.tdmovie" in objPath: thisObjScale = [1.3, 1.3] elif "fischer_movie01.tdmovie" in objPath: thisObjScale = [1.0, 1.0] #if None == options.positions: # options.positions = [ (0, -1000) ] elif "FISCHER_MOVIE01" in objPath: if None == options.positions: options.positions = [ (0, -100) ] #elif "enzo-b4096" in objPath: # thisObjScale = [2.0, 2.0] if objPath != None and os.path.exists(objPath): if IsValidDataType(objPath): # some data types are directories print "Creating Obj:", objPath #if None == pos: # pos = (0,30) if IsTiledMoviePath(objPath): movieDims = GetTiledMoviePathDims(objPath) # center obj since there's only one if thisObjScale != None: #pos = [2500 + fullRect.width / 2 - movieDims[0] / 2 * movieScale[0], fullRect.height / 2 - movieDims[1] / 2 * movieScale[1]] if None == pos: pos = [fullRect.width / 2. - movieDims[0] / 2. * thisObjScale[0], fullRect.height / 2. - movieDims[1] / 2. * thisObjScale[1]] else: print "Pos is not None, not recentering movie" else: if None == pos: pos = [fullRect.width / 2. - movieDims[0] / 2., fullRect.height / 2. - movieDims[1] / 2.] print "Recentered Movie position is:", pos, "movieDims:", movieDims, "full display rect:", fullRect elif IsImagePath(objPath): f = Image.open(objPath) imageDims = f.size if None == pos: pos = [fullRect.width / 2 - imageDims[0] / 2, fullRect.height / 2 - imageDims[1] / 2] print "SCALE !!!", thisObjScale obj = CreateObj(objPath, imagePos=pos, scale=thisObjScale) if obj != None: objectsListList.append(obj) else: print "Path is not to a single data file/data item" if os.path.isdir(objPath): imageList = os.listdir(objPath) else: # just one image imageList = [objPath] objPath = "" print "File List:", imageList j = 0 imageList.sort() for i in imageList: extension = i.split(".")[-1] # just guesses so far #if extension.lower() in ["png", "jpg", "jpeg", "tif", "tiff", "tga", "gif", "rgb", "rgba", "sgi", "mpg", "mp4", "mov", "vob", "ogv"] and not i.startswith("._"): if IsValidDataType(i): #obj = CreateObj(os.path.join(objPath,i), imagePos=(3000-j*300,2000-j*200)) pos = (100+j*220,30+j*0) fullPath = os.path.join(objPath, i) if IsTiledMoviePath(fullPath): movieDims = GetTiledMoviePathDims(fullPath) # center tiled movies for now pos = [fullRect.width / 2 - movieDims[0] / 2, fullRect.height / 2 - movieDims[1] / 2] print "Creating Obj:", fullPath obj = CreateObj(fullPath, imagePos=pos, scale=thisObjScale) #obj = CreateObj(os.path.join(objPath,i), imagePos=(0+j*220,0+j*0)) if obj != None: objectsListList.append(obj) j += 1 else: print "skipping file (unhandled extension):", i return obj def loadMovieSequence(moviePaths): if len(movieSequence) > 1: sequenceObj = MovieSequence() else: sequenceObj = None for moviePath in movieSequence: obj = loadImageOrMovie(moviePath) if None != sequenceObj: numLoops = 1 if "NOAA_TEST.tdmovie" in moviePath: numLoops = 5 sequenceObj.append(obj, numLoops) if None != sequenceObj: sequenceObj.initializeObjects() return sequenceObj def loadLayout(layoutPath): layoutEntries = ReadLayout(layoutPath) for entry in layoutEntries: loadImageOrMovie(entry.path, pos=entry.pos) def getNextPosition(): global gPositionsIndex if None != options.positions and gPositionsIndex < len(options.positions): tmpPos = options.positions[gPositionsIndex] gPositionsIndex+=1 return tmpPos return None # load movie layout if specified if options.movieLayouts != None: thisObjScale = movieScale for movieLayout in options.movieLayouts: pos = getNextPosition() obj = CreateObj(movieLayout, imagePos=pos, scale=thisObjScale, objDesc=ObjectDescription(ObjType.TILED_MOVIE_WITH_LAYOUT)) if obj != None: objectsListList.append(obj) # load layout if specified if options.layouts != None: for layout in options.layouts: loadLayout(layout) # load image path if specified (different from default) if imageDir != defaultImageDir: loadImageOrMovie(imageDir, getNextPosition()) elif 0 == len(movieSequences) and None == options.layouts and None == options.movieLayouts: # or load default if no extra options # were specified. loadImageOrMovie(imageDir, getNextPosition()) # default if len(movieSequences) > 0: # load sequences from --sequence for movieSequence in movieSequences: sequenceObj = loadMovieSequence(movieSequence) app.addDynamicObject(sequenceObj, addToRenderer=False) #print "******************", options.stream if options.stream != None: if not gStreamingSupported: raise Exception("Error using --stream. Streaming not supported. Make sure StreamView could be imported.") try: address = options.stream[0] if len(options.stream) > 1: print "WARNING: So far we only handle one stream address. (multiple stream address handling coming soon)" #from streamView import StreamView, StartStreamViewLoop #streamView = StreamView() #obj = CreateObj(None, imagePos=(0, 0), obj=streamView) #objectsListList.append(obj) #StartStreamViewLoop(address) pos = [fullRect.width / 2, fullRect.height / 2 ] print "*********POS:", pos, "from:", fullRect streamWidth = options.streamSize[0][0] streamHeight = options.streamSize[0][1] vflip=False # works for RAW if StreamProtocols.FLX_H261 == streamProtocol: vflip=True streamDesc = objDesc=StreamObjDescription(streamProtocol, (streamWidth,streamHeight), vflip=vflip ) obj = CreateObj(address, imagePos=pos, objDesc=streamDesc, scale=movieScale, gridColsRows=options.streamColsRows) if obj != None: objectsListList.append(obj) except Exception, e: traceback.print_exc()
def run(): print "starting:", mpi.rank os.environ['SDL_VIDEO_WINDOW_POS']="400,300" print "Just after run SDL_VIDEO_WIDOW_POS:", mpi.rank, os.environ['SDL_VIDEO_WINDOW_POS'] rects = [Rect(0,0,1280,1024), Rect(1280,0, 1280,1024)] os.environ["DISPLAY"] = ":0.0" #os.environ['SDL_VIDEO_WINDOW_POS']="0,0" import pygame windowWidth = 2560 # 1280# 320 windowHeight = 1024 # 1024 # 280 app = App(windowWidth, windowHeight) renderers = [] for i in range(len(rects)): displayRect = rects[i] if i == 0: renderer = glRenderer2D(multipleRenderers=True, firstRenderer=True) renderer.addFrameSetupObj(ScreenClearer(color=(.9, .4, .4), clearDepth=False)) else: renderer = glRenderer2D(multipleRenderers=True) renderer.addFrameSetupObj(ScreenClearer(color=(.4, .9, .4), clearDepth=False)) renderers.append(renderer) app.addRenderer(renderer) print "app.initialize", mpi.rank app.initialize(windowBorder=False) for i in range(len(rects)): print "SETTING RECT:", rects[i] renderers[i].init(app.width, app.height, viewportRect=rects[i]) class glBox: def __init__(self): self.hasDrawFunc=True self.hasEraseDrawFunc=True self.visible = True def update(self, app, secs): pass def draw(self, renderer): #glClearColor(.4, .4, .4, 1.0) #glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self, imageFilename="../data/test1.png", initialOffset=(0,0) ): self.hasDrawFunc=True self.hasEraseDrawFunc=True self.visible = True #self.texture = Texture( "../data/test1.png") self.easyTexture = EasyTexture(imageFilename, blend=False) #self.easyTexture.width = renderer.width * 0.8 #self.easyTexture.height = renderer.height * 0.8 self.easyTexture.width = renderer.width self.easyTexture.height = renderer.height self.useDrawPixel = False # For comparison debugging self.useDrawPixel = False # For comparison debugging self.xvel = 0.1 self.yvel = 0.1 self.easyTexture.zoom(2, 2) self.easyTexture.setOffset(initialOffset[0], initialOffset[1]) def update(self, secs, app): self.easyTexture.pan(self.xvel * secs, self.yvel* secs) def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) self.easyTexture.draw() imageFilename="/home/eolson/am-macs/data/JC4-Sol1355A_1358A_DeckPan_L456atc_br2.jpg" glEnable(GL_TEXTURE_2D) for i in range(len(renderers)): rect = rects[i] box = glTxtrBox(imageFilename, initialOffset=(rect.x, rect.y)) app.addDynamicObject(box, addToRenderer=False) renderers[i].addDynamicObject(box) print "Running app" try: app.run() except: traceback.print_exc() #import time #time.sleep(3) print "exiting: ", mpi.rank
def run(): imageFilename = sys.argv[1] windowWidth = 1280 # 320 windowHeight = 1024 # 280 app = App(windowWidth, windowHeight) renderer = glRenderer2D() app.setRenderer(renderer) app.initialize(windowBorder=False) renderer.init(windowWidth, windowHeight) class glBox: def __init__(self): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True def update(self, app, secs): pass def draw(self, renderer): glClearColor(.8, .8, .8, 1.0) glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self, imageFilename="../data/test1.png"): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True #self.texture = Texture( "../data/test1.png") self.easyTexture = EasyTexture(imageFilename, blend=False) #self.easyTexture.width = renderer.width * 0.8 #self.easyTexture.height = renderer.height * 0.8 self.easyTexture.width = renderer.width self.easyTexture.height = renderer.height self.useDrawPixel = False # For comparison debugging self.useDrawPixel = False # For comparison debugging def update(self, app, secs): pass def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) self.easyTexture.draw() box = glBox() app.addDynamicObject(box) glEnable(GL_TEXTURE_2D) box2 = glTxtrBox(imageFilename) app.addDynamicObject(box2) app.drawBounds = 0 print "Running app" app.run()
def run(): tileConfig = CreateAMConfig() # fqdn = getfqdn() hostname = gethostname() machineDesc = tileConfig.getMachineDescByHostname(hostname) localRects = [] absoluteRects = [] for tile in machineDesc.tiles: localRects.append(tileConfig.getLocalDrawRect(tile.uid)) absoluteRects.append(tileConfig.getAbsoluteFullDisplayRect(tile.uid)) print hostname, machineDesc.hostname, localRects, absoluteRects # return fullRect = tileConfig.getMainDisplayRect() if mpi.rank == 0: print "FULL DISPLAY:", fullRect.width, fullRect.height #rects = [Rect(0,0,1280,1024), Rect(1280,0, 1280,1024)] #rects = [Rect(0,0,1280,1024)] os.environ["DISPLAY"] = ":0.0" os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0" imageFilename = sys.argv[1] #windowWidth = 2560 # 1280# 320 #windowWidth = 3840 # 1280# 320 windowWidth = 2560 # 1280# 320 windowHeight = 1024 # 1024 # 280 #windowWidth = 1280 # 1280# 320 #windowHeight = 1024 # 1024 # 280 app = App(windowWidth, windowHeight) renderers = [] for i in range(len(localRects)): displayRect = localRects[i] if i == 0: renderer = glRenderer2D(multipleRenderers=True, firstRenderer=True) renderer.addFrameSetupObj( ScreenClearer(color=(.0, .0, .0), clearDepth=False)) else: renderer = glRenderer2D(multipleRenderers=True) renderer.addFrameSetupObj( ScreenClearer(color=(.0, .0, .0), clearDepth=False)) renderers.append(renderer) app.addRenderer(renderer) # app.initialize(windowBorder=False) app.initialize(windowBorder=True) for i in range(len(localRects)): print "SETTING RECT:", localRects[i] renderers[i].init(app.width, app.height, viewportRect=localRects[i]) class glBox: def __init__(self): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True def update(self, app, secs): pass def draw(self, renderer): #glClearColor(.4, .4, .4, 1.0) #glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self, imageFilename, screenRect, fullRect, absRect, initialOffset=(0, 0), zoom=(4, 4), imagePos=(0, 0), imageSize=None): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True self.texture = Texture(imageFilename) #self.easyTexture = EasyTexture(imageFilename, screenGeomRect=screenRect, blend=False) #self.easyTexture.width = renderer.width * 0.8 #self.easyTexture.height = renderer.height * 0.8 #self.easyTexture.width = renderer.width #self.easyTexture.height = renderer.height self.useDrawPixel = False # For comparison debugging self.xvel = 0.1 self.yvel = 0.1 self.zoom = zoom #self.easyTexture.zoom(zoom[0], zoom[1]) #self.easyTexture.setOffset(initialOffset[0], initialOffset[1]) self.autoPan = True self.imagePos = Vec2(imagePos[0], imagePos[1]) if imageSize == None: self.imageSize = self.texture.getWidth( ), self.texture.getHeight() else: self.imageSize = imageSize self.fullRect = fullRect self.absRect = absRect self.screenRect = screenRect def getPos(self): return (self.imagePos.x, self.imagePos.y) def setPos(self, x, y): self.imagePos = Vec2(x, y) def update(self, secs, app): pass #if self.autoPan: # self.easyTexture.pan(self.xvel * secs, self.yvel* secs) def pan(self, xchange, ychange): if mpi.rank == 1: print "Panning:", xchange, ychange #self.easyTexture.pan(xchange * 300, ychange * 300) def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) # convert to local coords localBtmLeft = Vec2(self.imagePos.x - self.absRect.x, self.imagePos.y - self.absRect.y) localTopRight = Vec2(localBtmLeft.x + self.imageSize[0], localBtmLeft.y + self.imageSize[1]) localBtmLeft = Vec2(max(localBtmLeft.x, 0), max(localBtmLeft.y, 0)) localTopRight = Vec2(min(localTopRight.x, self.screenRect.width), min(localTopRight.y, self.screenRect.height)) blitSize = Vec2(localTopRight.x - localBtmLeft.x, localTopRight.y - localBtmLeft.y) # convert clipped local coords back to global coords find the source rect globalBtmLeft = Vec2(localBtmLeft.x + self.absRect.x, localBtmLeft.y + self.absRect.y) globalTopRight = Vec2(localTopRight.x + self.absRect.x, localTopRight.y + self.absRect.y) # convert global coords to txtr coords offset = Vec2(globalBtmLeft.x - self.imagePos.x, globalBtmLeft.y - self.imagePos.y) size = (globalTopRight.x - globalBtmLeft.x, globalTopRight.y - globalBtmLeft.y) if size[0] > 0 and size[1] > 0: self.texture.blit(localBtmLeft, Rect(offset.x, offset.y, size[0], size[1]), (renderer.width, renderer.height)) #self.easyTexture.draw() #box = glBox() #app.addDynamicObject(box) glEnable(GL_TEXTURE_2D) boxes = [] for i in range(len(renderers)): absRect = absoluteRects[i] locRect = localRects[i] renderer = renderers[i] box = glTxtrBox(imageFilename, screenRect=Rect(0, 0, locRect.width, locRect.height), imagePos=(2000, 500), absRect=absRect, fullRect=fullRect) # to scale, change the geometry and the txtr coords: imageSize and #box.imageSize = (box.imageSize[0]*2, box.imageSize[1]*2) #box.easyTexture.zoom(5,1) #box.easyTexture.setOffset( (absRect.x % float(box.easyTexture.getWidth())) / box.easyTexture.getWidth(), # (absRect.y % float(box.easyTexture.getHeight())) / box.easyTexture.getHeight() ) # box.easyTexture.setWidth( float(locRect.width) / float(box.easyTexture.getHeight()) ) #zoom = (0.5,1) #box.easyTexture.setZoom(zoom[0], zoom[1]) #box.easyTexture.setOffset(absRect.x * zoom[0] ,absRect.y * zoom[1]) #box.easyTexture.setZoom(float(box.easyTexture.getWidth()) / localRect.width, # float(box.easyTexture.getHeight()) / localRect.height ) # scale offset back by zoom (offset is between 0 and 1) #box.easyTexture.setOffset( float(rect.x) / fullRect.width * box.easyTexture.getWidth(), # float(rect.y) / fullRect.height * box.easyTexture.getHeight()) app.addDynamicObject(box, addToRenderer=False) renderers[i].addDynamicObject(box) boxes.append(box) app.drawBounds = 0 # setup control def setupMoteControl(panningObjects, app, displayWidth, displayHeight): tileMote = TileMote(panningObjects, displayWidth, displayHeight) if mpi.rank == 0: mote = connectToMote() moteMouse = MoteMouse(mote, tileMote) else: moteMouse = None mote = None class MouseUpdater: def __init__(self, moteMouse, tileMote): self.moteMouse = moteMouse self.tileMote = tileMote def update(self, app, secs): # process data from device if mpi.rank == 0: self.moteMouse.processAndUpdateMouse() # send data to all nodes and apply self.tileMote.syncAndApply() app.addDynamicObject(MouseUpdater(moteMouse, tileMote), addToRenderer=False) return mote, moteMouse, tileMote mote = None for arg in sys.argv: if "wii" in arg.lower(): mote, moteMouse, tileMote = setupMoteControl( boxes, app, fullRect.width, fullRect.height) for box in boxes: box.autoPan = False break # break out of this loop class Syncer: def __init__(self, cursorObjectsListList=None): # list of lists: [ [a1,a2,a3], [b1,b2] ] # access: cursor[i][localcopies] # only the first object for each cursors is read, all are written if cursorObjectsListList == None: self.cursorObjects = [] else: self.cursorObjects = cursorObjectsListList self.cursors = [] for obj in self.cursorObjects: self.cursors.append((0, 0)) self.resultCursors = [] if mpi.rank == 0: self.dataLock = Lock() def update(self, app, secs): self.syncAndApply() def syncAndApply(self): if mpi.rank == 0: self.dataLock.acquire( ) # this lock probably isn't necessary yet try: for i in range(len(self.cursorObjects)): self.cursors[i] = self.cursorObjects[i][0].getPos() except: traceback.print_exc() finally: self.dataLock.release() if mpi.rank == 0: resultCursors = mpi.bcast(self.cursors) else: self.resultCursors = mpi.bcast() if mpi.rank != 0: for i in range(len(self.cursorObjects)): if len(self.resultCursors) > i: # access: cursorObjects[i][localcopies] for j in range(len(self.cursorObjects[i]) ): # set for each local copy self.cursorObjects[i][j].setPos( self.resultCursors[i][0], self.resultCursors[i][1]) #if len(resultQueue) > 0: # print "Bcasting recv:", resultQueue, mpi.rank class CursorAutoMover: def __init__(self, target, xrange=(0, 5000), yrange=(0, 3000), xvel=100, yvel=100): self.target = target self.xvel = xvel self.yvel = yvel self.xrange = xrange self.yrange = yrange self.visible = False def draw(self): pass def update(self, secs, app): posTuple = self.target.getPos() pos = Vec2(posTuple[0], posTuple[1]) pos.x = pos.x + self.xvel * secs pos.y = pos.y + self.yvel * secs if pos.x > self.xrange[1]: self.xvel = -abs(self.xvel) if pos.y > self.yrange[1]: self.yvel = -abs(self.yvel) if pos.x < self.xrange[0]: self.xvel = abs(self.xvel) if pos.y < self.xrange[0]: self.yvel = abs(self.yvel) self.target.setPos(pos.x, pos.y) # print "pos:", pos.x, pos.y #class Cursor: def CreateCursor(x=500, y=500, xvel=100, yvel=100): tmpCursors = [] for i in range(len(renderers)): absRect = absoluteRects[i] locRect = localRects[i] renderer = renderers[i] cursor = glTxtrBox("../../../../data/fl-logo-color-small.gif", screenRect=Rect(0, 0, locRect.width, locRect.height), imagePos=(x, y), absRect=absRect, fullRect=fullRect) app.addDynamicObject(cursor, addToRenderer=False) renderers[i].addDynamicObject(cursor) tmpCursors.append(cursor) # change this to only happen on master and sync if mpi.rank == 0: app.addDynamicObject(CursorAutoMover(cursor, xrange=(0, fullRect.width), yrange=(0, fullRect.height), xvel=xvel, yvel=yvel), addToRenderer=False) return tmpCursors numCursors = 3 cursorListList = [] for i in range(numCursors): nodeCursors = CreateCursor(x=randrange(0, fullRect.width), y=randrange(0, fullRect.height), xvel=randrange(200, 400), yvel=randrange(200, 400)) cursorListList.append(nodeCursors) # print mpi.rank, " cursor list:", cursorListList syncer = Syncer(cursorListList) app.addDynamicObject(syncer, addToRenderer=False) print "Running app" try: app.run() except: traceback.print_exc() finally: if mpi.rank == 0: if mote != None: mote.disconnect() if mote.readThread != None: print "Exiting, joining thread" mote.readThread.join()
r = PyFfmpegMovieReader() #r.loadFile("/home/eolson/Desktop/jai-head2.mp4") #r.setFile("/home/eolson/fl/notes/viz/tomo1.mpg") if len(sys.argv) > 1: r.setFile(sys.argv[1]) else: r.setFile("/home/eolson/blah_mpeg1.mpg") # Note: Example to encode an mpeg1 file readable by pygame.Movie: # mencoder original.avi -of mpeg -mpegopts format=mpeg1:tsaf:muxrate=2000 -o test.mpg -srate 44100 -af lavcresample=44100 -oac twolame -twolameopts br=160 -ovc lavc -lavcopts vcodec=mpeg1video:vbitrate=1152:keyint=15:mbd=2 # Setup window, etc. windowWidth = 1000 # 320 windowHeight = 700 # 280 app = App(windowWidth, windowHeight) renderer = glRenderer2D() app.setRenderer(renderer) app.initialize() renderer.init(windowWidth, windowHeight) glEnable(GL_TEXTURE_2D) r.loadFile() p = GLMoviePlayer(origWidth=r.getSize()[0], origHeight=r.getSize()[1]) #p.setPos(50, 200) p.setPos(50, 0) #p.setPos(50, -50) p.setVideoSource(r) r.start()
def run(): tileConfig = CreateAMConfig() # fqdn = getfqdn() hostname = gethostname() machineDesc = tileConfig.getMachineDescByHostname(hostname) localRects = [] absoluteRects = [] for tile in machineDesc.tiles: localRects.append(tileConfig.getLocalDrawRect(tile.uid)) absoluteRects.append(tileConfig.getAbsoluteFullDisplayRect(tile.uid)) print hostname, machineDesc.hostname, localRects, absoluteRects # return fullRect = tileConfig.getMainDisplayRect() if mpi.rank == 0: print "FULL DISPLAY:", fullRect.width, fullRect.height #rects = [Rect(0,0,1280,1024), Rect(1280,0, 1280,1024)] #rects = [Rect(0,0,1280,1024)] os.environ["DISPLAY"] = ":0.0" os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0" imageFilename = sys.argv[1] #windowWidth = 2560 # 1280# 320 #windowWidth = 3840 # 1280# 320 windowWidth = 2560 # 1280# 320 windowHeight = 1024 # 1024 # 280 #windowWidth = 1280 # 1280# 320 #windowHeight = 1024 # 1024 # 280 app = App(windowWidth, windowHeight) renderers = [] for i in range(len(localRects)): displayRect = localRects[i] if i == 0: renderer = glRenderer2D(multipleRenderers=True, firstRenderer=True) renderer.addFrameSetupObj( ScreenClearer(color=(.9, .4, .4), clearDepth=False)) else: renderer = glRenderer2D(multipleRenderers=True) renderer.addFrameSetupObj( ScreenClearer(color=(.4, .9, .4), clearDepth=False)) renderers.append(renderer) app.addRenderer(renderer) # app.initialize(windowBorder=False) app.initialize(windowBorder=True) for i in range(len(localRects)): print "SETTING RECT:", localRects[i] renderers[i].init(app.width, app.height, viewportRect=localRects[i]) class glBox: def __init__(self): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True def update(self, app, secs): pass def draw(self, renderer): #glClearColor(.4, .4, .4, 1.0) #glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self, imageFilename, screenRect, fullRect, absRect, initialOffset=(0, 0), zoom=(4, 4), imagePos=(0, 0), imageSize=None): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True self.texture = Texture(imageFilename) #self.easyTexture = EasyTexture(imageFilename, screenGeomRect=screenRect, blend=False) #self.easyTexture.width = renderer.width * 0.8 #self.easyTexture.height = renderer.height * 0.8 #self.easyTexture.width = renderer.width #self.easyTexture.height = renderer.height self.useDrawPixel = False # For comparison debugging self.xvel = 0.1 self.yvel = 0.1 self.zoom = zoom #self.easyTexture.zoom(zoom[0], zoom[1]) #self.easyTexture.setOffset(initialOffset[0], initialOffset[1]) self.autoPan = True self.imagePos = imagePos if imageSize == None: self.imageSize = self.texture.getWidth( ), self.texture.getHeight() else: self.imageSize = imageSize self.fullRect = fullRect self.absRect = absRect self.screenRect = screenRect def update(self, secs, app): pass #if self.autoPan: # self.easyTexture.pan(self.xvel * secs, self.yvel* secs) def pan(self, xchange, ychange): if mpi.rank == 1: print "Panning:", xchange, ychange #self.easyTexture.pan(xchange * 300, ychange * 300) def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) # convert to local coords localBtmLeft = Vec2(self.imagePos[0] - self.absRect.x, self.imagePos[1] - self.absRect.y) localTopRight = Vec2(localBtmLeft.x + self.imageSize[0], localBtmLeft.y + self.imageSize[1]) localBtmLeft = Vec2(max(localBtmLeft.x, 0), max(localBtmLeft.y, 0)) localTopRight = Vec2(min(localTopRight.x, self.screenRect.width), min(localTopRight.y, self.screenRect.height)) blitSize = Vec2(localTopRight.x - localBtmLeft.x, localTopRight.y - localBtmLeft.y) # convert clipped local coords back to global coords find the source rect globalBtmLeft = Vec2(localBtmLeft.x + self.absRect.x, localBtmLeft.y + self.absRect.y) globalTopRight = Vec2(localTopRight.x + self.absRect.x, localTopRight.y + self.absRect.y) # convert global coords to txtr coords offset = Vec2(globalBtmLeft.x - self.imagePos[0], globalBtmLeft.y - self.imagePos[1]) size = (globalTopRight.x - globalBtmLeft.x, globalTopRight.y - globalBtmLeft.y) if size[0] > 0 and size[1] > 0: self.texture.blit(localBtmLeft, Rect(offset.x, offset.y, size[0], size[1]), (renderer.width, renderer.height)) #self.easyTexture.draw() #box = glBox() #app.addDynamicObject(box) glEnable(GL_TEXTURE_2D) boxes = [] for i in range(len(renderers)): absRect = absoluteRects[i] locRect = localRects[i] renderer = renderers[i] box = glTxtrBox(imageFilename, screenRect=Rect(0, 0, locRect.width, locRect.height), imagePos=(2000, 500), absRect=absRect, fullRect=fullRect) # to scale, change the geometry and the txtr coords: imageSize and #box.imageSize = (box.imageSize[0]*2, box.imageSize[1]*2) #box.easyTexture.zoom(5,1) #box.easyTexture.setOffset( (absRect.x % float(box.easyTexture.getWidth())) / box.easyTexture.getWidth(), # (absRect.y % float(box.easyTexture.getHeight())) / box.easyTexture.getHeight() ) # box.easyTexture.setWidth( float(locRect.width) / float(box.easyTexture.getHeight()) ) #zoom = (0.5,1) #box.easyTexture.setZoom(zoom[0], zoom[1]) #box.easyTexture.setOffset(absRect.x * zoom[0] ,absRect.y * zoom[1]) #box.easyTexture.setZoom(float(box.easyTexture.getWidth()) / localRect.width, # float(box.easyTexture.getHeight()) / localRect.height ) # scale offset back by zoom (offset is between 0 and 1) #box.easyTexture.setOffset( float(rect.x) / fullRect.width * box.easyTexture.getWidth(), # float(rect.y) / fullRect.height * box.easyTexture.getHeight()) app.addDynamicObject(box, addToRenderer=False) renderers[i].addDynamicObject(box) boxes.append(box) app.drawBounds = 0 # setup control def setupMoteControl(panningObjects, app, displayWidth, displayHeight): tileMote = TileMote(panningObjects, displayWidth, displayHeight) if mpi.rank == 0: mote = connectToMote() moteMouse = MoteMouse(mote, tileMote) else: moteMouse = None mote = None class MouseUpdater: def __init__(self, moteMouse, tileMote): self.moteMouse = moteMouse self.tileMote = tileMote def update(self, app, secs): # process data from device if mpi.rank == 0: self.moteMouse.processAndUpdateMouse() # send data to all nodes and apply self.tileMote.syncAndApply() app.addDynamicObject(MouseUpdater(moteMouse, tileMote), addToRenderer=False) return mote, moteMouse, tileMote mote = None for arg in sys.argv: if "wii" in arg.lower(): mote, moteMouse, tileMote = setupMoteControl( boxes, app, fullRect.width, fullRect.height) for box in boxes: box.autoPan = False break # break out of this loop print "Running app" try: app.run() except: traceback.print_exc() finally: if mpi.rank == 0: if mote != None: mote.disconnect() if mote.readThread != None: print "Exiting, joining thread" mote.readThread.join()
def run(): windowWidth = 1024 / 2 # 320 windowHeight = 768 /2 # 280 app = App(windowWidth, windowHeight) renderer = glRenderer2D() app.setRenderer(renderer) app.initialize() renderer.init(windowWidth, windowHeight) renderer.addFrameSetupObj(ScreenClearer( (0.8, 0.8, 0.8), clearDepth=False)) """ glDisable(GL_DEPTH_TEST) #use our zbuffer glDisable(GL_LIGHTING) #use our zbuffer glMatrixMode(GL_PROJECTION) glLoadIdentity() gluOrtho2D(0, windowWidth, 0, windowHeight) glColor3f(1,1,0) """ class pointListRenderer: M_BASIC = 0 M_EXT = 1 M_FULL = 2 def __init__(self): self.hasDrawFunc=True self.hasEraseDrawFunc=True self.visible = True self.points = [ (0.5, 0.5) ] self.pointsAndSize = [ (0.5, 0.5, 1.0) ] self.pointsFull = [ (0.5, 0.5, 1.0, 0.40, 0.45, 0.60, 0.55, 1.0) ] self.color = (0.4, 0.4, 0.9) self.lineColor = (0.4, 0.9, 0.4) self.pointSize = 10 self.lineWidth = 2 self.mode = self.M_BASIC def setPointsFromList(self, pointList): self.points = pointList def setPointsAndSizeFromList(self, pointList): self.pointsAndSize = pointList def setPointsFullFromList(self, pointList): self.pointsFull = pointList def update(self, app, secs): pass def eraseDraw(self, app): pass def draw(self, renderer): glColor3fv(self.color) if self.mode == self.M_BASIC: glPointSize(self.pointSize) glBegin(GL_POINTS) # print "drawing: ", self.points for p in self.points: glVertex2f(p[0] * renderer.width, p[1] * renderer.height) glEnd() elif self.mode == self.M_EXT: # print "drawing: ", self.points for p in self.pointsAndSize: glPointSize(self.pointSize * (p[2] + 0.5)) glBegin(GL_POINTS) glVertex2f(p[0] * renderer.width, p[1] * renderer.height) glEnd() elif self.mode == self.M_FULL: glColor3fv(self.color) for p in self.pointsFull: glPointSize(self.pointSize * (p[7] + 0.5)) glBegin(GL_POINTS) glVertex2f(p[0] * renderer.width, p[1] * renderer.height) glEnd() glColor3fv(self.lineColor) for p in self.pointsFull: glLineWidth(self.lineWidth * (p[7] + 0.5)) glBegin(GL_LINE_LOOP) glVertex2f(p[3] * renderer.width, p[4] * renderer.height) glVertex2f(p[5] * renderer.width, p[4] * renderer.height) glVertex2f(p[5] * renderer.width, p[6] * renderer.height) glVertex2f(p[3] * renderer.width, p[6] * renderer.height) glEnd() else: raise Exception("Unimplemented pointList draw mode" + str(self.mode)) points = pointListRenderer() app.addDynamicObject(points) app.drawBounds = 0 class motePointProcessor: def __init__(self, mote, pointsView): self.hasDrawFunc=False self.mote = mote self.pointsView = pointsView if mote.irMode == "f": self.pointsView.mode = self.pointsView.M_FULL elif mote.irMode == "e": self.pointsView.mode = self.pointsView.M_EXT else: # mote.irMode == "b": self.pointsView.mode = self.pointsView.M_BASIC def draw(self, renderer): pass def update(self, app, secs): if self.mote.irMode == "f": points = self.mote.extractNormalizedPointsFull() if len(points) > 0: # print "setting points:", points[-1] self.pointsView.setPointsFullFromList(points[-1]) elif self.mote.irMode == "e": points = self.mote.extractNormalizedPointsAndSize() if len(points) > 0: # print "setting points:", points[-1] self.pointsView.setPointsAndSizeFromList(points[-1]) else: # irMode == "b" points = self.mote.extractNormalizedPoints() if len(points) > 0: # print "setting points:", points[-1] self.pointsView.setPointsFromList(points[-1]) mote = connectToMote() # mote = None processor = motePointProcessor(mote, points) app.addDynamicObject(processor) print "Running app" try: app.run() except: traceback.print_exc() finally: mote.disconnect() if mote.readThread != None: print "Exiting, joining thread" mote.readThread.join()
def run(): windowWidth = 320 windowHeight = 280 app = App(windowWidth, windowHeight) renderer = glRenderer2D() app.setRenderer(renderer) app.initialize() renderer.init(windowWidth, windowHeight) renderer.addFrameSetupObj(ScreenClearer( (0.8, 0.8, 0.8), clearDepth=False)) """ glDisable(GL_DEPTH_TEST) #use our zbuffer glDisable(GL_LIGHTING) #use our zbuffer glMatrixMode(GL_PROJECTION) glLoadIdentity() gluOrtho2D(0, windowWidth, 0, windowHeight) glColor3f(1,1,0) """ class pointListRenderer: def __init__(self): self.hasDrawFunc=True self.hasEraseDrawFunc=True self.visible = True self.points = [ (0.5, 0.5) ] self.color = (0.4, 0.4, 0.9) self.pointSize = 10 def setPointsFromList(self, pointList): self.points = pointList def update(self, app, secs): pass def eraseDraw(self, app): pass def draw(self, renderer): glColor3fv(self.color) glPointSize(self.pointSize) glBegin(GL_POINTS) # print "drawing: ", self.points for p in self.points: glVertex2f(p[0] * renderer.width, p[1] * renderer.height) glEnd() points = pointListRenderer() app.addDynamicObject(points) app.drawBounds = 0 class motePointProcessor: def __init__(self, mote, pointsView): self.hasDrawFunc=False self.mote = mote self.pointsView = pointsView def draw(self, renderer): pass def update(self, app, secs): points = self.mote.extractNormalizedPoints() if len(points) > 0: # print "setting points:", points[-1] self.pointsView.setPointsFromList(points[-1]) mote = connectToMote() # mote = None processor = motePointProcessor(mote, points) app.addDynamicObject(processor) print "Running app" try: app.run() except: traceback.print_exc() finally: mote.disconnect() if mote.readThread != None: print "Exiting, joining thread" mote.readThread.join()
def run(): mpi.barrier() print "run", mpi.rank mpi.barrier() os.environ['SDL_VIDEO_WINDOW_POS'] = "400,300" print "Just after run SDL_VIDEO_WIDOW_POS:", mpi.rank, os.environ[ 'SDL_VIDEO_WINDOW_POS'] print "run", mpi.rank """ tileConfig = CreateAMConfig() # fqdn = getfqdn() hostname = gethostname() machineDesc = tileConfig.getMachineDescByHostname(hostname) tileRects = [] rects = [] for tile in machineDesc.tiles: # tileConfig.getLocalDrawRect() rects.append(tileConfig.getAbsoluteFullDisplayRect(tile.uid)) print hostname, machineDesc.hostname, rects # return """ rects = [Rect(0, 0, 1280, 1024), Rect(1280, 0, 1280, 1024)] #rects = [Rect(0,0,1280,1024)] os.environ["DISPLAY"] = ":0.0" #os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0" os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0" import pygame os.system("export SDL_VIDEO_WINDOW_POS=0,0") imageFilename = sys.argv[1] #windowWidth = 2560 # 1280# 320 #windowWidth = 3840 # 1280# 320 windowWidth = 2560 # 1280# 320 windowHeight = 1024 # 1024 # 280 #windowWidth = 1280 # 1280# 320 #windowHeight = 1024 # 1024 # 280 app = App(windowWidth, windowHeight) renderers = [] for i in range(len(rects)): displayRect = rects[i] if i == 0: renderer = glRenderer2D(multipleRenderers=True, firstRenderer=True) renderer.addFrameSetupObj( ScreenClearer(color=(.9, .4, .4), clearDepth=False)) else: renderer = glRenderer2D(multipleRenderers=True) renderer.addFrameSetupObj( ScreenClearer(color=(.4, .9, .4), clearDepth=False)) renderers.append(renderer) app.addRenderer(renderer) print "app.initialize" app.initialize(windowBorder=False) #app.initialize(windowBorder=True) for i in range(len(rects)): print "SETTING RECT:", rects[i] renderers[i].init(app.width, app.height, viewportRect=rects[i]) class glBox: def __init__(self): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True def update(self, app, secs): pass def draw(self, renderer): #glClearColor(.4, .4, .4, 1.0) #glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self, imageFilename="../data/test1.png", initialOffset=(0, 0)): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True #self.texture = Texture( "../data/test1.png") self.easyTexture = EasyTexture(imageFilename, blend=False) #self.easyTexture.width = renderer.width * 0.8 #self.easyTexture.height = renderer.height * 0.8 self.easyTexture.width = renderer.width self.easyTexture.height = renderer.height self.useDrawPixel = False # For comparison debugging self.useDrawPixel = False # For comparison debugging self.xvel = 0.1 self.yvel = 0.1 self.easyTexture.zoom(2, 2) self.easyTexture.setOffset(initialOffset[0], initialOffset[1]) def update(self, secs, app): self.easyTexture.pan(self.xvel * secs, self.yvel * secs) def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) self.easyTexture.draw() #box = glBox() #app.addDynamicObject(box) glEnable(GL_TEXTURE_2D) for i in range(len(renderers)): rect = rects[i] box = glTxtrBox(imageFilename, initialOffset=(rect.x, rect.y)) app.addDynamicObject(box, addToRenderer=False) renderers[i].addDynamicObject(box) app.drawBounds = 0 print "Running app" try: app.run() except: traceback.print_exc()
def run(): """ tileConfig = CreateAMConfig() # fqdn = getfqdn() hostname = gethostname() machineDesc = tileConfig.getMachineDescByHostname(hostname) tileRects = [] rects = [] for tile in machineDesc.tiles: # tileConfig.getLocalDrawRect() rects.append(tileConfig.getAbsoluteFullDisplayRect(tile.uid)) print hostname, machineDesc.hostname, rects # return """ rects = [Rect(0,0,1280,1024), Rect(1280,0, 1280,1024)] #rects = [Rect(0,0,1280,1024)] os.environ["DISPLAY"] = ":0.0" #os.environ['SDL_VIDEO_WINDOWPOS'] = "0,0" imageFilename = sys.argv[1] #windowWidth = 2560 # 1280# 320 #windowWidth = 3840 # 1280# 320 windowWidth = 2560 # 1280# 320 windowHeight = 1024 # 1024 # 280 #windowWidth = 1280 # 1280# 320 #windowHeight = 1024 # 1024 # 280 app = App(windowWidth, windowHeight) renderers = [] for i in range(len(rects)): displayRect = rects[i] if i == 0: renderer = glRenderer2D(multipleRenderers=True, firstRenderer=True) renderer.addFrameSetupObj(ScreenClearer(color=(.9, .4, .4), clearDepth=False)) else: renderer = glRenderer2D(multipleRenderers=True) renderer.addFrameSetupObj(ScreenClearer(color=(.4, .9, .4), clearDepth=False)) renderers.append(renderer) app.addRenderer(renderer) # app.initialize(windowBorder=False) app.initialize(windowBorder=True) for i in range(len(rects)): print "SETTING RECT:", rects[i] renderers[i].init(app.width, app.height, viewportRect=rects[i]) class glBox: def __init__(self): self.hasDrawFunc=True self.hasEraseDrawFunc=True self.visible = True def update(self, app, secs): pass def draw(self, renderer): #glClearColor(.4, .4, .4, 1.0) #glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self, imageFilename="../data/test1.png", initialOffset=(0,0) ): self.hasDrawFunc=True self.hasEraseDrawFunc=True self.visible = True #self.texture = Texture( "../data/test1.png") self.easyTexture = EasyTexture(imageFilename, blend=False) #self.easyTexture.width = renderer.width * 0.8 #self.easyTexture.height = renderer.height * 0.8 self.easyTexture.width = renderer.width self.easyTexture.height = renderer.height self.useDrawPixel = False # For comparison debugging self.useDrawPixel = False # For comparison debugging self.xvel = 0.1 self.yvel = 0.1 self.easyTexture.zoom(2, 2) self.easyTexture.setOffset(initialOffset[0], initialOffset[1]) def update(self, secs, app): self.easyTexture.pan(self.xvel * secs, self.yvel* secs) def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) self.easyTexture.draw() #box = glBox() #app.addDynamicObject(box) glEnable(GL_TEXTURE_2D) for i in range(len(renderers)): rect = rects[i] box = glTxtrBox(imageFilename, initialOffset=(rect.x, rect.y)) app.addDynamicObject(box, addToRenderer=False) renderers[i].addDynamicObject(box) app.drawBounds = 0 print "Running app" app.run()
def run(): print "starting:", mpi.rank os.environ['SDL_VIDEO_WINDOW_POS'] = "400,300" print "Just after run SDL_VIDEO_WIDOW_POS:", mpi.rank, os.environ[ 'SDL_VIDEO_WINDOW_POS'] rects = [Rect(0, 0, 1280, 1024), Rect(1280, 0, 1280, 1024)] os.environ["DISPLAY"] = ":0.0" #os.environ['SDL_VIDEO_WINDOW_POS']="0,0" import pygame windowWidth = 2560 # 1280# 320 windowHeight = 1024 # 1024 # 280 app = App(windowWidth, windowHeight) renderers = [] for i in range(len(rects)): displayRect = rects[i] if i == 0: renderer = glRenderer2D(multipleRenderers=True, firstRenderer=True) renderer.addFrameSetupObj( ScreenClearer(color=(.9, .4, .4), clearDepth=False)) else: renderer = glRenderer2D(multipleRenderers=True) renderer.addFrameSetupObj( ScreenClearer(color=(.4, .9, .4), clearDepth=False)) renderers.append(renderer) app.addRenderer(renderer) print "app.initialize", mpi.rank app.initialize(windowBorder=False) for i in range(len(rects)): print "SETTING RECT:", rects[i] renderers[i].init(app.width, app.height, viewportRect=rects[i]) class glBox: def __init__(self): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True def update(self, app, secs): pass def draw(self, renderer): #glClearColor(.4, .4, .4, 1.0) #glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self, imageFilename="../data/test1.png", initialOffset=(0, 0)): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True #self.texture = Texture( "../data/test1.png") self.easyTexture = EasyTexture(imageFilename, blend=False) #self.easyTexture.width = renderer.width * 0.8 #self.easyTexture.height = renderer.height * 0.8 self.easyTexture.width = renderer.width self.easyTexture.height = renderer.height self.useDrawPixel = False # For comparison debugging self.useDrawPixel = False # For comparison debugging self.xvel = 0.1 self.yvel = 0.1 self.easyTexture.zoom(2, 2) self.easyTexture.setOffset(initialOffset[0], initialOffset[1]) def update(self, secs, app): self.easyTexture.pan(self.xvel * secs, self.yvel * secs) def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) self.easyTexture.draw() imageFilename = "/home/eolson/am-macs/data/JC4-Sol1355A_1358A_DeckPan_L456atc_br2.jpg" glEnable(GL_TEXTURE_2D) for i in range(len(renderers)): rect = rects[i] box = glTxtrBox(imageFilename, initialOffset=(rect.x, rect.y)) app.addDynamicObject(box, addToRenderer=False) renderers[i].addDynamicObject(box) print "Running app" try: app.run() except: traceback.print_exc() #import time #time.sleep(3) print "exiting: ", mpi.rank
#r.setFile("/home/eolson/blah_mpeg1.mpg") moviePath = "/home/eolson/blah_mpeg1.mpg" if len(sys.argv) > 1: moviePath = sys.argv[1] r.setFile(moviePath) # Note: Example to encode an mpeg1 file readable by pygame.Movie: # mencoder original.avi -of mpeg -mpegopts format=mpeg1:tsaf:muxrate=2000 -o test.mpg -srate 44100 -af lavcresample=44100 -oac twolame -twolameopts br=160 -ovc lavc -lavcopts vcodec=mpeg1video:vbitrate=1152:keyint=15:mbd=2 # Setup window, etc. #windowWidth = 1000# 320 #windowHeight = 800 # 280 windowWidth = 800 windowHeight = 700 # 280 app = App(windowWidth, windowHeight) renderer = glRenderer2D() app.setRenderer(renderer) app.initialize() renderer.init(windowWidth, windowHeight) glEnable(GL_TEXTURE_2D) r.loadFile() p = GLMoviePlayer(origWidth=r.getSize()[0], origHeight=r.getSize()[1]) #p.setPos(50, 200) p.setPos(50, 0) #p.setPos(50, -50) p.setVideoSource(r) r.start()
def run(): tileConfig = CreateAMConfig() # fqdn = getfqdn() hostname = gethostname() machineDesc = tileConfig.getMachineDescByHostname(hostname) localRects = [] absoluteRects = [] for tile in machineDesc.tiles: localRects.append(tileConfig.getLocalDrawRect(tile.uid)) absoluteRects.append(tileConfig.getAbsoluteFullDisplayRect(tile.uid)) print hostname, machineDesc.hostname, localRects, absoluteRects # return fullRect = tileConfig.getMainDisplayRect() if mpi.rank == 0: print "FULL DISPLAY:", fullRect.width, fullRect.height #rects = [Rect(0,0,1280,1024), Rect(1280,0, 1280,1024)] #rects = [Rect(0,0,1280,1024)] os.environ["DISPLAY"] = ":0.0" os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0" imageFilename = sys.argv[1] #windowWidth = 2560 # 1280# 320 #windowWidth = 3840 # 1280# 320 windowWidth = 2560 # 1280# 320 windowHeight = 1024 # 1024 # 280 #windowWidth = 1280 # 1280# 320 #windowHeight = 1024 # 1024 # 280 app = App(windowWidth, windowHeight) renderers = [] for i in range(len(localRects)): displayRect = localRects[i] if i == 0: renderer = glRenderer2D(multipleRenderers=True, firstRenderer=True) renderer.addFrameSetupObj(ScreenClearer(color=(.0, .0, .0), clearDepth=False)) else: renderer = glRenderer2D(multipleRenderers=True) renderer.addFrameSetupObj(ScreenClearer(color=(.0, .0, .0), clearDepth=False)) renderers.append(renderer) app.addRenderer(renderer) # app.initialize(windowBorder=False) app.initialize(windowBorder=True) for i in range(len(localRects)): print "SETTING RECT:", localRects[i] renderers[i].init(app.width, app.height, viewportRect=localRects[i]) class glBox: def __init__(self): self.hasDrawFunc=True self.hasEraseDrawFunc=True self.visible = True def update(self, app, secs): pass def draw(self, renderer): #glClearColor(.4, .4, .4, 1.0) #glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self, imageFilename, screenRect, fullRect, absRect, initialOffset=(0,0), zoom=(4,4), imagePos=(0,0), imageSize=None ): self.hasDrawFunc=True self.hasEraseDrawFunc=True self.visible = True self.texture = Texture( imageFilename) #self.easyTexture = EasyTexture(imageFilename, screenGeomRect=screenRect, blend=False) #self.easyTexture.width = renderer.width * 0.8 #self.easyTexture.height = renderer.height * 0.8 #self.easyTexture.width = renderer.width #self.easyTexture.height = renderer.height self.useDrawPixel = False # For comparison debugging self.xvel = 0.1 self.yvel = 0.1 self.zoom = zoom #self.easyTexture.zoom(zoom[0], zoom[1]) #self.easyTexture.setOffset(initialOffset[0], initialOffset[1]) self.autoPan = True self.imagePos = Vec2(imagePos[0], imagePos[1]) if imageSize == None: self.imageSize = self.texture.getWidth(), self.texture.getHeight() else: self.imageSize = imageSize self.fullRect = fullRect self.absRect = absRect self.screenRect = screenRect def getPos(self): return (self.imagePos.x, self.imagePos.y) def setPos(self, x, y): self.imagePos = Vec2(x,y) def update(self, secs, app): pass #if self.autoPan: # self.easyTexture.pan(self.xvel * secs, self.yvel* secs) def pan(self, xchange, ychange): if mpi.rank == 1: print "Panning:", xchange, ychange #self.easyTexture.pan(xchange * 300, ychange * 300) def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) # convert to local coords localBtmLeft = Vec2(self.imagePos.x - self.absRect.x, self.imagePos.y - self.absRect.y) localTopRight = Vec2(localBtmLeft.x + self.imageSize[0], localBtmLeft.y + self.imageSize[1]) localBtmLeft = Vec2(max(localBtmLeft.x, 0), max(localBtmLeft.y, 0)) localTopRight = Vec2(min(localTopRight.x, self.screenRect.width), min(localTopRight.y, self.screenRect.height)) blitSize = Vec2(localTopRight.x - localBtmLeft.x, localTopRight.y - localBtmLeft.y) # convert clipped local coords back to global coords find the source rect globalBtmLeft = Vec2(localBtmLeft.x + self.absRect.x, localBtmLeft.y + self.absRect.y) globalTopRight = Vec2(localTopRight.x + self.absRect.x, localTopRight.y + self.absRect.y) # convert global coords to txtr coords offset = Vec2(globalBtmLeft.x - self.imagePos.x , globalBtmLeft.y - self.imagePos.y) size = (globalTopRight.x - globalBtmLeft.x, globalTopRight.y - globalBtmLeft.y) if size[0] > 0 and size[1] > 0: self.texture.blit( localBtmLeft, Rect(offset.x,offset.y, size[0], size[1]), (renderer.width, renderer.height) ) #self.easyTexture.draw() #box = glBox() #app.addDynamicObject(box) glEnable(GL_TEXTURE_2D) boxes = [] for i in range(len(renderers)): absRect = absoluteRects[i] locRect = localRects[i] renderer = renderers[i] box = glTxtrBox(imageFilename, screenRect=Rect(0,0,locRect.width, locRect.height), imagePos=(2000,500), absRect= absRect, fullRect=fullRect) # to scale, change the geometry and the txtr coords: imageSize and #box.imageSize = (box.imageSize[0]*2, box.imageSize[1]*2) #box.easyTexture.zoom(5,1) #box.easyTexture.setOffset( (absRect.x % float(box.easyTexture.getWidth())) / box.easyTexture.getWidth(), # (absRect.y % float(box.easyTexture.getHeight())) / box.easyTexture.getHeight() ) # box.easyTexture.setWidth( float(locRect.width) / float(box.easyTexture.getHeight()) ) #zoom = (0.5,1) #box.easyTexture.setZoom(zoom[0], zoom[1]) #box.easyTexture.setOffset(absRect.x * zoom[0] ,absRect.y * zoom[1]) #box.easyTexture.setZoom(float(box.easyTexture.getWidth()) / localRect.width, # float(box.easyTexture.getHeight()) / localRect.height ) # scale offset back by zoom (offset is between 0 and 1) #box.easyTexture.setOffset( float(rect.x) / fullRect.width * box.easyTexture.getWidth(), # float(rect.y) / fullRect.height * box.easyTexture.getHeight()) app.addDynamicObject(box, addToRenderer=False) renderers[i].addDynamicObject(box) boxes.append(box) app.drawBounds = 0 # setup control def setupMoteControl(panningObjects, app, displayWidth, displayHeight): tileMote = TileMote(panningObjects, displayWidth, displayHeight) if mpi.rank == 0: mote = connectToMote() moteMouse = MoteMouse(mote,tileMote) else: moteMouse = None mote = None class MouseUpdater: def __init__(self, moteMouse, tileMote): self.moteMouse = moteMouse self.tileMote = tileMote def update(self, app, secs): # process data from device if mpi.rank == 0: self.moteMouse.processAndUpdateMouse() # send data to all nodes and apply self.tileMote.syncAndApply() app.addDynamicObject(MouseUpdater(moteMouse, tileMote), addToRenderer=False) return mote, moteMouse, tileMote mote = None for arg in sys.argv: if "wii" in arg.lower(): mote, moteMouse, tileMote = setupMoteControl(boxes, app, fullRect.width, fullRect.height) for box in boxes: box.autoPan=False break # break out of this loop class Syncer: def __init__(self, cursorObjectsListList=None): # list of lists: [ [a1,a2,a3], [b1,b2] ] # access: cursor[i][localcopies] # only the first object for each cursors is read, all are written if cursorObjectsListList == None: self.cursorObjects = [] else: self.cursorObjects = cursorObjectsListList self.cursors = [] for obj in self.cursorObjects: self.cursors.append( (0,0) ) self.resultCursors = [] if mpi.rank == 0: self.dataLock = Lock() def update(self, app, secs): self.syncAndApply() def syncAndApply(self): if mpi.rank == 0: self.dataLock.acquire() # this lock probably isn't necessary yet try: for i in range(len(self.cursorObjects)): self.cursors[i] = self.cursorObjects[i][0].getPos() except: traceback.print_exc() finally: self.dataLock.release() if mpi.rank == 0: resultCursors = mpi.bcast(self.cursors) else: self.resultCursors = mpi.bcast() if mpi.rank != 0: for i in range(len(self.cursorObjects)): if len(self.resultCursors) > i: # access: cursorObjects[i][localcopies] for j in range(len(self.cursorObjects[i])): # set for each local copy self.cursorObjects[i][j].setPos( self.resultCursors[i][0], self.resultCursors[i][1]) #if len(resultQueue) > 0: # print "Bcasting recv:", resultQueue, mpi.rank class CursorAutoMover: def __init__(self, target, xrange=(0,5000), yrange=(0,3000), xvel=100, yvel=100): self.target = target self.xvel = xvel self.yvel = yvel self.xrange = xrange self.yrange = yrange self.visible = False def draw(self): pass def update(self, secs, app): posTuple = self.target.getPos() pos = Vec2(posTuple[0], posTuple[1]) pos.x = pos.x + self.xvel * secs pos.y = pos.y + self.yvel * secs if pos.x > self.xrange[1]: self.xvel = -abs(self.xvel) if pos.y > self.yrange[1]: self.yvel = -abs(self.yvel) if pos.x < self.xrange[0]: self.xvel = abs(self.xvel) if pos.y < self.xrange[0]: self.yvel = abs(self.yvel) self.target.setPos(pos.x, pos.y) # print "pos:", pos.x, pos.y #class Cursor: def CreateCursor(x=500,y=500, xvel=100, yvel=100): tmpCursors = [] for i in range(len(renderers)): absRect = absoluteRects[i] locRect = localRects[i] renderer = renderers[i] cursor = glTxtrBox("../../../../data/fl-logo-color-small.gif", screenRect=Rect(0,0,locRect.width, locRect.height), imagePos=(x,y), absRect= absRect, fullRect=fullRect) app.addDynamicObject(cursor, addToRenderer=False) renderers[i].addDynamicObject(cursor) tmpCursors.append(cursor) # change this to only happen on master and sync if mpi.rank == 0: app.addDynamicObject(CursorAutoMover(cursor, xrange=(0, fullRect.width), yrange=(0, fullRect.height), xvel=xvel, yvel=yvel), addToRenderer=False) return tmpCursors numCursors = 3 cursorListList = [] for i in range(numCursors): nodeCursors = CreateCursor(x=randrange(0,fullRect.width), y=randrange(0,fullRect.height), xvel=randrange(200,400), yvel=randrange(200,400)) cursorListList.append(nodeCursors) # print mpi.rank, " cursor list:", cursorListList syncer = Syncer(cursorListList) app.addDynamicObject(syncer, addToRenderer=False) print "Running app" try: app.run() except: traceback.print_exc() finally: if mpi.rank == 0: if mote != None: mote.disconnect() if mote.readThread != None: print "Exiting, joining thread" mote.readThread.join()
def run(): windowWidth = 2560 # 320 windowHeight = 800 # 280 app = App(windowWidth, windowHeight) renderer = glRenderer2D() app.setRenderer(renderer) app.initialize() import pygame print pygame.display.get_wm_info() from Xlib.display import Display display = Display(":0") screen = display.screen() #print dir(screen) Xlib.MoveWindow(23432, 5, 5) #print display.info return renderer.init(windowWidth, windowHeight) class glBox: def __init__(self): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True def update(self, app, secs): pass def draw(self, renderer): glClearColor(.8, .8, .8, 1.0) glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True #self.texture = Texture( "../data/test1.png") self.easyTexture = EasyTexture("../data/test1.png") self.easyTexture.width = renderer.width * 0.8 self.easyTexture.height = renderer.height * 0.8 self.useDrawPixel = False # For comparison debugging def update(self, app, secs): pass def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) self.easyTexture.draw() box = glBox() app.addDynamicObject(box) glEnable(GL_TEXTURE_2D) box2 = glTxtrBox() app.addDynamicObject(box2) app.drawBounds = 0 print "Running app" app.run()
def run(): os.environ["DISPLAY"] = ":0.0" imageFilename = sys.argv[1] windowWidth = 1280 # 320 windowHeight = 1024 # 280 app = App(windowWidth, windowHeight) renderer = glRenderer2D() app.setRenderer(renderer) app.initialize(windowBorder=False) renderer.init(windowWidth, windowHeight) class glBox: def __init__(self): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True def update(self, app, secs): pass def draw(self, renderer): glClearColor(0.8, 0.8, 0.8, 1.0) glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self, imageFilename="../data/test1.png"): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True # self.texture = Texture( "../data/test1.png") self.easyTexture = EasyTexture(imageFilename, blend=False) # self.easyTexture.width = renderer.width * 0.8 # self.easyTexture.height = renderer.height * 0.8 self.easyTexture.width = renderer.width self.easyTexture.height = renderer.height self.useDrawPixel = False # For comparison debugging self.useDrawPixel = False # For comparison debugging self.xvel = 0.1 self.yvel = 0.1 self.xoffset = 0.0 self.yoffset = 0.0 self.easyTexture.zoom(2, 2) def update(self, secs, app): self.easyTexture.pan(self.xvel * secs, self.yvel * secs) def draw(self, renderer): # glClearColor(.8, .8, .8, 1.0) # glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) # self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) self.easyTexture.draw() box = glBox() app.addDynamicObject(box) glEnable(GL_TEXTURE_2D) box2 = glTxtrBox(imageFilename) app.addDynamicObject(box2) app.drawBounds = 0 print "Running app" app.run()
def run(): windowWidth = 1000 # 320 windowHeight = 800 # 280 app = App(windowWidth, windowHeight) renderer = glRenderer2D() app.setRenderer(renderer) app.initialize() renderer.init(windowWidth, windowHeight) class glBox: def __init__(self): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True def update(self, app, secs): pass def draw(self, renderer): glClearColor(.8, .8, .8, 1.0) glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True #self.texture = Texture( "../data/test1.png") self.easyTexture = EasyTexture("../data/test1.png") #self.easyTexture.width = renderer.width * 0.8 self.easyTexture.setWidth(renderer.width * 0.1) self.easyTexture.setHeight(renderer.height * 0.1) self.useDrawPixel = False # For comparison debugging def update(self, app, secs): length = self.easyTexture.texture.image.size[ 0] * self.easyTexture.texture.image.size[ 1] * self.easyTexture.texture.numChannels self.easyTexture.texture.imagestr = [ random.randrange(0, 255) for x in xrange(length) ] self.easyTexture.texture.reloadGLTextureFromData() def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) self.easyTexture.draw() box = glBox() app.addDynamicObject(box) glEnable(GL_TEXTURE_2D) box2 = glTxtrBox() # Change the size #box2.easyTexture.texture.image.size = (200,200) #box2.easyTexture.setOffsetX(400) #box2.easyTexture.setOffsetY(400) box2.easyTexture.setWidth(800) box2.easyTexture.setHeight(600) app.addDynamicObject(box2) app.drawBounds = 0 print "Running app" app.run()
def run(): windowWidth = 2560# 320 windowHeight = 800 # 280 app = App(windowWidth, windowHeight) renderer = glRenderer2D() app.setRenderer(renderer) app.initialize() import pygame print pygame.display.get_wm_info() from Xlib.display import Display display=Display(":0") screen = display.screen() #print dir(screen) Xlib.MoveWindow(23432, 5, 5) #print display.info return renderer.init(windowWidth, windowHeight) class glBox: def __init__(self): self.hasDrawFunc=True self.hasEraseDrawFunc=True self.visible = True def update(self, app, secs): pass def draw(self, renderer): glClearColor(.8, .8, .8, 1.0) glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self): self.hasDrawFunc=True self.hasEraseDrawFunc=True self.visible = True #self.texture = Texture( "../data/test1.png") self.easyTexture = EasyTexture( "../data/test1.png") self.easyTexture.width = renderer.width * 0.8 self.easyTexture.height = renderer.height * 0.8 self.useDrawPixel = False # For comparison debugging def update(self, app, secs): pass def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) self.easyTexture.draw() box = glBox() app.addDynamicObject(box) glEnable(GL_TEXTURE_2D) box2 = glTxtrBox() app.addDynamicObject(box2) app.drawBounds = 0 print "Running app" app.run()
def run(): windowWidth = 1024 / 2 # 320 windowHeight = 768 / 2 # 280 app = App(windowWidth, windowHeight) renderer = glRenderer2D() app.setRenderer(renderer) app.initialize() renderer.init(windowWidth, windowHeight) renderer.addFrameSetupObj(ScreenClearer((0.8, 0.8, 0.8), clearDepth=False)) """ glDisable(GL_DEPTH_TEST) #use our zbuffer glDisable(GL_LIGHTING) #use our zbuffer glMatrixMode(GL_PROJECTION) glLoadIdentity() gluOrtho2D(0, windowWidth, 0, windowHeight) glColor3f(1,1,0) """ class pointListRenderer: M_BASIC = 0 M_EXT = 1 M_FULL = 2 def __init__(self): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True self.points = [(0.5, 0.5)] self.pointsAndSize = [(0.5, 0.5, 0.5)] self.color = (0.4, 0.4, 0.9) self.pointSize = 10 self.mode = self.M_BASIC def setPointsFromList(self, pointList): self.points = pointList def setPointsAndSizeFromList(self, pointList): self.pointsAndSize = pointList def update(self, app, secs): pass def eraseDraw(self, app): pass def draw(self, renderer): glColor3fv(self.color) if self.mode == self.M_BASIC: glPointSize(self.pointSize) glBegin(GL_POINTS) # print "drawing: ", self.points for p in self.points: glVertex2f(p[0] * renderer.width, p[1] * renderer.height) glEnd() elif self.mode == self.M_EXT: # print "drawing: ", self.points for p in self.pointsAndSize: glPointSize(self.pointSize * (p[2] + 0.5)) glBegin(GL_POINTS) glVertex2f(p[0] * renderer.width, p[1] * renderer.height) glEnd() else: # self.mode== self.M_FULL raise Exception("Unimplemented pointList draw mode") points = pointListRenderer() app.addDynamicObject(points) app.drawBounds = 0 class motePointProcessor: def __init__(self, mote, pointsView): self.hasDrawFunc = False self.mote = mote self.pointsView = pointsView if mote.irMode == "f": self.pointsView.mode = self.pointsView.M_FULL elif mote.irMode == "e": self.pointsView.mode = self.pointsView.M_EXT else: # mote.irMode == "b": self.pointsView.mode = self.pointsView.M_BASIC def draw(self, renderer): pass def update(self, app, secs): if self.mote.irMode == "f": raise Exception("Unimplemented") elif self.mote.irMode == "e": points = self.mote.extractNormalizedPointsAndSize() if len(points) > 0: # print "setting points:", points[-1] self.pointsView.setPointsAndSizeFromList(points[-1]) else: # irMode == "b" points = self.mote.extractNormalizedPoints() if len(points) > 0: # print "setting points:", points[-1] self.pointsView.setPointsFromList(points[-1]) mote = connectToMote() # mote = None processor = motePointProcessor(mote, points) app.addDynamicObject(processor) print "Running app" try: app.run() except: traceback.print_exc() finally: mote.disconnect() if mote.readThread != None: print "Exiting, joining thread" mote.readThread.join()
def run(): tileConfig = CreateAMConfig() # fqdn = getfqdn() hostname = gethostname() machineDesc = tileConfig.getMachineDescByHostname(hostname) localRects = [] absoluteRects = [] for tile in machineDesc.tiles: localRects.append(tileConfig.getLocalDrawRect(tile.uid)) absoluteRects.append(tileConfig.getAbsoluteFullDisplayRect(tile.uid)) print hostname, machineDesc.hostname, localRects, absoluteRects # return fullRect = tileConfig.getMainDisplayRect() if mpi.rank == 0: print "FULL DISPLAY:", fullRect.width, fullRect.height #rects = [Rect(0,0,1280,1024), Rect(1280,0, 1280,1024)] #rects = [Rect(0,0,1280,1024)] os.environ["DISPLAY"] = ":0.0" os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0" imageFilename = sys.argv[1] #windowWidth = 2560 # 1280# 320 #windowWidth = 3840 # 1280# 320 windowWidth = 2560 # 1280# 320 windowHeight = 1024 # 1024 # 280 #windowWidth = 1280 # 1280# 320 #windowHeight = 1024 # 1024 # 280 app = App(windowWidth, windowHeight) renderers = [] for i in range(len(localRects)): displayRect = localRects[i] if i == 0: renderer = glRenderer2D(multipleRenderers=True, firstRenderer=True) renderer.addFrameSetupObj(ScreenClearer(color=(.9, .4, .4), clearDepth=False)) else: renderer = glRenderer2D(multipleRenderers=True) renderer.addFrameSetupObj(ScreenClearer(color=(.4, .9, .4), clearDepth=False)) renderers.append(renderer) app.addRenderer(renderer) # app.initialize(windowBorder=False) app.initialize(windowBorder=True) for i in range(len(localRects)): print "SETTING RECT:", localRects[i] renderers[i].init(app.width, app.height, viewportRect=localRects[i]) class glBox: def __init__(self): self.hasDrawFunc=True self.hasEraseDrawFunc=True self.visible = True def update(self, app, secs): pass def draw(self, renderer): #glClearColor(.4, .4, .4, 1.0) #glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self, imageFilename, screenRect, fullRect, absRect, initialOffset=(0,0), zoom=(4,4), imagePos=(0,0), imageSize=None ): self.hasDrawFunc=True self.hasEraseDrawFunc=True self.visible = True self.texture = Texture( imageFilename) #self.easyTexture = EasyTexture(imageFilename, screenGeomRect=screenRect, blend=False) #self.easyTexture.width = renderer.width * 0.8 #self.easyTexture.height = renderer.height * 0.8 #self.easyTexture.width = renderer.width #self.easyTexture.height = renderer.height self.useDrawPixel = False # For comparison debugging self.xvel = 0.1 self.yvel = 0.1 self.zoom = zoom #self.easyTexture.zoom(zoom[0], zoom[1]) #self.easyTexture.setOffset(initialOffset[0], initialOffset[1]) self.autoPan = True self.imagePos = imagePos if imageSize == None: self.imageSize = self.texture.getWidth(), self.texture.getHeight() else: self.imageSize = imageSize self.fullRect = fullRect self.absRect = absRect self.screenRect = screenRect def update(self, secs, app): pass #if self.autoPan: # self.easyTexture.pan(self.xvel * secs, self.yvel* secs) def pan(self, xchange, ychange): if mpi.rank == 1: print "Panning:", xchange, ychange #self.easyTexture.pan(xchange * 300, ychange * 300) def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) # convert to local coords localBtmLeft = Vec2(self.imagePos[0] - self.absRect.x, self.imagePos[1] - self.absRect.y) localTopRight = Vec2(localBtmLeft.x + self.imageSize[0], localBtmLeft.y + self.imageSize[1]) localBtmLeft = Vec2(max(localBtmLeft.x, 0), max(localBtmLeft.y, 0)) localTopRight = Vec2(min(localTopRight.x, self.screenRect.width), min(localTopRight.y, self.screenRect.height)) blitSize = Vec2(localTopRight.x - localBtmLeft.x, localTopRight.y - localBtmLeft.y) # convert clipped local coords back to global coords find the source rect globalBtmLeft = Vec2(localBtmLeft.x + self.absRect.x, localBtmLeft.y + self.absRect.y) globalTopRight = Vec2(localTopRight.x + self.absRect.x, localTopRight.y + self.absRect.y) # convert global coords to txtr coords offset = Vec2(globalBtmLeft.x - self.imagePos[0] , globalBtmLeft.y - self.imagePos[1]) size = (globalTopRight.x - globalBtmLeft.x, globalTopRight.y - globalBtmLeft.y) if size[0] > 0 and size[1] > 0: self.texture.blit( localBtmLeft, Rect(offset.x,offset.y, size[0], size[1]), (renderer.width, renderer.height) ) #self.easyTexture.draw() #box = glBox() #app.addDynamicObject(box) glEnable(GL_TEXTURE_2D) boxes = [] for i in range(len(renderers)): absRect = absoluteRects[i] locRect = localRects[i] renderer = renderers[i] box = glTxtrBox(imageFilename, screenRect=Rect(0,0,locRect.width, locRect.height), imagePos=(2000,500), absRect= absRect, fullRect=fullRect) # to scale, change the geometry and the txtr coords: imageSize and #box.imageSize = (box.imageSize[0]*2, box.imageSize[1]*2) #box.easyTexture.zoom(5,1) #box.easyTexture.setOffset( (absRect.x % float(box.easyTexture.getWidth())) / box.easyTexture.getWidth(), # (absRect.y % float(box.easyTexture.getHeight())) / box.easyTexture.getHeight() ) # box.easyTexture.setWidth( float(locRect.width) / float(box.easyTexture.getHeight()) ) #zoom = (0.5,1) #box.easyTexture.setZoom(zoom[0], zoom[1]) #box.easyTexture.setOffset(absRect.x * zoom[0] ,absRect.y * zoom[1]) #box.easyTexture.setZoom(float(box.easyTexture.getWidth()) / localRect.width, # float(box.easyTexture.getHeight()) / localRect.height ) # scale offset back by zoom (offset is between 0 and 1) #box.easyTexture.setOffset( float(rect.x) / fullRect.width * box.easyTexture.getWidth(), # float(rect.y) / fullRect.height * box.easyTexture.getHeight()) app.addDynamicObject(box, addToRenderer=False) renderers[i].addDynamicObject(box) boxes.append(box) app.drawBounds = 0 # setup control def setupMoteControl(panningObjects, app, displayWidth, displayHeight): tileMote = TileMote(panningObjects, displayWidth, displayHeight) if mpi.rank == 0: mote = connectToMote() moteMouse = MoteMouse(mote,tileMote) else: moteMouse = None mote = None class MouseUpdater: def __init__(self, moteMouse, tileMote): self.moteMouse = moteMouse self.tileMote = tileMote def update(self, app, secs): # process data from device if mpi.rank == 0: self.moteMouse.processAndUpdateMouse() # send data to all nodes and apply self.tileMote.syncAndApply() app.addDynamicObject(MouseUpdater(moteMouse, tileMote), addToRenderer=False) return mote, moteMouse, tileMote mote = None for arg in sys.argv: if "wii" in arg.lower(): mote, moteMouse, tileMote = setupMoteControl(boxes, app, fullRect.width, fullRect.height) for box in boxes: box.autoPan=False break # break out of this loop print "Running app" try: app.run() except: traceback.print_exc() finally: if mpi.rank == 0: if mote != None: mote.disconnect() if mote.readThread != None: print "Exiting, joining thread" mote.readThread.join()