title: Pyglet 2.0: How to Manipulate light in 3D projection?
body: <p>For those familiar with 3D games in Pyglet version 2.0, can you help me out with a lighting issue and maybe clarify how pyglet's new graphics classes work?</p>
  <p>I am basically attempting to simulate a day/night cycle for my 3D world, which, of course, would require me to manipulate the scene's light (pos,color, and brightness). My world is currently lit with some default light source, however, I can't change any of its properties. The only thing I know is that it's fixed to the &quot;camera's&quot; position. Changing the window's view projection changes the angle of the light.</p>
  <p>There are already a few questions with solutions pertaining to OpenGL lights in previous pyglet versions. But Pyglet 2.0 seems to work very differently in that none of those solutions work for me. Trying to change the light's properties with Opengl calls like   glLightfv(GL_LIGHT0, GL_POSITION, (GLfloat*4)(1, 0, .5, 0)) doesn't affect this default light. Even when I disable gl_lighting and GL_LIGHT0, my model stays lit. I've scoured pyglet's code to find where the default light is enabled and defined with no success.
  Am I doing something wrong or in the wrong order? Or does lighting just work differently in pyglet 2.0?</p>
  <p>Below is my code. I only left out the HUD and World classes.</p>
  <p>for the App Class:</p>
  <pre><code>class App(object):
  def __init__(self):
      #Initialize Window
      self.world = World(50)
      self.win = Window(1280, 900, self.world)
      self.win.active = True
      self.hud = Hud(self.win,self.world)
  
  def run(self):
      while not self.win.has_exit:
          self.win.dispatch_events()
  
          self.win.clear()
          glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
          
          
          self.win.camera.ProjectWorld()
          self.world.Draw()
  
          self.win.camera.ProjectHud()
          self.hud.Draw()
  
          self.win.flip()
  </code></pre>
  <p>the Camera Class:</p>
  <pre><code>class Camera(object):
  def __init__(self, win):
      self.win = win
      self.ZOOM_IN_FACTOR = 1.05
      self.ZOOM_OUT_FACTOR = 1/self.ZOOM_IN_FACTOR
  
      #initialize camera values
      self.zoom_level = 1
      self.modelposx = 0
      self.modelposy = 0
  
  
  def ProjectWorld(self):
      glEnable(GL_DEPTH_TEST)
      self.win.projection = self.win.modelview
      self.win.view = Mat4.from_translation(Vec3(-self.modelposx,-self.modelposy,-100*self.zoom_level))
      
  
  def ProjectHud(self):
      glDisable(GL_DEPTH_TEST)
      self.win.projection = self.win.uiview
      self.win.view = Mat4.from_translation(Vec3(0, 0, -50*self.zoom_level))
  </code></pre>
  <p>and Window Class:</p>
  <pre><code>class Window(window.Window):
  def __init__(self, width, height, world):
      #Initialize Window
      conf = Config(sample_buffers=1, samples=4, depth_size=16, double_buffer=True)
      super(Window,self).__init__(width, height, caption='World Generator', config=conf, resizable=True)        
      self.camera = Camera(self)
      self.modelview = Mat4.perspective_projection(0,width,0,height, z_near=0.01, z_far = 400, fov=60)
      self.uiview = Mat4.orthogonal_projection(0, width, 0, height, z_near = 0.01, z_far = 400)
  
      
  def init_gl(self, width, height):
  
      # Set 3D 
      glEnable(GL_DEPTH_TEST)
      glEnable(GL_CULL_FACE)
      glEnable(GL_LIGHTING)
  
      
      glLightfv(GL_LIGHT0, GL_SPECULAR, (GLfloat*4)(.5,.5,1,1))
      glLightfv(GL_LIGHT0, GL_DIFFUSE, (GLfloat*4)(1,1,1,1))
      glLightfv(GL_LIGHT0, GL_POSITION, (GLfloat*4)(1, 0, .5, 0))
      glEnable(GL_LIGHT0)
  
      glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
  
      glEnable(GL_TEXTURE_2D)
      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
      
      # Set clear color
      pyglet.gl.glClearColor(0.8, 0.8, 0.8, 1.0)        
  
      # Set viewport
      glViewport(0, 0, width, height)
  
  
  def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
      # Move camera
      self.camera.modelposx -= (dx*self.camera.zoom_level)/10
      self.camera.modelposy -= (dy*self.camera.zoom_level)/10
      print(dy*self.camera.modelposx)
      print(dx*self.camera.modelposy)
  
  def on_resize(self, width, height):
      self.init_gl(width, height)
      self.projection = self.uiview
      self.view = self.view.translate(Vec3(-50,-50,-50))  
  
  def on_mouse_scroll(self, x, y, dx, dy):
      # Get scale factor
      f = self.camera.ZOOM_IN_FACTOR if dy &gt; 0 else self.camera.ZOOM_OUT_FACTOR if dy &lt; 0 else 1
      # If zoom_level is in the proper range
      if .2 &lt; self.camera.zoom_level*f &lt; 5:
          self.camera.zoom_level *= f
  </code></pre>
  <p>Please let me know if I should include anything else in this post!</p>