Example #1
0
def draw_text_2d(text, x, y, line_height=17, color=None):
    """Draw a text at a given 2D position.

    A very basic 2D drawing function for drawing (multi-line) text."
    """
    width = glutGet(GLUT_WINDOW_WIDTH)
    height = glutGet(GLUT_WINDOW_HEIGHT)

    glMatrixMode(GL_PROJECTION)
    glPushMatrix()  #matrix = glGetDouble( GL_PROJECTION_MATRIX )
    glLoadIdentity()
    glOrtho(0.0, width, 0.0, height, -1.0, 1.0)
    glMatrixMode(GL_MODELVIEW)
    glPushMatrix()
    glLoadIdentity()
    if color:
        glColor3f(*color)
    glRasterPos2i(x, y)
    lines = 0
    for character in text:
        if character == '\n':
            lines += 1
            glRasterPos(x, y - (lines * line_height))
        else:
            glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ord(character))
    glPopMatrix()
    glMatrixMode(GL_PROJECTION)
    glPopMatrix()  #glLoadMatrixd(matrix)
    glMatrixMode(GL_MODELVIEW)
def _draw_text(font, input_str, x, y, line_height=16, r=1.0, g=1.0, b=1.0):
    """Render text based on window position. The origin is in the bottom-left."""
    glColor3f(r, g, b)
    glWindowPos2f(x, y)
    input_list = input_str.split('\n')
    y = y + (line_height * (len(input_list) - 1))
    for line in input_list:
        glWindowPos2f(x, y)
        y -= line_height
        for ch in line:
            glutBitmapCharacter(font, ctypes.c_int(ord(ch)))
Example #3
0
File: text.py Project: reims/wesen
 def Print(self, text):
     """Print(String text) prints text to the screen"""
     glPushMatrix()
     glTranslatef(0.02, 0.96, 0.0) # TODO where does the magic number come from?
     for character in text:
         if(character == "\n"):
             self.rasterPos -= self.y
             glRasterPos(0, self.rasterPos)
         else:
             glutBitmapCharacter(GLUT_BITMAP_8_BY_13,
                                 ord(character))
     glPopMatrix()
Example #4
0
def draw_text_3d(text, x, y, z, color=None):
    """Draw a text at a given 3D position.

    A very basic 3D drawing function for displaying text in a 3D scene.
    The multi-line support is experimental.
    """
    if color:
        glColor3f(*color)
    glRasterPos(x, y, z)
    for character in text:
        if character == '\n':
            glRasterPos(x, y, z - 15)
        else:
            glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ord(character))
Example #5
0
    def _text_(self, text, offs, stroke=False, color=None):
        '''
        '''

        if stroke:
            font = GLUT_STROKE_ROMAN

            glutStrokeWidth(font, 50)
            for c in text:
                glutStrokeCharacter(font, ord(c))
        else:
            glDisable(GL_LIGHTING)
            co = color if (color and (isinstance(color, tuple) or isinstance(color, list))) else (0, 1, 0)

            glColor3f(*co)
            font = GLUT_BITMAP_HELVETICA_18
            glRasterPos2f(*offs)
            for c in text:
                glutBitmapCharacter(font, ord(c))
            glEnable(GL_LIGHTING)
Example #6
0
    def render(self):
        if self.blend < 1:
            glColor3fv((1, 0, 0))  # dark grey this one
        else:
            glColor3fv(self.textcolors[0])  #

        # marquee
        glPushMatrix()
        glEnable(GL_LINE_STIPPLE)
        glLineStipple(
            1, 0x1111)  # 0x0101 dotted # 0x00FF  dashed #0x1C47  dash/dot/dash
        glTranslatef(self.x, self.y, -self.z)  # translate to GL loc ppint
        glLineWidth(1)
        glBegin(GL_LINE_LOOP)
        glVertex2f(-self.width2, -self.height2)
        glVertex2f(self.width2, -self.height2)
        glVertex2f(self.width2, self.height2)
        glVertex2f(-self.width2, self.height2)
        glEnd()
        glDisable(GL_LINE_STIPPLE)
        glPopMatrix()

        bgleft = self.x - self.width2  # display's marquee left side
        w = (self.limits[1] - self.limits[0] +
             1) * 0.5  # half width of color area
        x = bgleft + self.limits[0] + w  # x loc of color rect

        # colored selection area #
        glColor4fv(self.forecolor)  # black?
        glPushMatrix()
        glTranslatef(x, self.y, -self.z)  # translate to GL loc ppint
        glRectf(-w, -self.height2 + 1, w, self.height2)
        glPopMatrix()

        # marquee
        self.playhead = (self.app.loopers[self.z].pos * self.width) + bgleft

        # reference line
        glColor4fv(self.forecolor)
        glPushMatrix()
        glTranslatef(x, 0, -self.z)  # translate to GL loc ppint
        glLineWidth(1)
        glEnable(GL_LINE_STIPPLE)
        glLineStipple(1, 0xF0F0)
        glBegin(GL_LINES)
        glVertex2f(-w, 0)  # line ends
        glVertex2f(-w, self.app.height)
        glVertex2f(w, 0)  # line ends
        glVertex2f(w, self.app.height)
        glEnd()
        glDisable(GL_LINE_STIPPLE)
        glPopMatrix()

        # playhead line
        glColor4fv(
            (1, 0, 0, 1))  ### EVERYTHING below goes red but normal volume ###
        glPushMatrix()
        glTranslatef(self.playhead, self.y,
                     -self.z)  # translate to GL loc ppint
        glLineWidth(1)
        glBegin(GL_LINES)
        glVertex2f(0, self.height2)  # line ends
        glVertex2f(0, -self.height2)
        glEnd()
        glPopMatrix()

        # red mark # already drawing red at this point
        if self.selected:  # mark as selected
            glPushMatrix()
            glTranslatef(20, self.y, -self.z)
            glRectf(-7, -7, 7, 7)
            glPopMatrix()

        # amp/MUTED label #
        if self.blend < 1:
            glColor3fv((1, 0, 0))  # dark grey this one
            txt = 'MUTED'
        else:
            txt = ''

        glRasterPos3f(self.left + 25, self.top + 13, -self.z)

        for c in txt:
            glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ord(c))
Example #7
0
 def DrawString(self, s='', f=None):
     if f is None: f = GLUT_BITMAP_HELVETICA_12
     for c in s:
         glutBitmapCharacter(f, ord(c))
Example #8
0
 def draw_string(x, y, string):
     glWindowPos2i(x, y)
     for c in string:
         glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ord(c))
Example #9
0
 def DrawString(self, s='', f=None):
   if f is None: f = GLUT_BITMAP_HELVETICA_12
   for c in s: glutBitmapCharacter(f, ord(c))
 def renderizar_texto(self, texto, posicao_texto, fonte, cor=(1., 1., 1.)):
     # glColor(*cor)
     glRasterPos2f(*posicao_texto)
     for char in texto:
         glutBitmapCharacter(fonte, ord(char))
Example #11
0
    def draw(self):
        """
        Draw this menu on the screen.
        """
        from OpenGL.GL import glRasterPos2f
        from OpenGL.GLUT import glutBitmapCharacter, GLUT_BITMAP_HELVETICA_18

        view = glGetInteger(GL_VIEWPORT)

        # Switch to an orthogonal projection for drawing the menu.
        glDisable(GL_LIGHTING)
        glDisable(GL_DEPTH_TEST)
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()

        # Height and width of the viewport.
        vheight = view[3] - view[1]
        vwidth = view[2] - view[0]

        right = 100.0
        top = float(vheight) / float(vwidth) * right
        glOrtho(0.0, right, 0.0, top, 0.0, 1.0)

        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        gluLookAt(0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
        # glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glEnable(GL_BLEND)
        glEnable(GL_LINE_SMOOTH)
        glEnable(GL_POLYGON_SMOOTH)

        #
        # Draw the background box
        #
        nopts = len(self.opts)

        # Constants used to size the menu elements.
        ratio = right / vwidth

        charRise = 22 * ratio
        charFall = 8 * ratio
        charWidth = 12 * ratio

        vmargin = 10 * ratio
        hmargin = 20 * ratio

        #
        itemHeight = charRise + charFall + vmargin
        if self.opts:
            # Include the length of the title in maxChars so that
            # the menu is never narrower than the title.
            maxChars = max([len(s) for s in self.opts + (self.title,)])
            totalHeight = itemHeight * len(self.opts) + vmargin
        else:
            maxChars = len(self.title)
            totalHeight = itemHeight + vmargin
        width = charWidth * maxChars + hmargin * 2.0
        titleWidth = charWidth * len(self.title) + hmargin * 2.0

        glColor4f(*self.bgColor)
        glPushMatrix()
        # Translate into the center of the display.
        glTranslatef(50.0, top / 2.0, 0.0)

        # Now translate this whole figure so that it's centered.
        glTranslatef(width / -2.0, totalHeight / -2.0, 0.0)
        glBegin(GL_QUADS)
        glVertex3f(0.0, 0.0, 0.0)
        glVertex3f(width, 0.0, 0.0)
        glVertex3f(width, totalHeight, 0.0)
        glVertex3f(0.0, totalHeight, 0.0)
        glEnd()

        glPushMatrix()
        glColor4f(*self.fgColor)
        glTranslatef(0.0, totalHeight, 0.0)
        # Draw the background for the title.
        glBegin(GL_QUADS)
        glVertex3f(0.0, 0.0, 0.0)
        glVertex3f(titleWidth, 0.0, 0.0)
        glVertex3f(titleWidth, itemHeight, 0.0)
        glVertex3f(0.0, itemHeight, 0.0)
        glEnd()
        glPopMatrix()

        #
        # Draw the selection frame for the currently selected item
        #
        glColor4f(*self.selColor)

        # push is 1/2 the linewidth
        glPushMatrix()
        glTranslatef(0.0, itemHeight * (nopts - self.selection - 1) + vmargin / 2.0, 0.0)
        glBegin(GL_QUADS)
        glVertex3f(hmargin / 4.0, vmargin / 4.0, 0.0)
        glVertex3f(width - hmargin / 4.0, vmargin / 4.0, 0.0)
        glVertex3f(width - hmargin / 4.0, itemHeight - vmargin / 4.0, 0.0)
        glVertex3f(hmargin / 4.0, itemHeight - vmargin / 4.0, 0.0)
        glEnd()
        glPopMatrix()

        #
        # Draw the menu items
        #

        # Translate into position for the last item.
        glTranslatef(hmargin, charFall + vmargin, 0.0)

        # Draw items, moving up as we go
        for i in range(nopts - 1, -1, -1):
            glPushMatrix()
            glColor4f(*self.fgColor)

            glRasterPos2f(0, 0)
            for c in self.opts[i]:
                glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(c))
            glPopMatrix()
            glTranslatef(0.0, itemHeight, 0.0)


        #
        # Draw the menu title.
        #

        glTranslatef(0.0, vmargin / 2.0, 0.0)
        glColor4f(*self.bgColor)
        glRasterPos2f(0, 0)
        for c in self.title:
            glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(c))

        glPopMatrix()
        #
        # end draw
        #
        glPopMatrix()
        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        glEnable(GL_LIGHTING)
        glEnable(GL_DEPTH_TEST)
Example #12
0
    def render(self) : 
        if self.blend < 1:
            glColor3fv( (1,0,0) ) # dark grey this one
        else :
            glColor3fv(self.textcolors[0]) # 
        
        # marquee
        glPushMatrix()
        glEnable(GL_LINE_STIPPLE)
        glLineStipple(1, 0x1111) # 0x0101 dotted # 0x00FF  dashed #0x1C47  dash/dot/dash
        glTranslatef(self.x, self.y, -self.z) # translate to GL loc ppint 	 
        glLineWidth(1) 	 
        glBegin(GL_LINE_LOOP) 	 
        glVertex2f(-self.width2, -self.height2) 	 
        glVertex2f(self.width2, -self.height2) 	 
        glVertex2f(self.width2, self.height2) 	 
        glVertex2f(-self.width2, self.height2) 	 
        glEnd()
        glDisable(GL_LINE_STIPPLE)
        glPopMatrix()

        bgleft = self.x - self.width2  # display's marquee left side
        w = (self.limits[1] - self.limits[0] + 1)*0.5 # half width of color area
        x = bgleft + self.limits[0] + w # x loc of color rect
        
        # colored selection area #
        glColor4fv(self.forecolor) # black? 
        glPushMatrix()
        glTranslatef(x, self.y, -self.z) # translate to GL loc ppint
        glRectf(-w, -self.height2+1, w, self.height2)
        glPopMatrix()

        # marquee
        self.playhead = (self.app.loopers[self.z].pos * self.width) + bgleft

        # reference line
        glColor4fv( self.forecolor ) 
        glPushMatrix()
        glTranslatef( x, 0, -self.z ) # translate to GL loc ppint
        glLineWidth(1)
        glEnable(GL_LINE_STIPPLE)
        glLineStipple(1, 0xF0F0)
        glBegin(GL_LINES)
        glVertex2f( -w, 0) # line ends
        glVertex2f( -w, self.app.height )
        glVertex2f( w, 0) # line ends
        glVertex2f( w, self.app.height )
        glEnd()
        glDisable(GL_LINE_STIPPLE)
        glPopMatrix()
        
        # playhead line
        glColor4fv( (1,0,0,1) ) ### EVERYTHING below goes red but normal volume ###
        glPushMatrix()
        glTranslatef( self.playhead, self.y, -self.z ) # translate to GL loc ppint
        glLineWidth(1)
        glBegin(GL_LINES)
        glVertex2f( 0, self.height2 ) # line ends
        glVertex2f( 0, -self.height2 )
        glEnd()
        glPopMatrix()

        # red mark # already drawing red at this point
        if self.selected : # mark as selected
            glPushMatrix()
            glTranslatef(20, self.y, -self.z)
            glRectf(-7,-7,7,7)
            glPopMatrix()

        # amp/MUTED label #
        if self.blend < 1:
            glColor3fv( (1,0,0) ) # dark grey this one
            txt ='MUTED' 
        else :
            txt = ''

        glRasterPos3f(self.left + 25, self.top + 13, -self.z)
        
        for c in txt : 
            glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ord(c))
Example #13
0
 def draw_string(x, y, string):
     glWindowPos2i(x, y)
     for c in string:
         glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ord(c))