def glinit(self,mode="wireframe"): GL.glClearColor(*RGBA(self.bgcolor))# Clear The Background Color GL.glClearDepth(1.0) # Enables Clearing Of The Depth Buffer GL.glDepthFunc(GL.GL_LESS) # The Type Of Depth Test To Do GL.glEnable(GL.GL_DEPTH_TEST) # Enables Depth Testing if mode == "wireframe": self.wireframe = True GL.glShadeModel(GL.GL_FLAT) # Enables Flat Color Shading GL.glDisable(GL.GL_LIGHTING) elif mode == "render": self.wireframe = False GL.glShadeModel(GL.GL_SMOOTH) # Enables Smooth Color Shading #print "set up lights" GL.glLightModel(GL.GL_LIGHT_MODEL_AMBIENT,(0.5,0.5,0.5,1)) GL.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, (1.0, 1.0, 1.0, 1.0)) GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0)) GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, (1.0, 1.0, 1.0, 1.0)) GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, (-1.0, -1.0, 5.0)) GL.glEnable(GL.GL_LIGHT0) GL.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, (0.0, 0.0, 0.0, 1.0)) GL.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0)) GL.glLightfv(GL.GL_LIGHT1, GL.GL_SPECULAR, (1.0, 1.0, 1.0, 1.0)) GL.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, (1.0, 1.0, 1.0)) GL.glEnable(GL.GL_LIGHT1) GL.glEnable(GL.GL_LIGHTING) #print "set up materials" GL.glEnable(GL.GL_COLOR_MATERIAL) GL.glColorMaterial ( GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE )
def glinit(self,mode=None): if mode: self.rendermode = mode GL.glClearColor(*colors.RGBA(self.bgcolor))# Clear The Background Color GL.glClearDepth(1.0) # Enables Clearing Of The Depth Buffer GL.glDepthFunc(GL.GL_LESS) # The Type Of Depth Test To Do GL.glEnable(GL.GL_DEPTH_TEST) # Enables Depth Testing if self.rendermode == 'wireframe': GL.glShadeModel(GL.GL_FLAT) # Enables Flat Color Shading GL.glDisable(GL.GL_LIGHTING) elif self.rendermode == 'flat': GL.glShadeModel(GL.GL_FLAT) # Enables Flat Color Shading GL.glDisable(GL.GL_LIGHTING) elif self.rendermode == 'smooth': GL.glShadeModel(GL.GL_SMOOTH) # Enables Smooth Color Shading GL.glEnable(GL.GL_LIGHTING) for l,i in zip(['light0','light1'],[GL.GL_LIGHT0,GL.GL_LIGHT1]): key = 'render/%s' % l light = GD.cfg.get(key,self.default_light) GD.debug(" set up %s %s" % (l,light)) GL.glLightModel(GL.GL_LIGHT_MODEL_AMBIENT,rgba(GD.cfg['render/ambient'])) GL.glLightModel(GL.GL_LIGHT_MODEL_TWO_SIDE, GL.GL_TRUE) GL.glLightModel(GL.GL_LIGHT_MODEL_LOCAL_VIEWER, 0) GL.glLightfv(i,GL.GL_AMBIENT,rgba(light['ambient'])) GL.glLightfv(i,GL.GL_DIFFUSE,rgba(light['diffuse'])) GL.glLightfv(i,GL.GL_SPECULAR,rgba(light['specular'])) GL.glLightfv(i,GL.GL_POSITION,rgba(light['position'])) GL.glEnable(i) GL.glMaterialfv(GL.GL_FRONT_AND_BACK,GL.GL_SPECULAR,rgba(GD.cfg['render/specular'])) GL.glMaterialfv(GL.GL_FRONT_AND_BACK,GL.GL_EMISSION,rgba(GD.cfg['render/emission'])) GL.glMaterialfv(GL.GL_FRONT_AND_BACK,GL.GL_SHININESS,GD.cfg['render/shininess']) GL.glColorMaterial(GL.GL_FRONT_AND_BACK,GL.GL_AMBIENT_AND_DIFFUSE) GL.glEnable(GL.GL_COLOR_MATERIAL) else: raise RuntimeError,"Unknown rendering mode"
def glinit(self,mode=None): if mode: self.rendermode = mode GL.glClearColor(*RGBA(self.bgcolor))# Clear The Background Color GL.glClearDepth(1.0) # Enables Clearing Of The Depth Buffer GL.glDepthFunc(GL.GL_LESS) # The Type Of Depth Test To Do GL.glEnable(GL.GL_DEPTH_TEST) # Enables Depth Testing if self.rendermode == 'wireframe': GL.glShadeModel(GL.GL_FLAT) # Enables Flat Color Shading GL.glDisable(GL.GL_LIGHTING) elif self.rendermode == 'flat': GL.glShadeModel(GL.GL_FLAT) # Enables Flat Color Shading GL.glDisable(GL.GL_LIGHTING) elif self.rendermode == 'smooth': GL.glShadeModel(GL.GL_SMOOTH) # Enables Smooth Color Shading #print "set up materials" #GL.glMaterialfv(GL.GL_FRONT,GL.GL_AMBIENT_AND_DIFFUSE,(0.5,0.5,0.5,1.)) #print GD.cfg.render.specular #print GD.cfg.render.shininess GL.glMaterialfv(GL.GL_FRONT_AND_BACK,GL.GL_SPECULAR,GD.cfg.render.specular) GL.glMaterialfv(GL.GL_FRONT_AND_BACK,GL.GL_SHININESS,GD.cfg.render.shininess) GL.glColorMaterial(GL.GL_FRONT_AND_BACK,GL.GL_AMBIENT_AND_DIFFUSE) GL.glEnable(GL.GL_COLOR_MATERIAL) #print "set up lights" #print GD.cfg.render.keys() GL.glEnable(GL.GL_LIGHTING) for l,i in zip(['light0','light1'],[GL.GL_LIGHT0,GL.GL_LIGHT1]): #print " set up light ",l,i if GD.cfg.render.has_key(l): #print GD.cfg.render[l] GL.glLightModel(GL.GL_LIGHT_MODEL_TWO_SIDE, GL.GL_TRUE) GL.glLightfv(i,GL.GL_AMBIENT,GD.cfg.render[l]['ambient']) GL.glLightfv(i,GL.GL_DIFFUSE,GD.cfg.render[l]['diffuse']) GL.glLightfv(i,GL.GL_SPECULAR,GD.cfg.render[l]['specular']) GL.glLightfv(i,GL.GL_POSITION,GD.cfg.render[l]['position']) GL.glEnable(i) else: raise RuntimeError,"Unknown rendering mode"