Exemplo n.º 1
0
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()
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
def run():
    windowWidth = 320
    windowHeight = 280
    app = App(windowWidth, windowHeight)
    renderer = glRenderer3D()
    renderer.camera.setPos(5, 5, 10)
    renderer.addGlSetupObj(glInitObj())
    renderer.addFrameSetupObj(ScreenClearer())
    app.setRenderer(renderer)
    app.initialize()

    renderer.init(windowWidth, windowHeight)

    class glSphere:
        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)
            glColor3f(1.0, 0, 0)
            GLUT.glutSolidSphere(2, 16, 16)

    sphere = glSphere()
    print "after make sphere"
    app.addDynamicObject(sphere)

    light = Light(Vec3(5, 100, 5), 0)
    renderer.addFrameSetupObj(light)

    app.drawBounds = 0

    app.appDoesCollisionChecks = False
    print "Running app"
    # app.printFPS = True
    app.run()
Exemplo n.º 4
0
def run():
    windowWidth = 320
    windowHeight = 280
    app = App(windowWidth, windowHeight)
    renderer = glRenderer3D()
    renderer.camera.setPos(5, 5, 10)
    renderer.addGlSetupObj(glInitObj())
    renderer.addFrameSetupObj(ScreenClearer())
    app.setRenderer(renderer)
    app.initialize()

    renderer.init(windowWidth, windowHeight)

    class glSphere:
        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)
            glColor3f(1.0, 0, 0)
            GLUT.glutSolidSphere(2, 16, 16)

    sphere = glSphere()
    print "after make sphere"
    app.addDynamicObject(sphere)

    light = Light(Vec3(5,100,5), 0)
    renderer.addFrameSetupObj(light)

    app.drawBounds = 0

    app.appDoesCollisionChecks = False
    print "Running app"
    # app.printFPS = True
    app.run()
Exemplo n.º 5
0
def run():
    windowWidth = 320
    windowHeight = 280
    app = App(windowWidth, windowHeight)
    renderer = glRenderer3D()
    renderer.camera.setPos(5, 5, 10)
    renderer.addGlSetupObj(glInitObj())
    renderer.addFrameSetupObj(ScreenClearer())
    app.setRenderer(renderer)
    app.initialize()

    renderer.init(windowWidth, windowHeight)

    glDisable(GL_LIGHTING)

    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)
            glColor3f(1.0, 0, 0)
            GLUT.glutSolidCube(2)

    box = glBox()
    print "after make box"
    app.addDynamicObject(box)
    print "after adddyn"
    app.drawBounds = 0

    app.appDoesCollisionChecks = False
    print "Running app"
    app.run()
Exemplo n.º 6
0
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()
Exemplo n.º 7
0
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()
Exemplo n.º 8
0
    # 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()
    app.addDynamicObject(p)
    #app.addDynamicObject(r, addToRenderer=False)

    app.drawBounds = 0

    app.run()

Exemplo n.º 9
0
    # 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()
    app.addDynamicObject(p)
    #app.addDynamicObject(r, addToRenderer=False)

    app.drawBounds = 0

    app.run()
Exemplo n.º 10
0
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()
Exemplo n.º 11
0
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()
Exemplo n.º 12
0
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()
Exemplo n.º 13
0
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()
Exemplo n.º 14
0
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()
Exemplo n.º 15
0
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()
Exemplo n.º 16
0
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()
Exemplo n.º 17
0
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()
Exemplo n.º 18
0
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()
Exemplo n.º 19
0
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()
Exemplo n.º 20
0
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()
Exemplo n.º 21
0
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()
Exemplo n.º 22
0
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()
Exemplo n.º 23
0
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()