def display(self, mode_2d=False): with self.lock: glPushMatrix() glTranslatef(self.offset_x, self.offset_y, 0) glEnableClientState(GL_VERTEX_ARRAY) has_vbo = isinstance(self.vertex_buffer, VertexBufferObject) if self.display_travels: self._display_travels(has_vbo) glEnable(GL_LIGHTING) glEnableClientState(GL_NORMAL_ARRAY) 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)) glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50) glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE) self._display_movements(has_vbo) glDisable(GL_LIGHTING) glDisableClientState(GL_COLOR_ARRAY) glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_NORMAL_ARRAY) glPopMatrix()
def init_gl(self): gl.glClearColor(.93, .93, 1, 1) # glColor3f(1, 0, 0) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_CULL_FACE) gl.glEnable(gl.GL_LIGHTING) gl.glEnable(gl.GL_LIGHT0) gl.glEnable(gl.GL_LIGHT1) gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, _gl_vector(.5, .5, 1, 0)) gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, _gl_vector(.5, .5, 1, 1)) gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, _gl_vector(1, 1, 1, 1)) gl.glLightfv(gl.GL_LIGHT1, gl.GL_POSITION, _gl_vector(1, 0, .5, 0)) gl.glLightfv(gl.GL_LIGHT1, gl.GL_DIFFUSE, _gl_vector(.5, .5, .5, 1)) gl.glLightfv(gl.GL_LIGHT1, gl.GL_SPECULAR, _gl_vector(1, 1, 1, 1)) gl.glColorMaterial(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE) gl.glEnable(gl.GL_COLOR_MATERIAL) gl.glShadeModel(gl.GL_SMOOTH) gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, _gl_vector(0.192250, 0.192250, 0.192250)) gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, _gl_vector(0.507540, 0.507540, 0.507540)) gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, _gl_vector(.5082730, .5082730, .5082730)) gl.glMaterialf(gl.GL_FRONT, gl.GL_SHININESS, .4 * 128.0) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
def setup(): # One-time GL setup glClearColor(1, 1, 1, 1) glColor3f(1, 0, 0) glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) # Uncomment this line for a wireframe view #glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) # Simple light setup. On Windows GL_LIGHT0 is enabled by default, # but this is not the case on Linux or Mac, so remember to always # include it. glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_LIGHT1) # Define a simple function to create ctypes arrays of floats: def vec(*args): return (GLfloat * len(args))(*args) glLightfv(GL_LIGHT0, GL_POSITION, vec(.5, .5, 1, 0)) glLightfv(GL_LIGHT0, GL_SPECULAR, vec(.5, .5, 1, 1)) glLightfv(GL_LIGHT0, GL_DIFFUSE, vec(1, 1, 1, 1)) glLightfv(GL_LIGHT1, GL_POSITION, vec(1, 0, .5, 0)) glLightfv(GL_LIGHT1, GL_DIFFUSE, vec(.5, .5, .5, 1)) glLightfv(GL_LIGHT1, GL_SPECULAR, vec(1, 1, 1, 1)) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(0.5, 0, 0.3, 1)) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec(1, 1, 1, 1)) glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50)
def init_gl(self): gl.glClearColor(.93, .93, 1, 1) #glColor3f(1, 0, 0) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_CULL_FACE) gl.glEnable(gl.GL_LIGHTING) gl.glEnable(gl.GL_LIGHT0) gl.glEnable(gl.GL_LIGHT1) gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, _gl_vector(.5, .5, 1, 0)) gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, _gl_vector(.5, .5, 1, 1)) gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, _gl_vector(1, 1, 1, 1)) gl.glLightfv(gl.GL_LIGHT1, gl.GL_POSITION, _gl_vector(1, 0, .5, 0)) gl.glLightfv(gl.GL_LIGHT1, gl.GL_DIFFUSE, _gl_vector(.5, .5, .5, 1)) gl.glLightfv(gl.GL_LIGHT1, gl.GL_SPECULAR, _gl_vector(1, 1, 1, 1)) gl.glColorMaterial(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE) gl.glEnable(gl.GL_COLOR_MATERIAL) gl.glShadeModel(gl.GL_SMOOTH) gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, _gl_vector(0.192250, 0.192250, 0.192250)) gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, _gl_vector(0.507540, 0.507540, 0.507540)) gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, _gl_vector(.5082730,.5082730,.5082730)) gl.glMaterialf(gl.GL_FRONT, gl.GL_SHININESS, .4 * 128.0); gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
def gl_set(self): """ Set this color to the current material in OpenGL. """ color = (gl.GLfloat * 4)(*[self.red, self.green, self.blue, self.opacity]) gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE, color) gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR, color) gl.glMaterialf(gl.GL_FRONT_AND_BACK, gl.GL_SHININESS, 50)
def gl_set(self, opacity=1.0): """ Set the current material to this color :param opacity: the opacity value of the color :type opacity: float """ color = (gl.GLfloat * 4)(*[self.red, self.green, self.blue, opacity]) gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE, color) gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR, color) gl.glMaterialf(gl.GL_FRONT_AND_BACK, gl.GL_SHININESS, 50)
def gl_enable_color_material(): # do some openGL things gl.glColorMaterial(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE) gl.glEnable(gl.GL_COLOR_MATERIAL) gl.glShadeModel(gl.GL_SMOOTH) gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, gl_float([0.192250, 0.192250, 0.192250])) gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, gl_float([0.507540, 0.507540, 0.507540])) gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, gl_float([.5082730, .5082730, .5082730])) gl.glMaterialf(gl.GL_FRONT, gl.GL_SHININESS, .4 * 128.0)
def init_gl(self): """ Perform the magic incantations to create an OpenGL scene. """ # the background color gl.glClearColor(.97, .97, .97, 1.0) max_depth = (np.abs(self.scene.bounds).max(axis=1)**2).sum()**.5 max_depth = np.clip(max_depth, 500.00, np.inf) gl.glDepthRange(0.0, max_depth) gl.glClearDepth(1.0) gl.glEnable(gl.GL_DEPTH_TEST) gl.glDepthFunc(gl.GL_LEQUAL) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_CULL_FACE) gl.glEnable(gl.GL_LIGHTING) gl.glEnable(gl.GL_LIGHT0) gl.glEnable(gl.GL_LIGHT1) # put the light at one corner of the scenes AABB gl.glLightfv( gl.GL_LIGHT0, gl.GL_POSITION, rendering.vector_to_gl(np.append(self.scene.bounds[1], 0))) gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, rendering.vector_to_gl(.5, .5, 1, 1)) gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, rendering.vector_to_gl(1, 1, 1, .75)) gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, rendering.vector_to_gl(.1, .1, .1, .2)) gl.glColorMaterial(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE) gl.glEnable(gl.GL_COLOR_MATERIAL) gl.glShadeModel(gl.GL_SMOOTH) gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, rendering.vector_to_gl(0.192250, 0.192250, 0.192250)) gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, rendering.vector_to_gl(0.507540, 0.507540, 0.507540)) gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, rendering.vector_to_gl(.5082730, .5082730, .5082730)) gl.glMaterialf(gl.GL_FRONT, gl.GL_SHININESS, .4 * 128.0) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glEnable(gl.GL_LINE_SMOOTH) gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST) gl.glLineWidth(1.5) gl.glPointSize(4)
def _gl_enable_color_material(): gl.glColorMaterial(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE) gl.glEnable(gl.GL_COLOR_MATERIAL) gl.glShadeModel(gl.GL_SMOOTH) gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, rendering.vector_to_gl(0.192250, 0.192250, 0.192250)) gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, rendering.vector_to_gl(0.507540, 0.507540, 0.507540)) gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, rendering.vector_to_gl(.5082730, .5082730, .5082730)) gl.glMaterialf(gl.GL_FRONT, gl.GL_SHININESS, .4 * 128.0)
def set_state(self, face=gl.GL_FRONT_AND_BACK): if self.texture: gl.glEnable(self.texture.target) gl.glBindTexture(self.texture.target, self.texture.id) else: gl.glDisable(gl.GL_TEXTURE_2D) float4 = (gl.GLfloat * 4) o = [self.opacity] gl.glMaterialfv(face, gl.GL_DIFFUSE, float4(*(self.diffuse + o))) gl.glMaterialfv(face, gl.GL_AMBIENT, float4(*(self.ambient + o))) gl.glMaterialfv(face, gl.GL_SPECULAR, float4(*(self.specular + o))) gl.glMaterialfv(face, gl.GL_EMISSION, float4(*(self.emission + o))) gl.glMaterialf(face, gl.GL_SHININESS, self.shininess)
def setup(self): # One-time GL setup gl.glClearColor(1, 1, 1, 0) gl.glColor3f(1, 0, 0) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_CULL_FACE) # Uncomment this line for a wireframe view #glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) # Simple light setup. On Windows GL_LIGHT0 is enabled by default, # but this is not the case on Linux or Mac, so remember to always # include it. gl.glEnable(gl.GL_LIGHTING) gl.glEnable(gl.GL_LIGHT0) gl.glEnable(gl.GL_LIGHT1) # Define a simple function to create ctypes arrays of floats: def vec(*args): return (gl.GLfloat * len(args))(*args) gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, vec(.5, .5, 1, 0)) gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, vec(.5, .5, 1, 1)) gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, vec(1, 1, 1, 1)) gl.glLightfv(gl.GL_LIGHT1, gl.GL_POSITION, vec(1, 0, .5, 0)) gl.glLightfv(gl.GL_LIGHT1, gl.GL_DIFFUSE, vec(.5, .5, .5, 1)) gl.glLightfv(gl.GL_LIGHT1, gl.GL_SPECULAR, vec(1, 1, 1, 1)) gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE, vec(0.5, 0, 0.3, 1)) gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR, vec(1, 1, 1, 1)) gl.glMaterialf(gl.GL_FRONT_AND_BACK, gl.GL_SHININESS, 50) if sys.platform in ('win32', 'cygwin'): font = 'Arial' else: font = 'DejaVu Sans Mono' self.lowerlabel = pyglet.text.Label('Hello, world', font_size=14, font_name=font, x=5, y=20, color=(0, 0, 0, 255)) self.upperlabel = pyglet.text.Label('Hello, world', font_size=14, font_name=font, x=20, y=20, color=(0, 0, 0, 255))
def OnInitGL(self, call_reshape=True): '''Initialize OpenGL for use in the window.''' if self.GLinitialized: return self.GLinitialized = True # create a pyglet context for this panel self.pygletcontext = gl.Context(gl.current_context) self.pygletcontext.canvas = self self.pygletcontext.set_current() # normal gl init glClearColor(0, 0, 0, 1) glColor3f(1, 0, 0) glEnable(GL_DEPTH_TEST) glClearDepth(1.0) glDepthFunc(GL_LEQUAL) glEnable(GL_CULL_FACE) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) # Uncomment this line for a wireframe view # glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) # Simple light setup. On Windows GL_LIGHT0 is enabled by default, # but this is not the case on Linux or Mac, so remember to always # include it. glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_LIGHT1) glLightfv(GL_LIGHT0, GL_POSITION, vec(.5, .5, 1, 0)) glLightfv(GL_LIGHT0, GL_SPECULAR, vec(.5, .5, 1, 1)) glLightfv(GL_LIGHT0, GL_DIFFUSE, vec(1, 1, 1, 1)) glLightfv(GL_LIGHT1, GL_POSITION, vec(1, 0, .5, 0)) glLightfv(GL_LIGHT1, GL_DIFFUSE, vec(.5, .5, .5, 1)) glLightfv(GL_LIGHT1, GL_SPECULAR, vec(1, 1, 1, 1)) glShadeModel(GL_SMOOTH) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(0.5, 0, 0.3, 1)) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec(1, 1, 1, 1)) glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50) glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, vec(0, 0.1, 0, 0.9)) if call_reshape: self.OnReshape() if hasattr(self.parent, "filenames") and self.parent.filenames: for filename in self.parent.filenames: self.parent.load_file(filename) self.parent.autoplate() if hasattr(self.parent, "loadcb"): self.parent.loadcb() self.parent.filenames = None
def OnInitGL(self, call_reshape = True): '''Initialize OpenGL for use in the window.''' if self.GLinitialized: return self.GLinitialized = True # create a pyglet context for this panel self.pygletcontext = gl.Context(gl.current_context) self.pygletcontext.canvas = self self.pygletcontext.set_current() # normal gl init glClearColor(0, 0, 0, 1) glColor3f(1, 0, 0) glEnable(GL_DEPTH_TEST) glClearDepth(1.0) glDepthFunc(GL_LEQUAL) glEnable(GL_CULL_FACE) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) # Uncomment this line for a wireframe view # glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) # Simple light setup. On Windows GL_LIGHT0 is enabled by default, # but this is not the case on Linux or Mac, so remember to always # include it. glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_LIGHT1) glLightfv(GL_LIGHT0, GL_POSITION, vec(.5, .5, 1, 0)) glLightfv(GL_LIGHT0, GL_SPECULAR, vec(.5, .5, 1, 1)) glLightfv(GL_LIGHT0, GL_DIFFUSE, vec(1, 1, 1, 1)) glLightfv(GL_LIGHT1, GL_POSITION, vec(1, 0, .5, 0)) glLightfv(GL_LIGHT1, GL_DIFFUSE, vec(.5, .5, .5, 1)) glLightfv(GL_LIGHT1, GL_SPECULAR, vec(1, 1, 1, 1)) glShadeModel(GL_SMOOTH) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(0.5, 0, 0.3, 1)) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec(1, 1, 1, 1)) glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50) glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, vec(0, 0.1, 0, 0.9)) if call_reshape: self.OnReshape() if hasattr(self.parent, "filenames") and self.parent.filenames: for filename in self.parent.filenames: self.parent.load_file(filename) self.parent.autoplate() if hasattr(self.parent, "loadcb"): self.parent.loadcb() self.parent.filenames = None
def init_gl(self, on_init=None, **kwargs): gl.glClearColor(.97, .97, .97, 1.0) max_depth = (np.abs(self.scene.bounds).max(axis=1)**2).sum()**.5 max_depth = np.clip(max_depth, 500.00, np.inf) gl.glDepthRange(0.0, max_depth) gl.glClearDepth(1.0) gl.glEnable(gl.GL_DEPTH_TEST) gl.glDepthFunc(gl.GL_LEQUAL) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_CULL_FACE) gl.glEnable(gl.GL_LIGHTING) gl.glEnable(gl.GL_LIGHT0) gl.glEnable(gl.GL_LIGHT1) # put the light at one corner of the scenes AABB gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, _gl_vector(np.append(self.scene.bounds[1], 0))) gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, _gl_vector(.5, .5, 1, 1)) gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, _gl_vector(1, 1, 1, .75)) gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, _gl_vector(.1, .1, .1, .2)) gl.glColorMaterial(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE) gl.glEnable(gl.GL_COLOR_MATERIAL) gl.glShadeModel(gl.GL_SMOOTH) gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, _gl_vector(0.192250, 0.192250, 0.192250)) gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, _gl_vector(0.507540, 0.507540, 0.507540)) gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, _gl_vector(.5082730, .5082730, .5082730)) gl.glMaterialf(gl.GL_FRONT, gl.GL_SHININESS, .4 * 128.0) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glEnable(gl.GL_LINE_SMOOTH) gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST) gl.glLineWidth(1.5) gl.glPointSize(4) if on_init: on_init(gl, **kwargs)
def setMaterial(self, name): if name == 'neutral': # 'lines' mat_ambient = [0.6, 0.6, 0.6, 1.0] #[0.3, 0.3, 0.4, 1.0] gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, glvecf(mat_ambient)) mat_diffuse = [0.1, 0.1, 0.1] #[0.7, 0.5, 0.5, 1.0] gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_DIFFUSE, glvecf(mat_diffuse)) mat_specular = [0.2, 0.2, 0.2] gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR, glvecf(mat_specular)) shine = 0.0 gl.glMaterialf(gl.GL_FRONT_AND_BACK, gl.GL_SHININESS, shine * 128.0) elif name == 'metal': # 'chrome' mat_ambient = [0.25, 0.25, 0.25, 1.0] #[0.3, 0.3, 0.4, 1.0] gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, glvecf(mat_ambient)) mat_diffuse = [0.4, 0.4, 0.4] #[0.7, 0.5, 0.5, 1.0] gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, glvecf(mat_diffuse)) mat_specular = [0.774597, 0.774597, 0.774597] gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, glvecf(mat_specular)) shine = 0.6 gl.glMaterialf(gl.GL_FRONT, gl.GL_SHININESS, shine * 128.0) mat_emission = [0.1, 0.1, 0.1, 1.0] gl.glMaterialfv(gl.GL_FRONT, gl.GL_EMISSION, glvecf(mat_emission)) elif name == 'green rubber': mat_ambient = [0.01, 0.1, 0.01, 1.0] gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, glvecf(mat_ambient)) mat_diffuse = [0.5, 0.6, 0.5] gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, glvecf(mat_diffuse)) mat_specular = [0.05, 0.1, 0.05] gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, glvecf(mat_specular)) shine = 0.03 gl.glMaterialf(gl.GL_FRONT, gl.GL_SHININESS, shine * 128.0) #mat_emission = [0.1, 0.1, 0.15, 1.0] #gl.glMaterialfv(gl.GL_FRONT, gl.GL_EMISSION, glvecf(mat_emission)) elif name == 'white rubber': mat_ambient = [0.7, 0.7, 0.7, 1.0] gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, glvecf(mat_ambient)) mat_diffuse = [0.5, 0.5, 0.5] gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, glvecf(mat_diffuse)) mat_specular = [0.01, 0.01, 0.01] gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, glvecf(mat_specular)) shine = 0.03 gl.glMaterialf(gl.GL_FRONT, gl.GL_SHININESS, shine * 128.0) mat_emission = [0.2, 0.2, 0.2, 1.0] gl.glMaterialfv(gl.GL_FRONT, gl.GL_EMISSION, glvecf(mat_emission)) else: print('Undefined material {}'.format(name))
def apply(self): gl.glEnable(gl.GL_LIGHTING) for s in self.shaders: s.bind() for i, t in enumerate(self.textures): gl.glActiveTexture(gl.GL_TEXTURE0 + i) gl.glEnable(gl.GL_TEXTURE_2D) gl.glBindTexture(gl.GL_TEXTURE_2D, t.id) self.parameters["tex[%u]" % i] = i for k in self.parameters.keys(): if type(self.parameters[k]) == type(0): for s in self.shaders: s.uniformi(k, self.parameters[k]) if type(self.parameters[k]) == type(0.0): for s in self.shaders: s.uniformf(k, self.parameters[k]) a = self.ambient_rgb d = self.diffuse_rgb s = self.specular_rgb gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, raw(a[0], a[1], a[2], 1.0)) gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_DIFFUSE, raw(d[0], d[1], d[2], 1.0)) gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR, raw(s[0], s[1], s[2], 1.0)) gl.glMaterialf(gl.GL_FRONT_AND_BACK, gl.GL_SHININESS, self.shininess)
def init_gl(self): """ Perform the magic incantations to create an OpenGL scene using pyglet. """ # default background color is white-ish background = [.99, .99, .99, 1.0] # if user passed a background color use it if 'background' in self.kwargs: try: # convert to (4,) uint8 RGBA background = to_rgba(self.kwargs['background']) # convert to 0.0 - 1.0 float background = background.astype(np.float64) / 255.0 except BaseException: log.error('background color set but wrong!', exc_info=True) # apply the background color gl.glClearColor(*background) # find the maximum depth based on # maximum length of scene AABB max_depth = (np.abs(self.scene.bounds).max(axis=1) ** 2).sum() ** .5 max_depth = np.clip(max_depth, 500.00, np.inf) gl.glDepthRange(0.0, max_depth) gl.glClearDepth(1.0) gl.glEnable(gl.GL_DEPTH_TEST) gl.glDepthFunc(gl.GL_LEQUAL) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_CULL_FACE) # do some openGL things gl.glColorMaterial(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE) gl.glEnable(gl.GL_COLOR_MATERIAL) gl.glShadeModel(gl.GL_SMOOTH) gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, rendering.vector_to_gl( 0.192250, 0.192250, 0.192250)) gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, rendering.vector_to_gl( 0.507540, 0.507540, 0.507540)) gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, rendering.vector_to_gl( .5082730, .5082730, .5082730)) gl.glMaterialf(gl.GL_FRONT, gl.GL_SHININESS, .4 * 128.0) # enable blending for transparency gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) # make the lines from Path3D objects less ugly gl.glEnable(gl.GL_LINE_SMOOTH) gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST) # set the width of lines to 1.5 pixels gl.glLineWidth(1.5) # set PointCloud markers to 4 pixels in size gl.glPointSize(4) # set up the viewer lights using self.scene self.update_lighting()
def init_gl(self): """ Perform the magic incantations to create an OpenGL scene. """ # default background color is white-ish background = [.99, .99, .99, 1.0] # if user passed a background color use it if 'background' in self.kwargs: try: # convert to (4,) uint8 RGBA background = to_rgba(self.kwargs['background']) # convert to 0.0 - 1.0 float background = background.astype(np.float64) / 255.0 except BaseException: log.error('background color wrong!', exc_info=True) # apply the background color gl.glClearColor(*background) max_depth = (np.abs(self.scene.bounds).max(axis=1)**2).sum()**.5 max_depth = np.clip(max_depth, 500.00, np.inf) gl.glDepthRange(0.0, max_depth) gl.glClearDepth(1.0) gl.glEnable(gl.GL_DEPTH_TEST) gl.glDepthFunc(gl.GL_LEQUAL) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_CULL_FACE) gl.glEnable(gl.GL_LIGHTING) gl.glEnable(gl.GL_LIGHT0) gl.glEnable(gl.GL_LIGHT1) # put the light at one corner of the scenes AABB gl.glLightfv( gl.GL_LIGHT0, gl.GL_POSITION, rendering.vector_to_gl(np.append(self.scene.bounds[1], 0))) gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, rendering.vector_to_gl(.5, .5, 1, 1)) gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, rendering.vector_to_gl(1, 1, 1, .75)) gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, rendering.vector_to_gl(.1, .1, .1, .2)) gl.glColorMaterial(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE) gl.glEnable(gl.GL_COLOR_MATERIAL) gl.glShadeModel(gl.GL_SMOOTH) gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, rendering.vector_to_gl(0.192250, 0.192250, 0.192250)) gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, rendering.vector_to_gl(0.507540, 0.507540, 0.507540)) gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, rendering.vector_to_gl(.5082730, .5082730, .5082730)) gl.glMaterialf(gl.GL_FRONT, gl.GL_SHININESS, .4 * 128.0) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glEnable(gl.GL_LINE_SMOOTH) gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST) gl.glLineWidth(1.5) gl.glPointSize(4)