def createOffscreenBuffer(sort, xsize, ysize):
winprops = WindowProperties.size(xsize,ysize)
props = FrameBufferProperties()
props.setRgbColor(1)
props.setAlphaBits(1)
props.setDepthBits(1)
"""return base.graphicsEngine.makeOutput(
base.pipe, "offscreenBuffer",
sort, props, winprops,
GraphicsPipe.BFFbPropsOptional | GraphicsPipe.BFRefuseWindow)
"""
return base.graphicsEngine.makeOutput(
base.pipe, "offscreenBuffer",
sort, props, winprops,
GraphicsPipe.BFFbPropsOptional | GraphicsPipe.BFRefuseWindow,
base.win.getGsg(), base.win)
class Container(DirectObject):
def __init__(self, wxApp):
self.wxApp = wxApp
self.InitScene()
taskMgr.add(self.taskWalk, "walk")
def InitScene(self):
self.buffer = createOffscreenBuffer(0, MODEL_WIDTH, MODEL_HEIGHT)
self.LoadModel()
self.SetupTexture()
# remove the window will also stop the offscreen buffer to come up,
# because the gsg is shared ?
#base.userExit = lambda: None
#base.graphicsEngine.removeWindow(base.win)
# minimize is not implemented in panda
#props = WindowProperties()
#props.setMinimized(True)
#base.win.requestProperties(props)
def SetupTexture(self):
self.screenTexture = Texture()
self.screenTexture.setMinfilter(Texture.FTLinear)
self.screenTexture.setFormat(Texture.FRgba32)
self.buffer.addRenderTexture(self.screenTexture, GraphicsOutput.RTMCopyRam)
self.screenImage = PNMImage()
def GetImage(self):
if self.screenTexture.hasRamImage():
self.screenTexture.store(self.screenImage)
screenData = StringStream()
#self.screenImage.write(Filename("a.bmp"))
self.screenImage.write(screenData, "ppm")
return screenData
return None
def LoadModel(self):
self.buffer.setClearColor(VBase4(1.0,0.0,0.0,0.0))
self.cam = base.makeCamera(self.buffer)
self.render = NodePath("render")
self.cam.reparentTo(self.render)
self.cam.node().setScene(self.render)
self.actor= Actor('panda.egg', {'walk' : 'panda-walk.egg'})
self.actor.setScale(0.15,0.15,0.15)
self.actor.reparentTo(self.render)
self.actor.loop("walk")
self.cam.lookAt(self.actor.getPos())
self.cam.setPos(0, -5, 0.5)
dlight = NodePath(DirectionalLight('dlight'))
dlight.reparentTo(self.cam)
#dlight.reparentTo(self.render)
self.render.setLight(dlight)
def taskWalk(self, task):
self.actor.setX(self.actor, 0.2)
return task.cont
This pieces of codes is from clcheung. On his computer ,the panda window is unshown. but on my computer ,the window is shown.
And I read the content in manual about “Creating Windows and Buffers”, I also think creating a hiden window should coding like that. But uneffect.
Anyone can help me?