def background(*color): """Clears the screen with color. Color may be an (r,g,b) tuple or a single gray value. If depth testing is turned on, also clears the depth buffer.""" if len(color) == 1 and isinstance(color[0],PImage): image(color[0],0,0) else: color = _getColor(*color) glClearColor (*color) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
def updatePixels(): """Updates the display window with the data in the pixels array.""" new = createImage(width,height,'RGBA') color = _getColor((200)) glClearColor (*color) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) if npy: new.pixels = numpy.array(screen.pixels) new.updatePixels() else: for i in range(width*height): new.pixels[i] = screen.pixels[i] image(new,0,0)
def updatePixels(): """Updates the display window with the data in the pixels array.""" new = createImage(width, height, 'RGBA') color = _getColor((200)) glClearColor(*color) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) if npy: new.pixels = numpy.array(screen.pixels) new.updatePixels() else: for i in range(width * height): new.pixels[i] = screen.pixels[i] image(new, 0, 0)
def ambientLight(v1,v2,v3,x=0,y=0,z=0): """Adds an ambient light.""" _lightsOn() color = _getColor(v1,v2,v3) n = GL_LIGHT0 + attrib.lightCount attrib.lightCount += 1 glLightfv(n, GL_DIFFUSE, (ctypes.c_float * 3)(0,0,0)) glLightfv(n, GL_AMBIENT, (ctypes.c_float * 4)(*color)) glLightfv(n, GL_SPECULAR, (ctypes.c_float * 3)(0,0,0)) glLightfv(n, GL_POSITION, (ctypes.c_float * 4)(x,y,z,0)) constant, linear, quadratic = attrib.lightFalloff glLightf(n, GL_LINEAR_ATTENUATION, linear) glLightf(n, GL_QUADRATIC_ATTENUATION, quadratic) glLightf(n, GL_CONSTANT_ATTENUATION, constant) glEnable(n)
def ambientLight(v1, v2, v3, x=0, y=0, z=0): """Adds an ambient light.""" _lightsOn() color = _getColor(v1, v2, v3) n = GL_LIGHT0 + attrib.lightCount attrib.lightCount += 1 glLightfv(n, GL_DIFFUSE, (ctypes.c_float * 3)(0, 0, 0)) glLightfv(n, GL_AMBIENT, (ctypes.c_float * 4)(*color)) glLightfv(n, GL_SPECULAR, (ctypes.c_float * 3)(0, 0, 0)) glLightfv(n, GL_POSITION, (ctypes.c_float * 4)(x, y, z, 0)) constant, linear, quadratic = attrib.lightFalloff glLightf(n, GL_LINEAR_ATTENUATION, linear) glLightf(n, GL_QUADRATIC_ATTENUATION, quadratic) glLightf(n, GL_CONSTANT_ATTENUATION, constant) glEnable(n)
def pointLight(v1,v2,v3,x,y,z): """Adds a point light (diffuse/specular) with the given color and position.""" _lightsOn() color = _getColor(v1,v2,v3) n = GL_LIGHT0 + attrib.lightCount attrib.lightCount += 1 glLightfv(n, GL_DIFFUSE, (ctypes.c_float * 4)(*color)) glLightfv(n, GL_AMBIENT, (ctypes.c_float * 3)(0,0,0)) glLightfv(n, GL_SPECULAR, (ctypes.c_float * 4)(*attrib.lightSpecular)) glLightfv(n, GL_POSITION, (ctypes.c_float * 4)(x,y,z,1)) glLightfv(n, GL_SPOT_DIRECTION, (ctypes.c_float * 3)(0,0,-1)) glLightf(n, GL_SPOT_EXPONENT, 0) glLightf(n, GL_SPOT_CUTOFF, 180) constant, linear, quadratic = attrib.lightFalloff glLightf(n, GL_LINEAR_ATTENUATION, linear) glLightf(n, GL_QUADRATIC_ATTENUATION, quadratic) glLightf(n, GL_CONSTANT_ATTENUATION, constant) glEnable(n)
def spotLight(v1, v2, v3, x, y, z, nx, ny, nz, angle, concentration): """Adds a spot light source.""" _lightsOn() color = _getColor(v1,v2,v3) n = GL_LIGHT0 + attrib.lightCount attrib.lightCount += 1 glLightfv(n, GL_DIFFUSE, (ctypes.c_float * 4)(*color)) glLightfv(n, GL_AMBIENT, (ctypes.c_float * 3)(0,0,0)) glLightfv(n, GL_SPECULAR, (ctypes.c_float * 3)(0,0,0)) glLightfv(n, GL_POSITION, (ctypes.c_float * 4)(x,y,z,1)) glLightfv(n, GL_SPOT_DIRECTION, (ctypes.c_float * 3)(nx,ny,nz)) glLightf(n, GL_SPOT_EXPONENT, concentration) glLightf(n, GL_SPOT_CUTOFF, math.degrees(angle)) constant, linear, quadratic = attrib.lightFalloff glLightf(n, GL_LINEAR_ATTENUATION, linear) glLightf(n, GL_QUADRATIC_ATTENUATION, quadratic) glLightf(n, GL_CONSTANT_ATTENUATION, constant) glEnable(n)
def pointLight(v1, v2, v3, x, y, z): """Adds a point light (diffuse/specular) with the given color and position.""" _lightsOn() color = _getColor(v1, v2, v3) n = GL_LIGHT0 + attrib.lightCount attrib.lightCount += 1 glLightfv(n, GL_DIFFUSE, (ctypes.c_float * 4)(*color)) glLightfv(n, GL_AMBIENT, (ctypes.c_float * 3)(0, 0, 0)) glLightfv(n, GL_SPECULAR, (ctypes.c_float * 4)(*attrib.lightSpecular)) glLightfv(n, GL_POSITION, (ctypes.c_float * 4)(x, y, z, 1)) glLightfv(n, GL_SPOT_DIRECTION, (ctypes.c_float * 3)(0, 0, -1)) glLightf(n, GL_SPOT_EXPONENT, 0) glLightf(n, GL_SPOT_CUTOFF, 180) constant, linear, quadratic = attrib.lightFalloff glLightf(n, GL_LINEAR_ATTENUATION, linear) glLightf(n, GL_QUADRATIC_ATTENUATION, quadratic) glLightf(n, GL_CONSTANT_ATTENUATION, constant) glEnable(n)
def spotLight(v1, v2, v3, x, y, z, nx, ny, nz, angle, concentration): """Adds a spot light source.""" _lightsOn() color = _getColor(v1, v2, v3) n = GL_LIGHT0 + attrib.lightCount attrib.lightCount += 1 glLightfv(n, GL_DIFFUSE, (ctypes.c_float * 4)(*color)) glLightfv(n, GL_AMBIENT, (ctypes.c_float * 3)(0, 0, 0)) glLightfv(n, GL_SPECULAR, (ctypes.c_float * 3)(0, 0, 0)) glLightfv(n, GL_POSITION, (ctypes.c_float * 4)(x, y, z, 1)) glLightfv(n, GL_SPOT_DIRECTION, (ctypes.c_float * 3)(nx, ny, nz)) glLightf(n, GL_SPOT_EXPONENT, concentration) glLightf(n, GL_SPOT_CUTOFF, math.degrees(angle)) constant, linear, quadratic = attrib.lightFalloff glLightf(n, GL_LINEAR_ATTENUATION, linear) glLightf(n, GL_QUADRATIC_ATTENUATION, quadratic) glLightf(n, GL_CONSTANT_ATTENUATION, constant) glEnable(n)
def ambient(*args): """Ambient reflection material properties.""" color = _getColor(*args) glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, (ctypes.c_float * 4)(*color))
def specular(*args): """Specular reflection material properties.""" color = _getColor(*args) glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, (ctypes.c_float * 4)(*color))
def emissive(*args): """Emission material Properties""" color = _getColor(*args) glMaterialfv (GL_FRONT_AND_BACK, GL_EMISSION, (ctypes.c_float * 4)(*color))
def tint(*color): """Sets color as a tint for drawing images.""" attrib.tintColor = _getColor(*color)
def fill(*color): """Sets color as color for drawing filled shapes.""" attrib.fillColor = _getColor(*color)
def stroke(*color): """Sets color as color for drawing lines and shape borders.""" attrib.strokeColor = _getColor(*color)
def emissive(*args): """Emission material Properties""" color = _getColor(*args) glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (ctypes.c_float * 4)(*color))
def specular(*args): """Specular reflection material properties.""" color = _getColor(*args) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (ctypes.c_float * 4)(*color))
def lightSpecular(v1, v2, v3): """Sets the specular coefficients for light sources defined afterwards.""" attrib.lightSpecular = _getColor(v1, v2, v3)
def ambient(*args): """Ambient reflection material properties.""" color = _getColor(*args) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (ctypes.c_float * 4)(*color))
def lightSpecular (v1,v2,v3): """Sets the specular coefficients for light sources defined afterwards.""" attrib.lightSpecular = _getColor(v1,v2,v3)