#!/bin/env python # Copyright (C) 2002-2003 Gideon May (gideon@computer.org) # # Permission to copy, use, sell and distribute this software is granted # provided this copyright notice appears in all copies. # Permission to modify the code and to distribute modified code is granted # provided this copyright notice appears in all copies, and a notice # that the code was modified is included with the copyright notice. # # This software is provided "as is" without express or implied warranty, # and with no claim as to its suitability for any purpose. # -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield # # This application is open source and may be redistributed and/or modified # freely and without restriction, both in commericial and non commericial applications, # as long as this copyright notice is maintained. # # This application is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # from PyOSG import osg from PyOSG import osgDB import math import OpenGL def makeBase(): ir = 20.0 coords = osg.Vec3Array(19) tcoords = osg.Vec2Array(19) colors = osg.Vec4Array(1) colors[0].set(1.0,1.0,1.0,1.0) c = 0 coords[c].set(0.0,0.0,0.0) tcoords[c].set(0.0,0.0) for i in range(19): theta = osg.DegreesToRadians(i * 20.0) coords[c].set(ir * math.cos( theta ), ir * math.sin( theta ), 0.0) tcoords[c].set(coords[c][0]/36.0,coords[c][1]/36.0) c += 1 geom = osg.Geometry() geom.setVertexArray( coords ) geom.setTexCoordArray( 0, tcoords ) geom.setColorArray( colors ) geom.setColorBinding( osg.Geometry.BIND_OVERALL ) geom.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.TRIANGLE_FAN,0,19) ) tex = osg.Texture2D() tex.setImage(osgDB.readImageFile("Images/water.rgb")) tex.setWrap( osg.Texture2D.WRAP_S, osg.Texture2D.REPEAT ) tex.setWrap( osg.Texture2D.WRAP_T, osg.Texture2D.REPEAT ) dstate = osg.StateSet() dstate.setMode( OpenGL.GL.GL_LIGHTING, osg.StateAttribute.OFF ) dstate.setTextureAttributeAndModes(0, tex, osg.StateAttribute.ON ) dstate.setTextureAttribute(0, osg.TexEnv() ) # clear the depth to the far plane. depth = osg.Depth() depth.setFunction(osg.Depth.ALWAYS) depth.setRange(1.0,1.0) dstate.setAttributeAndModes(depth,osg.StateAttribute.ON ) dstate.setRenderBinDetails(-1,"RenderBin") geom.setStateSet( dstate ) geode = osg.Geode() geode.addDrawable( geom ) return geode if __name__ == "__main__": import sys from PyOSG import Producer from PyOSG import osgDB from PyOSG import osgUtil from PyOSG import osgGA from PyOSG import osgProducer base = makeBase() viewer = osgProducer.Viewer() viewer.setUpViewer(osgProducer.Viewer.STANDARD_SETTINGS) viewer.setSceneData(base) viewer.realize() while not viewer.done(): viewer.sync() viewer.update() viewer.frame() viewer.sync() sys.exit(0)