Example #1
0
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)
Example #2
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)
Example #3
0
File: pimage.py Project: msarch/py
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)
Example #4
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)
Example #5
0
File: lights.py Project: msarch/py
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)
Example #6
0
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)
Example #7
0
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)
Example #8
0
File: lights.py Project: msarch/py
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)
Example #9
0
File: lights.py Project: msarch/py
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)
Example #10
0
def ambient(*args):
    """Ambient reflection material properties."""
    color = _getColor(*args)
    glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, (ctypes.c_float * 4)(*color))    
Example #11
0
def specular(*args):
    """Specular reflection material properties."""
    color = _getColor(*args)
    glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, (ctypes.c_float * 4)(*color))
Example #12
0
def emissive(*args):
    """Emission material Properties"""
    color = _getColor(*args)
    glMaterialfv (GL_FRONT_AND_BACK, GL_EMISSION, (ctypes.c_float * 4)(*color)) 
Example #13
0
def tint(*color):
    """Sets color as a tint for drawing images."""
    attrib.tintColor = _getColor(*color)
Example #14
0
def fill(*color):
    """Sets color as color for drawing filled shapes."""
    attrib.fillColor = _getColor(*color)
Example #15
0
def stroke(*color):
    """Sets color as color for drawing lines and shape borders."""
    attrib.strokeColor = _getColor(*color)
Example #16
0
def tint(*color):
    """Sets color as a tint for drawing images."""
    attrib.tintColor = _getColor(*color)
Example #17
0
def fill(*color):
    """Sets color as color for drawing filled shapes."""
    attrib.fillColor = _getColor(*color)
Example #18
0
def stroke(*color):
    """Sets color as color for drawing lines and shape borders."""
    attrib.strokeColor = _getColor(*color)
Example #19
0
def emissive(*args):
    """Emission material Properties"""
    color = _getColor(*args)
    glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (ctypes.c_float * 4)(*color))
Example #20
0
def specular(*args):
    """Specular reflection material properties."""
    color = _getColor(*args)
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (ctypes.c_float * 4)(*color))
Example #21
0
File: lights.py Project: msarch/py
def lightSpecular(v1, v2, v3):
    """Sets the specular coefficients for light sources defined afterwards."""
    attrib.lightSpecular = _getColor(v1, v2, v3)
Example #22
0
def ambient(*args):
    """Ambient reflection material properties."""
    color = _getColor(*args)
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (ctypes.c_float * 4)(*color))
Example #23
0
def lightSpecular (v1,v2,v3):
    """Sets the specular coefficients for light sources defined afterwards."""
    attrib.lightSpecular = _getColor(v1,v2,v3)