Ejemplo n.º 1
0
def get_gl_info_string(glpane): # grantham 20051129
    """Return a string containing some useful information about the OpenGL
    implementation.

    Use the GL context from the given QGLWidget glpane (by calling
    glpane.makeCurrent()).
    """

    glpane.makeCurrent() #bruce 070308 added glpane arg and makeCurrent call

    gl_info_string = ''

    gl_info_string += 'GL_VENDOR : "%s"\n' % glGetString(GL_VENDOR)
    gl_info_string += 'GL_VERSION : "%s"\n' % glGetString(GL_VERSION)
    gl_info_string += 'GL_RENDERER : "%s"\n' % glGetString(GL_RENDERER)
    gl_info_string += 'GL_EXTENSIONS : "%s"\n' % glGetString(GL_EXTENSIONS)

    from utilities.debug_prefs import debug_pref, Choice_boolean_False
    if debug_pref("get_gl_info_string call glAreTexturesResident?",
                  Choice_boolean_False):
        # Give a practical indication of how much video memory is available.
        # Should also do this with VBOs.

        # I'm pretty sure this code is right, but PyOpenGL seg faults in
        # glAreTexturesResident, so it's disabled until I can figure that
        # out. [grantham] [bruce 070308 added the debug_pref]

        all_tex_in = True
        tex_bytes = '\0' * (512 * 512 * 4)
        tex_names = []
        tex_count = 0
        tex_names = glGenTextures(1024)
        glEnable(GL_TEXTURE_2D)
        while all_tex_in:
            glBindTexture(GL_TEXTURE_2D, tex_names[tex_count])
            gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 512, 512, GL_RGBA,
                              GL_UNSIGNED_BYTE, tex_bytes)
            tex_count += 1

            glTexCoord2f(0.0, 0.0)
            glBegin(GL_QUADS)
            glVertex2f(0.0, 0.0)
            glVertex2f(1.0, 0.0)
            glVertex2f(1.0, 1.0)
            glVertex2f(0.0, 1.0)
            glEnd()
            glFinish()

            residences = glAreTexturesResident(tex_names[:tex_count])
            all_tex_in = reduce(lambda a,b: a and b, residences)
                # bruce 070308 sees this exception from this line:
                # TypeError: reduce() arg 2 must support iteration

        glDisable(GL_TEXTURE_2D)
        glDeleteTextures(tex_names)

        gl_info_string += "Could create %d 512x512 RGBA resident textures\n" \
                          % tex_count
    return gl_info_string
Ejemplo n.º 2
0
def get_gl_info_string(glpane):  # grantham 20051129
    """Return a string containing some useful information about the OpenGL
    implementation.

    Use the GL context from the given QGLWidget glpane (by calling
    glpane.makeCurrent()).
    """

    glpane.makeCurrent()  #bruce 070308 added glpane arg and makeCurrent call

    gl_info_string = ''

    gl_info_string += 'GL_VENDOR : "%s"\n' % glGetString(GL_VENDOR)
    gl_info_string += 'GL_VERSION : "%s"\n' % glGetString(GL_VERSION)
    gl_info_string += 'GL_RENDERER : "%s"\n' % glGetString(GL_RENDERER)
    gl_info_string += 'GL_EXTENSIONS : "%s"\n' % glGetString(GL_EXTENSIONS)

    from utilities.debug_prefs import debug_pref, Choice_boolean_False
    if debug_pref("get_gl_info_string call glAreTexturesResident?",
                  Choice_boolean_False):
        # Give a practical indication of how much video memory is available.
        # Should also do this with VBOs.

        # I'm pretty sure this code is right, but PyOpenGL seg faults in
        # glAreTexturesResident, so it's disabled until I can figure that
        # out. [grantham] [bruce 070308 added the debug_pref]

        all_tex_in = True
        tex_bytes = '\0' * (512 * 512 * 4)
        tex_names = []
        tex_count = 0
        tex_names = glGenTextures(1024)
        glEnable(GL_TEXTURE_2D)
        while all_tex_in:
            glBindTexture(GL_TEXTURE_2D, tex_names[tex_count])
            gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 512, 512, GL_RGBA,
                              GL_UNSIGNED_BYTE, tex_bytes)
            tex_count += 1

            glTexCoord2f(0.0, 0.0)
            glBegin(GL_QUADS)
            glVertex2f(0.0, 0.0)
            glVertex2f(1.0, 0.0)
            glVertex2f(1.0, 1.0)
            glVertex2f(0.0, 1.0)
            glEnd()
            glFinish()

            residences = glAreTexturesResident(tex_names[:tex_count])
            all_tex_in = reduce(lambda a, b: a and b, residences)
            # bruce 070308 sees this exception from this line:
            # TypeError: reduce() arg 2 must support iteration

        glDisable(GL_TEXTURE_2D)
        glDeleteTextures(tex_names)

        gl_info_string += "Could create %d 512x512 RGBA resident textures\n" \
                          % tex_count
    return gl_info_string
Ejemplo n.º 3
0
Archivo: draw.py Proyecto: Zildj1an/bui
def draw_textured_quad(coords):
    tex_coords = ((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0))
    
    with mode(GL_QUADS):
        for i in range(4):
            tex_x = tex_coords[i][0]
            tex_y = tex_coords[i][1]
            glTexCoord2f(tex_x, tex_y)
            
            x = coords[i][0]
            y = coords[i][1]
            glVertex2f(x, y)
Ejemplo n.º 4
0
    def _draw_zero_plane_xy(self, color, texture_id=None, scale=1.0):
        glPushMatrix()
        # glColor3f(*rgb_to_f(*color))
        apply_texture = texture_id is not None
        if apply_texture:
            glColor3f(1, 1, 1)
            glBindTexture(GL_TEXTURE_2D, self._textures[texture_id])
            glTexCoord2f(1.0 * scale, 0.0 * scale)
        else:
            glColor3f(*rgb_to_f(*color))
        glBegin(GL_POLYGON)
        size = self._size / 2

        glVertex3f(size, size, 0)
        if apply_texture:
            glTexCoord2f(1.0 * scale, 1.0 * scale)
        glVertex3f(size, -size, 0)
        if apply_texture:
            glTexCoord2f(0.0 * scale, 1.0 * scale)
        glVertex3f(-size, -size, 0)
        if apply_texture:
            glTexCoord2f(0.0 * scale, 0.0 * scale)
        glVertex3f(-size, size, 0)
        # if texture is not None:
        #     glBindTexture(GL_TEXTURE_2D, )
        glEnd()
        glPopMatrix()
Ejemplo n.º 5
0
    def render(self, viewBox):
        if not self.intersectsBox(viewBox):
            return
        if self.shouldRefresh:
            self.refresh()
            self.shouldRefresh = False
        
        glColor3f(1, 1, 1)

        img = self.textureData
        pic_ny, pic_nx = img.shape
        tex_nx,tex_ny = getTexSize(pic_nx,pic_ny)
        picTexRatio_x = float(pic_nx) / tex_nx
        picTexRatio_y = float(pic_ny) / tex_ny

        (x,y) = self.pos[:2]

        glBindTexture(GL_TEXTURE_2D, self.texture)
        glBegin(GL_QUADS)
        glTexCoord2f(0, picTexRatio_y)
        glVertex2f(x, y)
        glTexCoord2f(picTexRatio_x, picTexRatio_y)
        glVertex2f(x + self.size[0], y)
        glTexCoord2f(picTexRatio_x, 0)
        glVertex2f(x + self.size[0], y + self.size[1])
        glTexCoord2f(0, 0)
        glVertex2f(x, y + self.size[1])
        glEnd()
Ejemplo n.º 6
0
    def drawTexture(self, texture, dx, dy, dw, dh, x, y, w, h, r):
        '''
		texture is an int
		textureRect is a list of size 4, determines which square to take from the texture
		drawRect is a list of size 4, is used to determine the drawing size
		'''

        glBindTexture(self.texext, texture)

        glPushMatrix()
        glTranslatef(dx + dw / 2, dy + dh / 2, 0)
        glRotatef(r, 0, 0, 1.0)
        glTranslatef(-1 * (dx + dw / 2), -1 * (dy + dh / 2), 0)

        glBegin(GL_QUADS)
        #Top-left vertex (corner)
        glTexCoord2f(x, y + h)  #image/texture
        glVertex3f(dx, dy, 0)  #screen coordinates

        #Bottom-left vertex (corner)
        glTexCoord2f(x + w, y + h)
        glVertex3f((dx + dw), dy, 0)

        #Bottom-right vertex (corner)
        glTexCoord2f(x + w, y)
        glVertex3f((dx + dw), (dy + dh), 0)

        #Top-right vertex (corner)
        glTexCoord2f(x, y)
        glVertex3f(dx, (dy + dh), 0)
        glEnd()

        glPopMatrix()
Ejemplo n.º 7
0
def copy_pixels(tox, toy, w, h, fromx, fromy):
    glEnable(GL_TEXTURE_2D)
    glBegin(GL_QUADS)
    glTexCoord2f(fromx, fromy)
    glVertex2f(tox, toy)
    glTexCoord2f(fromx+w, fromy)
    glVertex2f(tox+w, toy)
    glTexCoord2f(fromx+w, fromy+h)
    glVertex2f(tox+w, toy+h)
    glTexCoord2f(fromx, fromy+h)
    glVertex2f(tox, toy+h)
    glEnd()
    glDisable(GL_TEXTURE_2D)
Ejemplo n.º 8
0
def copy_pixels(tox, toy, w, h, fromx, fromy):
    glEnable(GL_TEXTURE_2D)
    glBegin(GL_QUADS)
    glTexCoord2f(fromx, fromy)
    glVertex2f(tox, toy)
    glTexCoord2f(fromx + w, fromy)
    glVertex2f(tox + w, toy)
    glTexCoord2f(fromx + w, fromy + h)
    glVertex2f(tox + w, toy + h)
    glTexCoord2f(fromx, fromy + h)
    glVertex2f(tox, toy + h)
    glEnd()
    glDisable(GL_TEXTURE_2D)
Ejemplo n.º 9
0
	def _drawQuad(self, tex_offset):
		extent = self.extent
		y = self.seaLevel
		max_tex = 50.0+tex_offset
		glBegin(GL_QUADS)
		glTexCoord2f( 0.0+tex_offset, 0.0+tex_offset )
		glVertex3f( 0.0, y, 0.0 )
		glTexCoord2f( max_tex, 0.0+tex_offset )
		glVertex3f( extent, y, 0.0 )
		glTexCoord2f( max_tex, max_tex )
		glVertex3f( extent, y, extent )
		glTexCoord2f( 0.0+tex_offset, max_tex )
		glVertex3f( 0.0, y, extent )
		glEnd()
Ejemplo n.º 10
0
 def _drawQuad(self, tex_offset):
     extent = self.extent
     y = self.seaLevel
     max_tex = 50.0 + tex_offset
     glBegin(GL_QUADS)
     glTexCoord2f(0.0 + tex_offset, 0.0 + tex_offset)
     glVertex3f(0.0, y, 0.0)
     glTexCoord2f(max_tex, 0.0 + tex_offset)
     glVertex3f(extent, y, 0.0)
     glTexCoord2f(max_tex, max_tex)
     glVertex3f(extent, y, extent)
     glTexCoord2f(0.0 + tex_offset, max_tex)
     glVertex3f(0.0, y, extent)
     glEnd()
Ejemplo n.º 11
0
    def orthogonalPass(self, debugShadows=False):
        """
        draw stuff in orthogonal projection.
        mainly the scene can be post processed here
        and some gui elements could be drawn.
        """

        ### DRAW THE SCENE ###

        # TODO: post shader magic !
        glUseProgram(0)

        # enable the scene texture
        # Note that texture unit 0 should be active now.
        glEnable(GL_TEXTURE_2D)
        glBindTexture(GL_TEXTURE_2D, self.sceneTexture.glID)
        # make sure texture matrix is set to identity
        glMatrixMode(GL_TEXTURE)
        glLoadIdentity()
        glMatrixMode(GL_MODELVIEW)

        glBegin(GL_QUADS)
        glTexCoord2f(0.0, 0.0)
        glVertex3f(0.0, 0.0, -1.0)
        glTexCoord2f(1.0, 0.0)
        glVertex3f(self.winSize[0], 0.0, -1.0)
        glTexCoord2f(1.0, 1.0)
        glVertex3f(self.winSize[0], self.winSize[1], -1.0)
        glTexCoord2f(0.0, 1.0)
        glVertex3f(0.0, self.winSize[1], -1.0)
        glEnd()

        ### DEBUG DRAWINGS ###

        # debug shadow maps
        if debugShadows:
            # draw the shadow maps
            self.visualizeDepthShader.enable()
            layerLoc = glGetUniformLocation(self.visualizeDepthShader.program, "layer")
            drawShadowMaps(self.lights, layerLoc)

            # reset viewport and reset to ffp
            glViewport(0, 0, self.winSize[0], self.winSize[1])
            glUseProgram(0)

        glBindTexture(GL_TEXTURE_2D, 0)
        glDisable(GL_TEXTURE_2D)

        GLApp.orthogonalPass(self)
Ejemplo n.º 12
0
def draw_picture(picture, x, y, width, height):
    glBindTexture(GL_TEXTURE_2D, textures[picture])
    glPushMatrix()
    glTranslatef(x, y, 0.0)
    glBegin(GL_QUADS)
    # Bottom Left Of The Texture and Quad:
    glTexCoord2f(0.0, 0.0)
    glVertex2f(0, 0)
    # Bottom Right Of The Texture and Quad:
    glTexCoord2f(1.0, 0.0)
    glVertex2f(width, 0)
    # Top Right Of The Texture and Quad:
    glTexCoord2f(1.0, 1.0)
    glVertex2f(width, height)
    # Top Left Of The Texture and Quad:
    glTexCoord2f(0.0, 1.0)
    glVertex2f(0, height)
    glEnd()
    glPopMatrix()
Ejemplo n.º 13
0
 def renderizar_cuad(self, x, y, ancho, alto):
     """Renderiza un cuadrado, se ingresan coordenadas para
     textura por defecto.
     x, y = posición (superior izquierda) del cuadrado
     ancho, alto = tamaño del cuadrado"""
     glBegin(GL_QUADS)
     # Arriba-Izquierda
     glTexCoord2f(0.0, 1.0)
     glVertex3f(x, y, 0.0)
     # Abajo-Izquirda
     glTexCoord2f(0.0, 0.0)
     glVertex3f(x, alto, 0.0)
     # Abajo-Derecha
     glTexCoord2f(1.0, 0.0)
     glVertex3f(ancho, alto, 0.0)
     # Arriba-Derecha
     glTexCoord2f(1.0, 1.0)
     glVertex3f(ancho, y, 0.0)
     glEnd()
Ejemplo n.º 14
0
def draw_picture(picture, x, y, width, height):
    glBindTexture(GL_TEXTURE_2D, textures[picture])
    glPushMatrix()
    glTranslatef(x, y, 0.0)
    glBegin(GL_QUADS)
    # Bottom Left Of The Texture and Quad:
    glTexCoord2f(0.0, 0.0)
    glVertex2f(0, 0)
    # Bottom Right Of The Texture and Quad:
    glTexCoord2f(1.0, 0.0)
    glVertex2f(width, 0)
    # Top Right Of The Texture and Quad:
    glTexCoord2f(1.0, 1.0)
    glVertex2f(width, height)
    # Top Left Of The Texture and Quad:
    glTexCoord2f(0.0, 1.0)
    glVertex2f(0, height)
    glEnd()
    glPopMatrix()
Ejemplo n.º 15
0
    def openglSetup(self):
        glClearColor(0.0, 0.0, 0.0, 0.0)
        glEnable(GL.GL_DEPTH_TEST) 
        glEnable(GL.GL_COLOR_MATERIAL)

        glViewport (0, 0, self.surf.get_width(), self.surf.get_height())
        glMatrixMode (GL.GL_PROJECTION)
        glLoadIdentity ()
        glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0)
        glMatrixMode (GL.GL_MODELVIEW)

        self.cardList = glGenLists(1)
        glNewList(self.cardList, GL.GL_COMPILE)
        glColor3f(1,1,1)
        with begin(GL.GL_QUADS):
            glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, -1.0,  0.0)
            glTexCoord2f(1.0, 1.0); glVertex3f( 1.0, -1.0,  0.0)
            glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, 1.0,  0.0)
            glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, 1.0,  0.0)
        glEndList()
Ejemplo n.º 16
0
    def render(self, pen: numpy.array) -> None:
        glBindTexture(GL_TEXTURE_2D, self._texture_id)

        left = pen[0] + self._bearing_x
        bottom = pen[1] + self._descender

        glBegin(GL_QUADS)
        glTexCoord2f(0, 0)
        glVertex2f(left, bottom)

        glTexCoord2f(1, 0)
        glVertex2f(left + self._width, bottom)

        glTexCoord2f(1, 1)
        glVertex2f(left + self._width, bottom + self._height)

        glTexCoord2f(0, 1)
        glVertex2f(left, bottom + self._height)

        glEnd()
Ejemplo n.º 17
0
 def drawTexture(self):
     """
     Renders the current context as a texture. 
     Precondition: OpenGL mode and OpenGL context active.
     """
     
     tx = self.rect.x()
     ty = self.rect.y()
     w = self.rect.width()
     h = self.rect.height()
     glBindTexture(GL_TEXTURE_2D, self.texture)
     glBegin(GL_QUADS)
     glTexCoord2f(0.0, 1.0)
     glVertex2f(tx, ty)
     glTexCoord2f(1.0, 1.0)
     glVertex2f(tx + w, ty)
     glTexCoord2f(1.0, 0.0)
     glVertex2f(tx + w, ty + h)
     glTexCoord2f(0.0, 0.0)
     glVertex2f(tx, ty + h)
     glEnd()
Ejemplo n.º 18
0
    def openglSetup(self):
        glClearColor(0.0, 0.0, 0.0, 0.0)
        glEnable(GL.GL_DEPTH_TEST)
        glEnable(GL.GL_COLOR_MATERIAL)

        glViewport(0, 0, self.surf.get_width(), self.surf.get_height())
        glMatrixMode(GL.GL_PROJECTION)
        glLoadIdentity()
        glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0)
        glMatrixMode(GL.GL_MODELVIEW)

        self.cardList = glGenLists(1)
        glNewList(self.cardList, GL.GL_COMPILE)
        glColor3f(1, 1, 1)
        with begin(GL.GL_QUADS):
            glTexCoord2f(0.0, 1.0)
            glVertex3f(-1.0, -1.0, 0.0)
            glTexCoord2f(1.0, 1.0)
            glVertex3f(1.0, -1.0, 0.0)
            glTexCoord2f(1.0, 0.0)
            glVertex3f(1.0, 1.0, 0.0)
            glTexCoord2f(0.0, 0.0)
            glVertex3f(-1.0, 1.0, 0.0)
        glEndList()
Ejemplo n.º 19
0
def draw_textured_square(w=None, h=None):
    """
    Draws a texture square of 2 x 2 size centered at 0, 0
    
    Make sure to call glEnable(GL_TEXTURE_RECTANGLE_ARB) first.

    :param w: width of the image in pixels
    :param h: height of the image in pixels
    """
    if w is None or h is None:
        glBegin(GL_QUADS)
        glTexCoord2f(0.0, 0.0)
        glVertex2f(-1.0, -1.0)  # Bottom Left Of The Texture and Quad
        glTexCoord2f(1.0, 0.0)
        glVertex2f(1.0, -1.0)  # Bottom Right Of The Texture and Quad
        glTexCoord2f(1.0, 1.0)
        glVertex2f(1.0, 1.0)  # Top Right Of The Texture and Quad
        glTexCoord2f(0.0, 1.0)
        glVertex2f(-1.0, 1.0)  # Top Left Of The Texture and Quad
        glEnd()
    else:
        glBegin(GL_QUADS)
        glTexCoord2f(0.0, 0.0)
        glVertex2f(-1.0, -1.0)  # Bottom Left
        glTexCoord2f(w, 0.0)
        glVertex2f(1.0, -1.0)  # Bottom Right
        glTexCoord2f(w, h)
        glVertex2f(1.0, 1.0)  # Top Right
        glTexCoord2f(0.0, h)
        glVertex2f(-1.0, 1.0)  # Top Left
        glEnd()
Ejemplo n.º 20
0
def get_gl_info_string(glpane): # grantham 20051129
    """
    Return a string containing some useful information about the OpenGL
    implementation.

    Use the GL context from the given QGLWidget glpane (by calling
    glpane.makeCurrent()).
    """

    glpane.makeCurrent() #bruce 070308 added glpane arg and makeCurrent call

    gl_info_string = ''

    gl_info_string += 'GL_VENDOR : "%s"\n' % glGetString(GL_VENDOR)
    gl_info_string += 'GL_VERSION : "%s"\n' % glGetString(GL_VERSION)
    gl_info_string += 'GL_RENDERER : "%s"\n' % glGetString(GL_RENDERER)
    gl_extensions = glGetString(GL_EXTENSIONS)
    gl_extensions = gl_extensions.strip()
    gl_extensions = gl_extensions.replace(" ", "\n* ")
    gl_info_string += 'GL_EXTENSIONS : \n* %s\n' % gl_extensions

    if debug_pref("Graphics Card Info: call glAreTexturesResident?",
                  Choice_boolean_False):
        # Give a practical indication of how much video memory is available.
        # Should also do this with VBOs.

        # I'm pretty sure this code is right, but PyOpenGL seg faults in
        # glAreTexturesResident, so it's disabled until I can figure that
        # out. [grantham] [bruce 070308 added the debug_pref]

        all_tex_in = True
        tex_bytes = '\0' * (512 * 512 * 4)
        tex_names = []
        tex_count = 0
        tex_names = glGenTextures(1024)
        glEnable(GL_TEXTURE_2D)
        while all_tex_in:
            glBindTexture(GL_TEXTURE_2D, tex_names[tex_count])
            gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 512, 512, GL_RGBA,
                              GL_UNSIGNED_BYTE, tex_bytes)
            tex_count += 1

            glTexCoord2f(0.0, 0.0)
            glBegin(GL_QUADS)
            glVertex2f(0.0, 0.0)
            glVertex2f(1.0, 0.0)
            glVertex2f(1.0, 1.0)
            glVertex2f(0.0, 1.0)
            glEnd()
            glFinish()

            residences = glAreTexturesResident(tex_names[:tex_count])
            all_tex_in = reduce(lambda a,b: a and b, residences)
                # bruce 070308 sees this exception from this line:
                # TypeError: reduce() arg 2 must support iteration

        glDisable(GL_TEXTURE_2D)
        glDeleteTextures(tex_names)

        gl_info_string += "Could create %d 512x512 RGBA resident textures\n" \
                          % tex_count
        pass

    if True: ## or could be a debug_pref("Graphics Card Info: get all GL_MAX symbols?")
        #bruce 090314 new feature
        import OpenGL.GL
        symbols = [x for x in dir(OpenGL.GL) if x.startswith('GL_MAX_')]
        symbols.sort()
        gl_info_string += '\n'
        for symbol in symbols:
            try:
                numeric_symbol = getattr(OpenGL.GL, symbol)
                intval = glGetInteger(numeric_symbol)
            except:
                # this happens to most symbols, not sure why
                if debug_flags.atom_debug:
                    print_compact_traceback( "%s = ??: " % symbol )
                        # overkill, only the exception itself matters
                    # typical output (on Bruce's MacBookPro, 090314):
                    ## GL_MAX_4D_TEXTURE_SIZE_SGIS = ??:
                    ## <type 'exceptions.KeyError'>:
                    ## ('Unknown specifier GL_MAX_4D_TEXTURE_SIZE_SGIS (33080)',
                    ##  'Failure in cConverter <OpenGL.converters.SizedOutput object at 0x1457fab0>',
                    ##  [GL_MAX_4D_TEXTURE_SIZE_SGIS], 1, <OpenGL.wrapper.glGetIntegerv object at 0x1458aa30>)
                    ## [graphics_card_info.py:122] [wrapper.py:676] [converters.py:195] [converters.py:234]
                    pass
                pass ## gl_info_string += "%s = ??\n" % symbol
            else:
                gl_info_string += "%s = %r\n" % (symbol, intval)
            continue
        pass

    return gl_info_string
Ejemplo n.º 21
0
def get_gl_info_string(glpane):  # grantham 20051129
    """
    Return a string containing some useful information about the OpenGL
    implementation.

    Use the GL context from the given QGLWidget glpane (by calling
    glpane.makeCurrent()).
    """

    glpane.makeCurrent()  #bruce 070308 added glpane arg and makeCurrent call

    gl_info_string = ''

    gl_info_string += 'GL_VENDOR : "%s"\n' % glGetString(GL_VENDOR)
    gl_info_string += 'GL_VERSION : "%s"\n' % glGetString(GL_VERSION)
    gl_info_string += 'GL_RENDERER : "%s"\n' % glGetString(GL_RENDERER)
    gl_extensions = glGetString(GL_EXTENSIONS)
    gl_extensions = gl_extensions.strip()
    gl_extensions = gl_extensions.replace(" ", "\n* ")
    gl_info_string += 'GL_EXTENSIONS : \n* %s\n' % gl_extensions

    if debug_pref("Graphics Card Info: call glAreTexturesResident?",
                  Choice_boolean_False):
        # Give a practical indication of how much video memory is available.
        # Should also do this with VBOs.

        # I'm pretty sure this code is right, but PyOpenGL seg faults in
        # glAreTexturesResident, so it's disabled until I can figure that
        # out. [grantham] [bruce 070308 added the debug_pref]

        all_tex_in = True
        tex_bytes = '\0' * (512 * 512 * 4)
        tex_names = []
        tex_count = 0
        tex_names = glGenTextures(1024)
        glEnable(GL_TEXTURE_2D)
        while all_tex_in:
            glBindTexture(GL_TEXTURE_2D, tex_names[tex_count])
            gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 512, 512, GL_RGBA,
                              GL_UNSIGNED_BYTE, tex_bytes)
            tex_count += 1

            glTexCoord2f(0.0, 0.0)
            glBegin(GL_QUADS)
            glVertex2f(0.0, 0.0)
            glVertex2f(1.0, 0.0)
            glVertex2f(1.0, 1.0)
            glVertex2f(0.0, 1.0)
            glEnd()
            glFinish()

            residences = glAreTexturesResident(tex_names[:tex_count])
            all_tex_in = reduce(lambda a, b: a and b, residences)
            # bruce 070308 sees this exception from this line:
            # TypeError: reduce() arg 2 must support iteration

        glDisable(GL_TEXTURE_2D)
        glDeleteTextures(tex_names)

        gl_info_string += "Could create %d 512x512 RGBA resident textures\n" \
                          % tex_count
        pass

    if True:  ## or could be a debug_pref("Graphics Card Info: get all GL_MAX symbols?")
        #bruce 090314 new feature
        import OpenGL.GL
        symbols = [x for x in dir(OpenGL.GL) if x.startswith('GL_MAX_')]
        symbols.sort()
        gl_info_string += '\n'
        for symbol in symbols:
            try:
                numeric_symbol = getattr(OpenGL.GL, symbol)
                intval = glGetInteger(numeric_symbol)
            except:
                # this happens to most symbols, not sure why
                if debug_flags.atom_debug:
                    print_compact_traceback("%s = ??: " % symbol)
                    # overkill, only the exception itself matters
                    # typical output (on Bruce's MacBookPro, 090314):
                    ## GL_MAX_4D_TEXTURE_SIZE_SGIS = ??:
                    ## <type 'exceptions.KeyError'>:
                    ## ('Unknown specifier GL_MAX_4D_TEXTURE_SIZE_SGIS (33080)',
                    ##  'Failure in cConverter <OpenGL.converters.SizedOutput object at 0x1457fab0>',
                    ##  [GL_MAX_4D_TEXTURE_SIZE_SGIS], 1, <OpenGL.wrapper.glGetIntegerv object at 0x1458aa30>)
                    ## [graphics_card_info.py:122] [wrapper.py:676] [converters.py:195] [converters.py:234]
                    pass
                pass  ## gl_info_string += "%s = ??\n" % symbol
            else:
                gl_info_string += "%s = %r\n" % (symbol, intval)
            continue
        pass

    return gl_info_string
Ejemplo n.º 22
0
def draw_textured_square(w=None, h=None):
    """
    Draws a texture square of 2 x 2 size centered at 0, 0

    Make sure to call glEnable(GL_TEXTURE_RECTANGLE_ARB) first.

    :param w: width of the image in pixels
    :param h: height of the image in pixels
    """
    if w is None or h is None:
        glBegin(GL_QUADS)
        glTexCoord2f(0.0, 0.0)
        glVertex2f(-1.0, -1.0) # Bottom Left Of The Texture and Quad
        glTexCoord2f(1.0, 0.0)
        glVertex2f(1.0, -1.0) # Bottom Right Of The Texture and Quad
        glTexCoord2f(1.0, 1.0)
        glVertex2f(1.0, 1.0) # Top Right Of The Texture and Quad
        glTexCoord2f(0.0, 1.0)
        glVertex2f(-1.0, 1.0) # Top Left Of The Texture and Quad
        glEnd()
    else:
        glBegin(GL_QUADS)
        glTexCoord2f(0.0, 0.0)
        glVertex2f(-1.0, -1.0) # Bottom Left
        glTexCoord2f(w, 0.0)
        glVertex2f(1.0, -1.0) # Bottom Right
        glTexCoord2f(w, h)
        glVertex2f(1.0, 1.0) # Top Right
        glTexCoord2f(0.0, h)
        glVertex2f(-1.0, 1.0) # Top Left
        glEnd()
Ejemplo n.º 23
0
    def draw_mesh(m, lighting_on):

        # Supply vertices
        glEnableClientState(GL_VERTEX_ARRAY)
        m.vbo['v'].bind()
        glVertexPointer(3, GL_FLOAT, 0, m.vbo['v'])
        m.vbo['v'].unbind()

        # Supply normals
        if 'vn' in m.vbo.keys():
            glEnableClientState(GL_NORMAL_ARRAY)
            m.vbo['vn'].bind()
            glNormalPointer(GL_FLOAT, 0, m.vbo['vn'])
            m.vbo['vn'].unbind()
        else:
            glDisableClientState(GL_NORMAL_ARRAY)

        # Supply colors
        if 'vc' in m.vbo.keys():
            glEnableClientState(GL_COLOR_ARRAY)
            m.vbo['vc'].bind()
            glColorPointer(3, GL_FLOAT, 0, m.vbo['vc'])
            m.vbo['vc'].unbind()
        else:
            glDisableClientState(GL_COLOR_ARRAY)

        if ('vt' in m.vbo.keys()) and hasattr(m, 'textureID'):
            glEnable(GL_TEXTURE_2D)
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
            glBindTexture(GL_TEXTURE_2D, m.textureID)

            glEnableClientState(GL_TEXTURE_COORD_ARRAY)
            m.vbo['vt'].bind()
            glTexCoordPointer(2, GL_FLOAT, 0, m.vbo['vt'])
            m.vbo['vt'].unbind()
        else:
            glDisable(GL_TEXTURE_2D)
            glDisableClientState(GL_TEXTURE_COORD_ARRAY)

        # Draw
        if len(m.f) > 0:
            # ie if it is triangulated
            if lighting_on:
                glEnable(GL_LIGHTING)
            else:
                glDisable(GL_LIGHTING)
            glDrawElementsui(GL_TRIANGLES, np.arange(m.f.size,
                                                     dtype=np.uint32))
        else:
            # not triangulated, so disable lighting
            glDisable(GL_LIGHTING)
            glPointSize(2)
            glDrawElementsui(GL_POINTS, np.arange(len(m.v), dtype=np.uint32))
        if hasattr(m, 'v_to_text'):

            glEnable(GL_TEXTURE_2D)
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                            GL_LINEAR_MIPMAP_LINEAR)
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)

            # glEnable(GL_TEXTURE_GEN_S)
            # glEnable(GL_TEXTURE_GEN_T)
            # glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR)
            # glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR)

            bgcolor = np.array(glGetDoublev(GL_COLOR_CLEAR_VALUE))
            fgcolor = 1. - bgcolor

            from .lines import Lines
            sc = float(np.max(np.max(m.v, axis=0) - np.min(m.v, axis=0))) / 10.

            cur_mtx = np.linalg.pinv(glGetFloatv(GL_MODELVIEW_MATRIX).T)
            xdir = cur_mtx[:3, 0]
            ydir = cur_mtx[:3, 1]

            glEnable(GL_LINE_SMOOTH)
            glEnable(GL_BLEND)
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

            for vidx, text in m.v_to_text.items():
                pos0 = m.v[vidx].copy()
                pos1 = m.v[vidx].copy()
                if hasattr(m, 'vn'):
                    pos1 += m.vn[vidx] * sc
                glLineWidth(5.0)
                ln = Lines(v=np.vstack((pos0, pos1)), e=np.array([[0, 1]]))
                glEnable(GL_LIGHTING)
                glColor3f(1. - 0.8, 1. - 0.8, 1. - 1.00)
                MeshViewerSingle.draw_lines(ln)

                glDisable(GL_LIGHTING)

                texture_id = get_textureid_with_text(text, bgcolor, fgcolor)
                glBindTexture(GL_TEXTURE_2D, texture_id)

                glPushMatrix()
                glTranslatef(pos1[0], pos1[1], pos1[2])

                dx = xdir * .10
                dy = ydir * .10
                if False:
                    glBegin(GL_QUADS)

                    glTexCoord2f(1., 0.)
                    glVertex3f(*(+dx + dy))

                    glTexCoord2f(1., 1.)
                    glVertex3f(*(+dx - dy))

                    glTexCoord2f(0., 1.)
                    glVertex3f(*(-dx - dy))

                    glTexCoord2f(0., 0.)
                    glVertex3f(*(-dx + dy))

                    # gluSphere(quadratic,0.05,32,32)
                    glEnd()
                else:
                    glBegin(GL_POLYGON)

                    for r in np.arange(0, np.pi * 2., .01):
                        glTexCoord2f(np.cos(r) / 2. + .5, np.sin(r) / 2. + .5)
                        glVertex3f(*(dx * np.cos(r) + -dy * np.sin(r)))

                    glEnd()
                glPopMatrix()