Exemple #1
0
def rect(rectstyle, color, width=0, alpha=255.0):
    """Draw a rect <- return None
    """
   
    x, y, w, h = rectstyle
    points = [[x, y], [x+w, y], [x+w, y+h], [x, y+h]]
    points = flip_points(points)
    offset = window.get_size()[1]
    if not width:
        polygon(points, color, aa=False, alpha=alpha)
    else:
        lines(points, color, width=width, aa=False, alpha=alpha, closed=1)
Exemple #2
0
    def __init__(self, filename, filters=[FILTER]):
        """Load an image for drawing. <- return None
        """
        
        #load pygame image
        if type("") is type(filename):
            image = pygame.image.load(filename)
        else:
            image = filename
        self.image = image
        
	texSize=glGetIntegerv ( GL_MAX_TEXTURE_SIZE)
	oldH= image.get_height()
	oldW= image.get_width()
	image2=resize(image,texSize)
	newH= image2.get_height()
	newW= image2.get_width()
	fracH=oldH/float(newH)
	fracW=oldW/float(newW)

        #convert to GL texture
        self.texture = Texture(image2, filters)
        
        #image dimensions
        self.width = self.w = image.get_width()
        self.height = self.h = image.get_height()
        self.size = image.get_size()
   
        self.win_size = window.get_size()
                   
            
        #image mods
        self.rotation = 0
        self.scalar = 1.0
        self.color = [1.0, 1.0, 1.0, 1.0]
        self.ox, self.oy = self.image.get_width()/2, self.image.get_height()/2
        
        #crazy gl stuff :)
        self.dl = glGenLists(1)
        glNewList(self.dl, GL_COMPILE)
        glBindTexture(GL_TEXTURE_2D, self.texture)
        glBegin(GL_QUADS)
        glTexCoord2f(0, 1-fracH); glVertex3f(-self.width/2.0,-self.height/2.0,0)
        glTexCoord2f(fracW, 1-fracH); glVertex3f( self.width/2.0,-self.height/2.0,0)
        glTexCoord2f(fracW, 1.0); glVertex3f( self.width/2.0, self.height/2.0,0)
        glTexCoord2f(0, 1.0); glVertex3f(-self.width/2.0, self.height/2.0,0)
        glEnd()
        glEndList()
Exemple #3
0
def line(point1, point2, color, width=1, aa=True, alpha=255.0):
    """Draw a line from point1 to point2 <- return None
    """
    
    glLineWidth(width)
    if aa:
        glEnable(GL_LINE_SMOOTH)
    glDisable(GL_TEXTURE_2D)
    glColor4f(color[0]/255.0, color[1]/255.0, color[2]/255.0, alpha/255.0)
    glBegin(GL_LINE_STRIP)
    offset = window.get_size()[1]
    glVertex3f(point1[0], offset - point1[1], 0)
    glVertex3f(point2[0], offset - point2[1], 0)
    glEnd()
    glColor3f(1.0,1.0,1.0)
    glEnable(GL_TEXTURE_2D)
Exemple #4
0
def polygon(points, color, aa=True, alpha=255.0):
    """Draw a filled polygon <- return None
    """
    
    glDisable(GL_TEXTURE_2D)
    if aa:
        glEnable(GL_POLYGON_SMOOTH)
    glBegin(GL_POLYGON)
    glColor4f(color[0]/255.0, color[1]/255.0, color[2]/255.0, alpha/255.0)
    offset = window.get_size()[1]
    points = flip_points(points)
    for p in points:
        glVertex3f(p[0], offset - p[1], 0)
    glEnd()
    glColor3f(1.0,1.0,1.0)
    glDisable(GL_POLYGON_SMOOTH)
    glEnable(GL_TEXTURE_2D)
Exemple #5
0
def lines(points, color, width=1, aa=True, closed=0, alpha=255.0):
    """Draws a series of lines <- return None
    """
    
    glLineWidth(width)
    if aa:
        glEnable(GL_LINE_SMOOTH)
    glDisable(GL_TEXTURE_2D)
    glBegin(GL_LINE_STRIP)
    glColor4f(color[0]/255.0, color[1]/255.0, color[2]/255.0, alpha/255.0)
    offset = window.get_size()[1]
    points = flip_points(points)
    for p in points:
        glVertex3f(p[0], offset - p[1], 0)
    if closed:
        glVertex3f(points[0][0], offset - points[0][1], 0)
    glEnd()
    glColor3f(1.0,1.0,1.0)
    glDisable(GL_LINE_SMOOTH)
    glEnable(GL_TEXTURE_2D)