Commit 5684c83e authored by Guillaume Seguin's avatar Guillaume Seguin

Move lighting to panel to create lights at a fixed position

parent f5a722d5
......@@ -517,30 +517,10 @@ class GcodeModel(Model):
glTranslatef(self.offset_x, self.offset_y, 0)
glEnableClientState(GL_VERTEX_ARRAY)
glDisable(GL_LIGHTING)
glEnable(GL_RESCALE_NORMAL)
glShadeModel(GL_SMOOTH)
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1)
glLightfv(GL_LIGHT0, GL_AMBIENT, vec(0.2, 0.2, 0.2, 1.0))
glLightfv(GL_LIGHT0, GL_SPECULAR, vec(0, 0, 0, 0))
glLightfv(GL_LIGHT0, GL_DIFFUSE, vec(0, 0, 0, 0))
glEnable(GL_LIGHT1)
glLightfv(GL_LIGHT1, GL_AMBIENT, vec(0, 0, 0, 1.0))
glLightfv(GL_LIGHT1, GL_SPECULAR, vec(1., 1., 1., 1.))
glLightfv(GL_LIGHT1, GL_DIFFUSE, vec(0.72, 0.72, 0.72, 1))
glLightfv(GL_LIGHT1, GL_POSITION, vec(1, 2, 3, 0))
glLightfv(GL_LIGHT1, GL_SPOT_EXPONENT, vec(1., 1., 1., 1.))
glEnable(GL_LIGHT2)
glLightfv(GL_LIGHT2, GL_AMBIENT, vec(0, 0, 0, 1.0))
glLightfv(GL_LIGHT2, GL_SPECULAR, vec(1., 1., 1., 1.))
glLightfv(GL_LIGHT2, GL_DIFFUSE, vec(0.8, 0.8, 0.8, 1))
glLightfv(GL_LIGHT2, GL_POSITION, vec(-1, -1, 2, 0))
has_vbo = isinstance(self.vertex_buffer, VertexBufferObject)
self._display_travels(has_vbo)
glEnable(GL_LIGHTING)
glEnableClientState(GL_COLOR_ARRAY)
glMaterialfv(GL_FRONT, GL_SPECULAR, vec(1, 1, 1, 1))
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, vec(0, 0, 0, 0))
......@@ -549,10 +529,8 @@ class GcodeModel(Model):
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
self._display_movements(has_vbo)
glDisable(GL_LIGHT0)
glDisable(GL_LIGHT1)
glDisable(GL_LIGHT2)
glDisable(GL_LIGHTING)
glDisableClientState(GL_COLOR_ARRAY)
glDisableClientState(GL_VERTEX_ARRAY)
......
......@@ -26,6 +26,7 @@ pyglet.options['debug_gl'] = True
from pyglet.gl import *
from pyglet import gl
from .trackball import trackball, mulquat, build_rotmatrix
from .libtatlin.actors import vec
class wxGLPanel(wx.Panel):
'''A simple class for using OpenGL with wxPython.'''
......@@ -153,9 +154,31 @@ class wxGLPanel(wx.Panel):
self.pygletcontext.set_current()
self.update_object_resize()
def setup_lights(self):
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1)
glLightfv(GL_LIGHT0, GL_AMBIENT, vec(0.2, 0.2, 0.2, 1.0))
glLightfv(GL_LIGHT0, GL_SPECULAR, vec(0, 0, 0, 0))
glLightfv(GL_LIGHT0, GL_DIFFUSE, vec(0, 0, 0, 0))
glEnable(GL_LIGHT1)
glLightfv(GL_LIGHT1, GL_AMBIENT, vec(0, 0, 0, 1.0))
glLightfv(GL_LIGHT1, GL_SPECULAR, vec(1., 1., 1., 1.))
glLightfv(GL_LIGHT1, GL_DIFFUSE, vec(0.72, 0.72, 0.72, 1))
glLightfv(GL_LIGHT1, GL_POSITION, vec(1, 2, 3, 0))
glLightfv(GL_LIGHT1, GL_SPOT_EXPONENT, vec(1., 1., 1., 1.))
glEnable(GL_LIGHT2)
glLightfv(GL_LIGHT2, GL_AMBIENT, vec(0, 0, 0, 1.0))
glLightfv(GL_LIGHT2, GL_SPECULAR, vec(1., 1., 1., 1.))
glLightfv(GL_LIGHT2, GL_DIFFUSE, vec(0.8, 0.8, 0.8, 1))
glLightfv(GL_LIGHT2, GL_POSITION, vec(-1, -1, 2, 0))
glEnable(GL_RESCALE_NORMAL)
glShadeModel(GL_SMOOTH)
def reset_mview(self, factor):
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
self.setup_lights()
if self.orthographic:
ratio = factor * float(min(self.width, self.height)) / self.dist
self.zoom_factor = 1.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment