def _setup_lighting(self): """ [private method] Set up lighting in the model (according to self._lights). [Called from both initializeGL and paintGL.] """ # note: there is some duplicated code in this method # in GLPane_lighting_methods (has more comments) and ThumbView, # but also significant differences. Should refactor sometime. # [bruce 060415/080912 comment] glEnable(GL_NORMALIZE) # bruce comment 050311: I don't know if this relates to lighting or not # grantham 20051121: Yes, if NORMALIZE is not enabled (and normals # aren't unit length or the modelview matrix isn't just rotation) # then the lighting equation can produce unexpected results. #bruce 050413 try to fix bug 507 in direction of lighting: ##k might be partly redundant now; not sure whether projection matrix needs to be modified here [bruce 051212] glMatrixMode(GL_PROJECTION) glLoadIdentity() glMatrixMode(GL_MODELVIEW) glLoadIdentity() #bruce 051212 moved most code from this method into new function, setup_standard_lights setup_standard_lights( self._lights, self.glprefs) # record what glprefs data was used by that, for comparison to see when we need to call it again # (not needed for _lights since another system tells us when that changes) self._last_glprefs_data_used_by_lights = glprefs_data_used_by_setup_standard_lights( self.glprefs) return
def _setup_lighting(self): """ [private method] Set up lighting in the model (according to self._lights). [Called from both initializeGL and paintGL.] """ # note: there is some duplicated code in this method # in GLPane_lighting_methods (has more comments) and ThumbView, # but also significant differences. Should refactor sometime. # [bruce 060415/080912 comment] glEnable(GL_NORMALIZE) # bruce comment 050311: I don't know if this relates to lighting or not # grantham 20051121: Yes, if NORMALIZE is not enabled (and normals # aren't unit length or the modelview matrix isn't just rotation) # then the lighting equation can produce unexpected results. #bruce 050413 try to fix bug 507 in direction of lighting: ##k might be partly redundant now; not sure whether projection matrix needs to be modified here [bruce 051212] glMatrixMode(GL_PROJECTION) glLoadIdentity() glMatrixMode(GL_MODELVIEW) glLoadIdentity() #bruce 051212 moved most code from this method into new function, setup_standard_lights setup_standard_lights(self._lights, self.glprefs) # record what glprefs data was used by that, for comparison to see when we need to call it again # (not needed for _lights since another system tells us when that changes) self._last_glprefs_data_used_by_lights = glprefs_data_used_by_setup_standard_lights( self.glprefs) return
def setup_lighting_if_needed(self): #bruce 080910 un-inlined this if self.need_setup_lighting \ or (self._last_glprefs_data_used_by_lights != glprefs_data_used_by_setup_standard_lights( self.glprefs)) \ or debug_pref("always setup_lighting?", Choice_boolean_False): #bruce 060415 added debug_pref("always setup_lighting?"), # in GLPane and ThumbView [KEEP DFLTS THE SAME!!]; # using it makes specularity work on my iMac G4, # except for brief periods as you move mouse around to change selobj # (also observed on G5, but less frequently I think). # BTW using this (on G4) has no effect on whether "new wirespheres" # is needed to make wirespheres visible. # # (bruce 051126 added override_light_specular part of condition) # I don't know if it matters to avoid calling this every time... # in case it's slow, we'll only do it when it might have changed. self.need_setup_lighting = False # set to true again if setLighting is called self._setup_lighting() return