def main(argv): viewer = osgViewer.Viewer() wm = osgWidget.WindowManager( viewer, 1280.0, 1024.0, MASK_2D ) canvas = osgWidget.Canvas("canvas") canvas.attachMoveCallback() canvas.attachScaleCallback() canvas.addWidget( createWidget("w1", 0.2, osgWidget.Widget.LAYER_LOW), 0.0, 0.0 ) canvas.addWidget( createWidget("w2", 0.4, osgWidget.Widget.LAYER_MIDDLE), 200.0, 0.0 ) canvas.addWidget( createWidget("w3", 0.6, osgWidget.Widget.LAYER_HIGH), 400.0, 0.0 ) wm.addChild(canvas) program = osg.Program() program.addShader(osg.Shader.readShaderFile( osg.Shader.VERTEX, osgDB.findDataFile("osgWidget/osgwidgetshader-vert.glsl") )) program.addShader(osg.Shader.readShaderFile( osg.Shader.FRAGMENT, osgDB.findDataFile("osgWidget/osgwidgetshader-frag.glsl") )) canvas.getGeode().getOrCreateStateSet().setAttribute(program) return osgWidget.createExample(viewer, wm)
def main(argv): viewer = osgViewer.Viewer() wm = osgWidget.WindowManager(viewer, 1280.0, 1024.0, MASK_2D) canvas = osgWidget.Canvas("canvas") canvas.attachMoveCallback() canvas.attachScaleCallback() canvas.addWidget(createWidget("w1", 0.2, osgWidget.Widget.LAYER_LOW), 0.0, 0.0) canvas.addWidget(createWidget("w2", 0.4, osgWidget.Widget.LAYER_MIDDLE), 200.0, 0.0) canvas.addWidget(createWidget("w3", 0.6, osgWidget.Widget.LAYER_HIGH), 400.0, 0.0) wm.addChild(canvas) program = osg.Program() program.addShader( osg.Shader.readShaderFile( osg.Shader.VERTEX, osgDB.findDataFile("osgWidget/osgwidgetshader-vert.glsl"))) program.addShader( osg.Shader.readShaderFile( osg.Shader.FRAGMENT, osgDB.findDataFile("osgWidget/osgwidgetshader-frag.glsl"))) canvas.getGeode().getOrCreateStateSet().setAttribute(program) return osgWidget.createExample(viewer, wm)
def createEarth(): hints = osg.TessellationHints() hints.setDetailRatio(5.0) sd = osg.ShapeDrawable(osg.Sphere(osg.Vec3(0.0,0.0,0.0), osg.WGS_84_RADIUS_POLAR), hints) geode = osg.Geode() geode.addDrawable(sd) filename = osgDB.findDataFile("Images/land_shallow_topo_2048.jpg") geode.getOrCreateStateSet().setTextureAttributeAndModes(0, osg.Texture2D(osgDB.readImageFile(filename))) csn = osg.CoordinateSystemNode() csn.setEllipsoidModel(osg.EllipsoidModel()) csn.addChild(geode) return csn
"\n" "void main(void) \n" " \n" " gl_FragColor = texture2D( baseTexture, texcoord) \n" "\n" vertex_shader = osg.Shader(osg.Shader.VERTEX, vertexShaderSource) program.addShader(vertex_shader) fragment_shader = osg.Shader(osg.Shader.FRAGMENT, fragmentShaderSource) program.addShader(fragment_shader) #else: # get shaders from source program.addShader(osg.Shader.readShaderFile(osg.Shader.VERTEX, osgDB.findDataFile("shaders/forest.vert"))) program.addShader(osg.Shader.readShaderFile(osg.Shader.FRAGMENT, osgDB.findDataFile("shaders/forest.frag"))) #endif baseTextureSampler = osg.Uniform("baseTexture",0) stateset.addUniform(baseTextureSampler) group.addChild(createShaderGraph(cell,stateset)) group.addChild(createHUDWithText("Using OpenGL Shader to create a forest\n\nPress left cursor key to select osg.Vertex/FragmentProgram based forest\nPress right cursor key to select osg.Vertex/Geometry/FragmentProgram based forest")) _techniqueSwitch.addChild(group) print "done." print "Creating Geometry Shader based forest..." stateset = osg.StateSet(*dstate, osg.CopyOp.DEEP_COPY_ALL)
static osg.StateSet* ModelInstance() static float zvalue = 0.0 static osg.Node* masterModel = CreateModel() xform = osg.PositionAttitudeTransform() xform.setPosition(osg.Vec3( 0.0, -1.0, zvalue )) zvalue = zvalue + 2.2 xform.addChild(masterModel) rootNode.addChild(xform) return xform.getOrCreateStateSet() # load source from a file. static void LoadShaderSource( osg.Shader* shader, str fileName ) fqFileName = osgDB.findDataFile(fileName) if fqFileName.length() not = 0 : shader.loadShaderSourceFromFile( fqFileName.c_str() ) else: osg.notify(osg.WARN), "File \"", fileName, "\" not found." #####################################/ # rude but convenient globals static osg.Program* BlockyProgram static osg.Shader* BlockyVertObj static osg.Shader* BlockyFragObj static osg.Program* ErodedProgram static osg.Shader* ErodedVertObj
osg.notify(osg.INFO), "app found not " cxapp = xapp.c_str() osg.notify(osg.INFO), "char* = ", cxapp system = return(cxapp) osg.notify(osg.INFO), "app not found not " return 1 # end printList() void readConfFile( char* confFile) # read confFile 1 osg.notify(osg.INFO), "Start reading confFile" fileName = osgDB.findDataFile(confFile) if fileName.empty() : osg.notify(osg.INFO), "Config file not found", confFile return in = osgDB.ifstream(fileName.c_str()) if not in : osg.notify(osg.INFO), "File ", fileName, " can not be opened not " exit(1) imageBuffer = str() appBuffer = str() while not in.eof() : std.getline(in, imageBuffer) std.getline(in, appBuffer)