Exemplo n.º 1
0
 def bind(self):
     if not self._binded:
         GL.glBindTexture(
             self._kind,
             self.id,
         )
         self._binded = True
Exemplo n.º 2
0
def overlay_texture(txtr, surf, r, alpha = None):
    """Load surface into texture object, replacing part of txtr
    given by rect r. 
    @param txtr: texture to add to
    @param surf: surface to copy from
    @param r: rectangle indicating area to overlay.
    """

    if alpha:
        # set alpha for pixel values of the texture

        surf = surf.copy()

        pygame.surfarray.use_arraytype('numpy')
        a = pygame.surfarray.pixels_alpha(surf)
        a[:] = int(255.0*alpha)
        del a

    subsurf = surf.subsurface(r)
    textureData = pygame.image.tostring(subsurf, "RGBA", 1) 

    hS, wS = surf.get_size()
    rect = pygame.Rect(r.x,hS-(r.y+r.height),r.width,r.height)
    
    ogl.glEnable(ogl.GL_TEXTURE_2D)
    ogl.glBindTexture(ogl.GL_TEXTURE_2D, txtr)
    ogl.glTexSubImage2D(ogl.GL_TEXTURE_2D, 0, rect.x, rect.y, rect.width, rect.height,  
    ogl.GL_RGBA, ogl.GL_UNSIGNED_BYTE, textureData )
    ogl.glDisable(ogl.GL_TEXTURE_2D)
Exemplo n.º 3
0
    def bind_texture(self):
        ''' Bind the current texture to the OpenGL context 
        for rendering. You can release the texture in the
        usual way by binding the zero texture.
        i.e with GL.glBindTexture(GL.GL_TEXTURE_2D, 0)

        Alternatively, using the texture rendering code
        within the context manager defined by an instance
        of the class will bind the textures 
        automatically. Use this as:

        with texture_stream_2d_instance:
            rendering code
            goes
            here
        '''
        GL.glActiveTexture(self.__texture_unit)

        if self.__n_pixel_buffers is 1:
            texture_id = self.__textures[0]
        else:
            self.__update_read_idx()
            texture_id = self.__textures[self.__read_idx]

        GL.glBindTexture(GL.GL_TEXTURE_2D, texture_id)
Exemplo n.º 4
0
    def draw(self):
        ohs = self.owner.healthscale
        ohs = 1
        flippy = 1
        if self.owner.x > self.owner.gmx:
          flippy = -1
        #if self.on:
        GL.glPushMatrix()
        GL.glTranslatef(self.owner.cx, self.owner.cy, 0.0)
        GL.glRotatef(self.owner.aimgle,0,0,1)
        GL.glTranslatef(0.0, 12, 0.0)

        #print flippy
        GL.glTranslatef(self.owner.mx*self.posmult*ohs, self.owner.my*self.posmult*ohs, 0.0)
        GL.glScalef(flippy*self.scale,self.scale,1)
        GL.glScalef(8*ohs,8*ohs,12)

        GL.glBindTexture(GL.GL_TEXTURE_2D, self.image)
        if self.timetofire > 3:
          GL.glBindTexture(GL.GL_TEXTURE_2D, self.loadimage)
        GL.glColor3f(1.0, 1.0, 1.0)
        GL.glBegin(GL.GL_QUADS)
        GL.glTexCoord2f(0.0, 1.0)
        GL.glVertex3f(1.0, 1.0, 0.0)
        GL.glTexCoord2f(1.0, 1.0)
        GL.glVertex3f(-1.0, 1.0, 0.0)
        GL.glTexCoord2f(1.0, 0.0)
        GL.glVertex3f(-1.0, -1.0, 0.0)
        GL.glTexCoord2f(0.0, 0.0)
        GL.glVertex3f(1.0, -1.0, 0.0)
        GL.glEnd()
        GL.glPopMatrix()
Exemplo n.º 5
0
    def LoadFontImage(self):
        im = Image.open("res/font_0.png").convert("RGBA")
        newData = []
        data = im.getdata()
        for item in data:
            if item[0] == 255 and item[1] == 255 and item[2] == 255:
                newData.append((255, 255, 255, 0))
        else:
            newData.append(item)
        im.putdata(newData)

        ix, iy, image = im.size[0], im.size[1], im.tobytes("raw",
                                                           "RGBA",
                                                           0, -1)

        self.textID = GL.glGenTextures(1)
        GL.glBindTexture(GL.GL_TEXTURE_2D, self.textID)
        GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1)
        GL.glTexParameteri(GL.GL_TEXTURE_2D,
                           GL.GL_TEXTURE_WRAP_S,
                           GL.GL_REPEAT)
        GL.glTexParameteri(GL.GL_TEXTURE_2D,
                           GL.GL_TEXTURE_WRAP_T,
                           GL.GL_REPEAT)
        GL.glTexParameteri(GL.GL_TEXTURE_2D,
                           GL.GL_TEXTURE_MAG_FILTER,
                           GL.GL_LINEAR)
        GL.glTexParameteri(GL.GL_TEXTURE_2D,
                           GL.GL_TEXTURE_MIN_FILTER,
                           GL.GL_LINEAR)
        GL.glTexEnvf(GL.GL_TEXTURE_ENV,
                     GL.GL_TEXTURE_ENV_MODE,
                     GL.GL_BLEND)
        GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, ix, iy, 0,
                        GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, image)
Exemplo n.º 6
0
    def __init__(self, name, sx=None, sy=None, swrap=GL.GL_CLAMP, twrap=GL.GL_CLAMP):
        self.name=name
        image = PIL.Image.open(name)
        if sx or sy:
            if not sx: sx=image.width
            if not sy: sy=image.width
            image = image.resize((sx,sy), PIL.Image.BILINEAR)
        
        ix = image.size[0]
        iy = image.size[1]
        imdata = image.tostring("raw", "RGBA", 0, -1)

        self.bbox=array(image.getbbox(),'d') / array([ix,iy,ix,iy],'d')
        print name,self.bbox
        
        self.texid = GL.glGenTextures(1)
        GL.glBindTexture(GL.GL_TEXTURE_2D, self.texid)   # 2d texture (x and y size)
        
        GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1)
        GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, 4, ix, iy, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, imdata)
        GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, swrap)
        GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, twrap)
        GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR)
        GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR)
        GL.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE)
        GL.glEnable(GL.GL_TEXTURE_2D)
Exemplo n.º 7
0
    def __init__( self, sides, size, color,  position = (0.0, 0.0, 0.0) ):
        self.sides = sides
        self.color = color
        self.size = size
        self.position = np.array(position)
        
        height = LEGO_BIG_HEIGHT if self.size else LEGO_SMALL_HEIGHT
        length = self.bottom - self.top
        combine = lambda _points, _vertices, _weights: _points 
            
        self.__tess = GLU.gluNewTess()
        GLU.gluTessCallback(self.__tess, GLU.GLU_TESS_BEGIN, GL.glBegin)
        GLU.gluTessCallback(self.__tess,GLU.GLU_TESS_VERTEX,GL.glVertex3fv)
        GLU.gluTessCallback(self.__tess,GLU.GLU_TESS_COMBINE,combine)
        GLU.gluTessCallback(self.__tess, GLU.GLU_TESS_END, GL.glEnd)
        GLU.gluTessProperty(self.__tess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_ODD)

        self.__gllist = GL.glGenLists(1)
        
        GL.glNewList(self.__gllist,GL.GL_COMPILE)
        GL.glColor3fv(self.color)
        GL.glBindTexture(GL.GL_TEXTURE_2D,0)
        
        GLU.gluTessNormal(self.__tess, 0.0, 1.0, 0.0)
        GL.glNormal3f(0.0, 1.0, 0.0)
        GLU.gluTessBeginPolygon(self.__tess,None)
        GLU.gluTessBeginContour(self.__tess)
        for i in range(0,len(self.coords)):
            vertex =  (self.coords[i][0]*LEGO_GRID, height, self.coords[i-1][1]*LEGO_GRID)
            GLU.gluTessVertex(self.__tess, vertex, vertex)
            vertex =  (self.coords[i][0]*LEGO_GRID, height, self.coords[i][1]*LEGO_GRID)
            GLU.gluTessVertex(self.__tess, vertex, vertex)
        GLU.gluTessEndContour(self.__tess)
        GLU.gluTessEndPolygon(self.__tess)
        
        for i in range(0,len(self.coords)):
            GL.glBegin(GL.GL_QUADS)
            sign = float(np.sign(self.sides[2*i-1]))
            GL.glNormal3f( sign, 0.0, 0.0 )
            GL.glVertex3f( self.coords[i][0] * LEGO_GRID, height, self.coords[i-1][1] * LEGO_GRID)
            GL.glVertex3f( self.coords[i][0] * LEGO_GRID, height, self.coords[i]  [1]   * LEGO_GRID)
            GL.glVertex3f( self.coords[i][0] * LEGO_GRID, 0.0,    self.coords[i]  [1]   * LEGO_GRID)
            GL.glVertex3f( self.coords[i][0] * LEGO_GRID, 0.0,    self.coords[i-1][1] * LEGO_GRID)
            sign = float(np.sign(self.sides[2*i-2]))
            GL.glNormal3f( 0.0, 0.0, -sign )
            GL.glVertex3f( self.coords[i-1][0] * LEGO_GRID, height, self.coords[i-1][1] * LEGO_GRID )
            GL.glVertex3f( self.coords[i]  [0] * LEGO_GRID, height, self.coords[i-1][1] * LEGO_GRID )
            GL.glVertex3f( self.coords[i]  [0] * LEGO_GRID, 0.0,    self.coords[i-1][1] * LEGO_GRID )
            GL.glVertex3f( self.coords[i-1][0] * LEGO_GRID, 0.0,    self.coords[i-1][1] * LEGO_GRID )
            GL.glEnd()
            
        GL.glTranslatef( self.left*LEGO_GRID + LEGO_GRID/2.0, (LEGO_BUMP_HEIGHT+height)/2.0 , self.bottom*LEGO_GRID - LEGO_GRID/2.0 )
        for i in range( self.left, self.right ):
            for j in range( self.bottom, self.top ):
                GL.glTranslatef( 0.0, 0.0, LEGO_GRID )
                if self.is_hit( (i+0.5,j+0.5) ):
                    _caped_cylinder( LEGO_BUMP_RADIUS, height+LEGO_BUMP_HEIGHT, 32 )
            GL.glTranslatef( 0.0, 0.0, length*LEGO_GRID )
            GL.glTranslatef( LEGO_GRID, 0.0, 0.0 )
        GL.glEndList()
Exemplo n.º 8
0
    def upload(self):

        # Update uniform index for all objects
        # TODO: vectorize
        for i in range(len(self.objects)):
            _,vstart,vend,_,_,_,_ = self.objects[i]
            self.vertices_data[vstart:vend]['index'] = i/float(len(self.uniforms_data))

        VertexBuffer.upload(self)

        if not self._uniforms_id:
            self._uniforms_id = gl.glGenTextures(1)
        gl.glActiveTexture( gl.GL_TEXTURE0 )
        gl.glPixelStorei( gl.GL_UNPACK_ALIGNMENT, 1 )
        gl.glPixelStorei( gl.GL_PACK_ALIGNMENT, 1 )
        gl.glBindTexture( gl.GL_TEXTURE_2D, self._uniforms_id )
        gl.glTexParameterf( gl.GL_TEXTURE_2D,
                            gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST )
        gl.glTexParameterf( gl.GL_TEXTURE_2D,
                           gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST )
        gl.glTexParameterf( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE )
        gl.glTexParameterf( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE )

        data = self.uniforms_data.view(np.float32)
        self.uniforms_shape = data.shape[1]//4, data.shape[0]
        gl.glTexImage2D( gl.GL_TEXTURE_2D, 0, gl.GL_RGBA32F_ARB,
                         data.shape[1]//4, data.shape[0], 0, gl.GL_RGBA, gl.GL_FLOAT, data )
Exemplo n.º 9
0
    def render(self):
        gl.glClearColor(0, 0, 0, 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        with self.shader_prog:
            # Activate array
            gl.glBindVertexArray(self.vao_id)

            # FIXME: Why does the following work? tex_uniform is 1,
            # palette_uniform is 0, but I have to set the uniform for
            # tex_uniform to 0 and the uniform for palette_uniform to 1.
            # Obviously I'm not understanding something.
            #
            # See: http://stackoverflow.com/questions/26622204
            # https://www.opengl.org/discussion_boards/showthread.php/174926-when-to-use-glActiveTexture

            # Activate texture
            print(self.tex_uniform, self.palette_uniform, self.sample_texture, self.palette_id)
            gl.glActiveTexture(gl.GL_TEXTURE0 + self.tex_uniform)
            gl.glBindTexture(gl.GL_TEXTURE_2D, self.sample_texture)
            gl.glUniform1i(self.tex_uniform, 0)

            # Activate palette texture
            gl.glActiveTexture(gl.GL_TEXTURE0 + self.palette_uniform)
            gl.glBindTexture(gl.GL_TEXTURE_BUFFER, self.palette_texture)
            gl.glTexBuffer(gl.GL_TEXTURE_BUFFER, gl.GL_RGBA8, self.palette_id)
            gl.glUniform1i(self.palette_uniform, 1)

            # # Activate array
            # gl.glBindVertexArray(self.vao_id)

            # draw triangle
            gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
Exemplo n.º 10
0
    def _drawLUTtoScreen(self):
        """(private) Used to set the LUT on the Bits++.
        Used to draw the LUT to the screen when in 'bits++' mode (not mono++ or colour++).
        Should not be needed by user if attached to a ``psychopy.visual.Window()``
        since this will automatically draw the LUT as part of the screen refresh.
        """
        #push the projection matrix and set to orthorgaphic

        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glPushMatrix()
        GL.glLoadIdentity()
        GL.glOrtho( 0, self.win.size[0],self.win.size[1], 0, 0, 1 )	#this also sets the 0,0 to be top-left
        #but return to modelview for rendering
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glLoadIdentity()

        #draw the pixels
        GL_multitexture.glActiveTextureARB(GL_multitexture.GL_TEXTURE0_ARB)
        GL.glEnable(GL.GL_TEXTURE_2D)
        GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
        GL_multitexture.glActiveTextureARB(GL_multitexture.GL_TEXTURE1_ARB)
        GL.glEnable(GL.GL_TEXTURE_2D)
        GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
        GL.glRasterPos2i(0,1)
        GL.glDrawPixelsub(GL.GL_RGB, self._HEADandLUT)
        #GL.glDrawPixels(524,1, GL.GL_RGB,GL.GL_UNSIGNED_BYTE, self._HEADandLUTstr)
        #return to 3D mode (go and pop the projection matrix)
        GL.glMatrixMode( GL.GL_PROJECTION )
        GL.glPopMatrix()
        GL.glMatrixMode( GL.GL_MODELVIEW )
Exemplo n.º 11
0
    def paint_slid(self):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT);

        # activate the program and set parameters
        gl.glUseProgram(self.program)
        gl.glUniform1i(self.texture1, 0)  # indicate we use GL_TEXTURE0

        # set up the texture to map
        gl.glEnable(gl.GL_TEXTURE_2D)
        gl.glActiveTexture(gl.GL_TEXTURE0)
        if self.usingA:
            gl.glBindTexture(gl.GL_TEXTURE_2D, self.textureB)
        else:
            gl.glBindTexture(gl.GL_TEXTURE_2D, self.textureA)


        # a simple square filling the whole view
        self.square.bind()

        # activate using VBOs for the vertices
        gl.glEnableVertexAttribArray(0)

        # indicate that the VBO has texture and vertex data
        gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
        gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY);

        # indicate where the vertex and texture data is
        gl.glVertexAttribPointer(0, 3, gl.GL_FLOAT,
                                 gl.GL_FALSE, 5*4, None)
        gl.glTexCoordPointer(2, gl.GL_FLOAT, 5*4, self.square + 3*4)

        # draw the square
        gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6)
Exemplo n.º 12
0
    def draw_points(self, points, colors, sizes, texture):
        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
        gl.glVertexPointerd(points)
        gl.glEnableClientState(gl.GL_COLOR_ARRAY)
        gl.glColorPointerd(colors)

        fade_size = 60.0
        att_param = [0.0, 0.0, 0.01]
        (ps_min, ps_max) = gl.glGetFloatv(gl.GL_ALIASED_POINT_SIZE_RANGE)

        gl.glEnable(gl.GL_TEXTURE_2D)
        gl.glBindTexture(gl.GL_TEXTURE_2D, texture)

        gl.glEnable(gl.GL_POINT_SPRITE)

        gl.glPointSize(POINT_SIZE)
        gl.glTexEnvf(gl.GL_POINT_SPRITE, gl.GL_COORD_REPLACE, gl.GL_TRUE)
        gl.glPointParameterfv(gl.GL_POINT_DISTANCE_ATTENUATION, att_param)
        gl.glPointParameterf(gl.GL_POINT_SIZE_MAX, ps_max)
        gl.glPointParameterf(gl.GL_POINT_SIZE_MIN, ps_min)
        gl.glPointParameterf(gl.GL_POINT_FADE_THRESHOLD_SIZE, fade_size)

        ####
        self.draw_arrays(points, colors, sizes, False)
        ####

        gl.glDisable(gl.GL_POINT_SPRITE)
        gl.glDisable(gl.GL_TEXTURE_2D)
        gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
        gl.glDisableClientState(gl.GL_COLOR_ARRAY)
Exemplo n.º 13
0
    def load_textures(self):
        if self.gamecount() <= 1:
            # Make sure that this is always a list
            self.textures = gl.glGenTextures(2)
        else:
            self.textures = gl.glGenTextures(self.gamecount())
        c = 0
        for game in self.gamelist:
            textureSurface = game.getSurface()
            textureData = pygame.image.tostring(textureSurface, "RGBX", 1)

            gl.glBindTexture(gl.GL_TEXTURE_2D, self.textures[c])
            gl.glTexImage2D(
                gl.GL_TEXTURE_2D,
                0,
                gl.GL_RGBA,
                textureSurface.get_width(),
                textureSurface.get_height(),
                0,
                gl.GL_RGBA,
                gl.GL_UNSIGNED_BYTE,
                textureData,
            )
            gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
            gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST)
            c += 1
Exemplo n.º 14
0
    def blit(self, x, y, w, h, z=0, s=(0,1), t=(0,1)):
        ''' Draw texture to active framebuffer. '''

        if self.target == gl.GL_TEXTURE_1D:
            gl.glDisable (gl.GL_TEXTURE_2D)
            gl.glEnable (gl.GL_TEXTURE_1D)
            gl.glBindTexture(self.target, self.id)
            gl.glBegin(gl.GL_QUADS)
            gl.glTexCoord1f(s[0]), gl.glVertex2f(x,   y)
            gl.glTexCoord1f(s[0]), gl.glVertex2f(x,   y+h)
            gl.glTexCoord1f(s[1]), gl.glVertex2f(x+w, y+h)
            gl.glTexCoord1f(s[1]), gl.glVertex2f(x+w, y)
            gl.glEnd()
        else:
            gl.glEnable (gl.GL_TEXTURE_2D)
            gl.glDisable (gl.GL_TEXTURE_1D)
            gl.glBindTexture(self.target, self.id)
            gl.glBegin(gl.GL_QUADS)
            gl.glTexCoord2f(s[0], 1), gl.glVertex2f(x,   y)
            gl.glTexCoord2f(s[0], 0), gl.glVertex2f(x,   y+h)
            gl.glTexCoord2f(s[1], 0), gl.glVertex2f(x+w, y+h)
            gl.glTexCoord2f(s[1], 1), gl.glVertex2f(x+w, y)
            gl.glEnd()
        gl.glDisable (gl.GL_TEXTURE_1D)
        gl.glDisable (gl.GL_TEXTURE_2D)
Exemplo n.º 15
0
 def draw(self):
     loc = gl.glGetUniformLocation(self.program, "tex")
     gl.glUniform1i(loc, 0)
     gl.glActiveTexture(gl.GL_TEXTURE0)
     gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, self.tex)
     
     geometry.base.draw(self)
Exemplo n.º 16
0
    def buildQuad(self):
        if self.drawList > 0:
            GL.glDeleteLists(self.drawList, 1)
        xmin, ymin, zmin = self._limits[0]
        xmax, ymax, zmax = self._limits[1]
        tx0 = 0.0
        tx1 = (1.0 * self.__width)/self.__tWidth
        ty0 = 0.0
        ty1 = (1.0 * self.__height)/self.__tHeight
        self.drawList = GL.glGenLists(1)
        GL.glNewList(self.drawList, GL.GL_COMPILE)
        #The texture gets multiplied by this color!!
        GL.glColor4f(1.0, 1.0, 1.0, self.__alpha)
       	GL.glBindTexture(GL.GL_TEXTURE_2D, self.__textureId)
        GL.glEnable(GL.GL_TEXTURE_2D)
        GL.glBegin(GL.GL_QUADS)
       	GL.glTexCoord2d(tx0, ty0)
       	GL.glVertex3f(xmin, ymin, zmin)
	GL.glTexCoord2d(tx0, ty1)
	GL.glVertex3f(xmin, ymax, zmin)
	GL.glTexCoord2d(tx1, ty1)
	GL.glVertex3f(xmax, ymax, zmin)
	GL.glTexCoord2d(tx1, ty0)
	GL.glVertex3f(xmax, ymin, zmin)
        GL.glEnd()
        GL.glDisable(GL.GL_TEXTURE_2D)
        GL.glEndList()
        self._forceListCalculation = False
def makeGrating():
    res=128
    #make basic texture
    onePeriodX, onePeriodY = numpy.mgrid[0:2*pi:2*pi/res, 0:2*pi:2*pi/res]
    intensity = numpy.sin(onePeriodX-pi/2)#*numpy.sin(onePeriodY-pi/2)
    #paste into rgb
    data = numpy.ones((res,res,4),numpy.float32)#initialise data array as a float
    data[:,:,0] = intensity
    data[:,:,1] = intensity
    data[:,:,2] = intensity
    data[:,:,3] = 1.0
    #data = float_uint8(data)#data range -1:1 -> 0:255
    texture = data.tostring()#serialise
    print 'texID', texID
    #upload texture
    GL.glEnable(GL.GL_TEXTURE_2D)
    GL.glBindTexture(GL.GL_TEXTURE_2D, texID)#bind that name to the target
    GL.glTexImage2D(GL.GL_TEXTURE_2D,#target
                    0,                              #mipmap level
                    GL.GL_RGBA32F_ARB,      #internal format
                    res,                    #width
                    res,
                    0,                       #border
                    GL.GL_RGBA, #target format
                    GL.GL_FLOAT, #target data type
                    texture)                #the data
    GL.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_WRAP_S,GL.GL_REPEAT)  #makes the texture map wrap (this is actually default anyway)
    #interpolate with NEAREST NEIGHBOUR. Important if using bits++ because GL_LINEAR
    #sometimes extrapolates to pixel vals outside range
    GL.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MAG_FILTER,GL.GL_NEAREST)
    GL.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MIN_FILTER,GL.GL_NEAREST)
    GL.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE)
    GL.glBindTexture(GL.GL_TEXTURE_2D, 0)#bind that name to the target
    GL.glDisable(GL.GL_TEXTURE_2D)
def flip():
    global frameTexture
    
    if useFBO: 
        FB.glBindFramebufferEXT(FB.GL_FRAMEBUFFER_EXT, 0)
        
        GL.glDisable(GL.GL_BLEND)
        #GL.glBlendEquation(GL.GL_FUNC_ADD)
        #GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
        #GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_DST_ALPHA)
        
        #before flipping need to copy the renderBuffer to the frameBuffer
        GL.glColor4f(1,1,1,1)
        GL.glActiveTexture(GL.GL_TEXTURE0)
        GL.glBindTexture(GL.GL_TEXTURE_2D, frameTexture)
        GL.glBegin( GL.GL_QUADS )
        GL.glMultiTexCoord2f(GL.GL_TEXTURE0, 0.0, 0.0 ) 
        GL.glVertex2f( -1.0,-1.0 )
        GL.glMultiTexCoord2f(GL.GL_TEXTURE0, 0.0, 1.0 ) 
        GL.glVertex2f( -1.0, 1.0 )
        GL.glMultiTexCoord2f(GL.GL_TEXTURE0,1.0, 1.0 ) 
        GL.glVertex2f( 1.0,   1.0 )
        GL.glMultiTexCoord2f(GL.GL_TEXTURE0, 1.0, 0.0 ) 
        GL.glVertex2f( 1.0,   -1.0 )
        GL.glEnd()
    pygame.display.flip()
    
    if useFBO: 
        GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
        GL.glDisable(GL.GL_TEXTURE_2D)
        GL.glEnable(GL.GL_BLEND)
        
        FB.glBindFramebufferEXT(FB.GL_FRAMEBUFFER_EXT, frameBuffer)
Exemplo n.º 19
0
def createBufferTexture(texID, texw, texh):
    """createBufferTexture - create an 8-bit texture render target"""
    gl.glActiveTexture(gl.GL_TEXTURE0)
    gl.glBindTexture(gl.GL_TEXTURE_2D, texID)
    black = (0., 0., 0., 0.)
    # The special shader used to render this texture performs a
    # per-pixel image processing where point sampling is required,
    # so specify nearest neighbor sampling.
    #
    # Also, the flood fill shader handles its own edge clamping, so
    # texture mode GL_REPEAT is inconsequential. "Zero outside" would
    # be useful, but separate edge values are deprecated in OpenGL.
    #
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER,
                       gl.GL_NEAREST)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                       gl.GL_NEAREST)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S,
                       gl.GL_CLAMP_TO_EDGE)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T,
                       gl.GL_CLAMP_TO_EDGE)
    gl.glTexParameterfv(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_BORDER_COLOR, black)
    gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, texw, texh, 0,
                    gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, '\x00' * texw*texh*4)
    gl.glBindTexture(gl.GL_TEXTURE_2D, 0)
    checkGLError()
Exemplo n.º 20
0
    def _load_texture(surf):
        """Load surface into texture object.

        Returns a texture object.

        Parameters
        ----------
        surf : pygame.Surface object
            surface to make texture from

        """

        txtr = ogl.glGenTextures(1)
        textureData = pygame.image.tostring(surf, "RGBA", 1)
        ogl.glEnable(ogl.GL_TEXTURE_2D)
        ogl.glBindTexture(ogl.GL_TEXTURE_2D, txtr)
        width, height = surf.get_size()
        ogl.glTexImage2D(ogl.GL_TEXTURE_2D, 0, ogl.GL_RGBA, width, height, 0,
          ogl.GL_RGBA, ogl.GL_UNSIGNED_BYTE, textureData)
        ogl.glTexParameterf(ogl.GL_TEXTURE_2D,
                            ogl.GL_TEXTURE_MAG_FILTER,
                            ogl.GL_NEAREST)
        ogl.glTexParameterf(ogl.GL_TEXTURE_2D,
                            ogl.GL_TEXTURE_MIN_FILTER,
                            ogl.GL_NEAREST)
        ogl.glDisable(ogl.GL_TEXTURE_2D)
        return txtr
Exemplo n.º 21
0
    def display(self):
        """Draw surface to a quad. Call as part of OpenGL rendering code."""
        ogl.glEnable(ogl.GL_BLEND)
        ogl.glBlendFunc(ogl.GL_SRC_ALPHA, ogl.GL_ONE_MINUS_SRC_ALPHA)  
        ogl.glEnable(ogl.GL_TEXTURE_2D)
        ogl.glBindTexture(ogl.GL_TEXTURE_2D, self._txtr)
        ogl.glTexEnvf(ogl.GL_TEXTURE_ENV, ogl.GL_TEXTURE_ENV_MODE, ogl.GL_REPLACE)
        #ogl.glColor4d( 1.0, 1.0, 1.0, alpha )
        #ogl.glTexEnvf(ogl.GL_TEXTURE_ENV, ogl.GL_TEXTURE_ENV_MODE, ogl.GL_MODULATE)
        #glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
        #ogl.glTexEnvfv(ogl.GL_TEXTURE_ENV, ogl.GL_TEXTURE_ENV_COLOR, (0, 0, 0, alpha))

        #ogl.glNormal3f(0.0, 0.0, -1.0)

        ogl.glBegin(ogl.GL_QUADS)
        ogl.glTexCoord2f(0.0, 1-self._usable[1])
        # bottom left corner
        ogl.glVertex3f(*self.dims[0])

        ogl.glTexCoord2f(self._usable[0], 1-self._usable[1])
        # bottom right corner
        ogl.glVertex3f(self.dims[1][0],self.dims[1][1],0.0)

        ogl.glTexCoord2f(self._usable[0], 1.0)
        # top right corner
        ogl.glVertex3f(*self.dims[2])

        ogl.glTexCoord2f(0.0, 1.0)
        # top left corner
        ogl.glVertex3f(*self.dims[3])
        ogl.glEnd()
        ogl.glDisable(ogl.GL_BLEND)
        ogl.glDisable(ogl.GL_TEXTURE_2D)
Exemplo n.º 22
0
def draw_background(imname):
    ''' Draw background image using a quad. '''

    # load background image (should be .bmp) to OpenGL texture
    bg_image = pygame.image.load(imname).convert()
    bg_data = pygame.image.tostring(bg_image, "RGBA", 1)

    GL.glMatrixMode(GL.GL_MODELVIEW)
    GL.glLoadIdentity()

    GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)

    # bind the texture
    GL.glEnable(GL.GL_TEXTURE_2D)
    GL.glBindTexture(GL.GL_TEXTURE_2D, GL.glGenTextures(1))
    GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, bg_data)
    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST)
    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST)

    # create quad to fill the whole window
    GL.glBegin(GL.GL_QUADS)
    GL.glTexCoord2f(0.0, 0.0); GL.glVertex3f(-1.0, -1.0, -1.0)
    GL.glTexCoord2f(1.0, 0.0); GL.glVertex3f(1.0, -1.0, -1.0)
    GL.glTexCoord2f(1.0, 1.0); GL.glVertex3f(1.0, 1.0, -1.0)
    GL.glTexCoord2f(0.0, 1.0); GL.glVertex3f(-1.0, 1.0, -1.0)
    GL.glEnd()

    # clear the texture
    GL.glDeleteTextures(1)
Exemplo n.º 23
0
def init():
    #lighting is setup
    GL.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, lambient)
    GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, ldiffuse)
    GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, lspecular)
    GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, lposition)
    GL.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, lmodelambient)
    GL.glEnable(GL.GL_LIGHTING)
    GL.glEnable(GL.GL_LIGHT0)
    GL.glEnable(GL.GL_DEPTH_TEST)
    #display list for the axes and the orbitals
    GL.glNewList(1, GL.GL_COMPILE)
    GL.glPushMatrix()
    GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
    GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, [1.0, 1.0, 1.0, 1.0])
    GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0])
    GL.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
    GL.glMaterialf(GL.GL_FRONT, GL.GL_SHININESS, .5)
    GL.glBegin(GL.GL_LINES)
    GL.glVertex3f(0.0, 0.0, 0.0)
    GL.glVertex3f(50.0, 0.0, 0.0)
    GL.glEnd()
    GL.glBegin(GL.GL_LINES)
    GL.glVertex3f(0.0, 0.0, 0.0)
    GL.glVertex3f(0.0, 50.0, 0.0)
    GL.glEnd()
    GL.glBegin(GL.GL_LINES)
    GL.glVertex3f(0.0, 0.0, 0.0)
    GL.glVertex3f(0.0, 0.0, 50.0)
    GL.glEnd()
    GL.glPopMatrix()
    GL.glEndList()
Exemplo n.º 24
0
    def update(self, bias=0.0, scale=1.0):
        ''' Update texture. '''

        gl.glBindTexture(self.target, self.id)

        # Autoscale array using OpenGL pixel transfer parameters
        if self.target == gl.GL_TEXTURE_2D and self.src_type == gl.GL_FLOAT:
            gl.glPixelTransferf(gl.GL_ALPHA_SCALE, scale)
            gl.glPixelTransferf(gl.GL_ALPHA_BIAS, bias)

        if self.target == gl.GL_TEXTURE_1D:
            gl.glTexSubImage1D (self.target, 0, 0, 
                                self._Z.shape[0],
                                self.src_format,
                                self.src_type,
                                self._Z) #.ctypes.data)
        else:
            gl.glTexSubImage2D (self.target, 0, 0, 0,
                                self._Z.shape[1],
                                self._Z.shape[0],
                                self.src_format,
                                self.src_type,
                                self._Z) #.ctypes.data)
        if self.target == gl.GL_TEXTURE_2D and self.src_type == gl.GL_FLOAT:
            # Default parameters
            gl.glPixelTransferf(gl.GL_ALPHA_SCALE, 1)
            gl.glPixelTransferf(gl.GL_ALPHA_BIAS, 0)
Exemplo n.º 25
0
def load_texture(surf,alpha=None):
    """Load surface into texture object. Return texture object. 
    @param surf: surface to make texture from.
    """
    txtr = ogl.glGenTextures(1)

    if alpha:
        # set alpha for pixel values of the texture

        surf = surf.copy()

        pygame.surfarray.use_arraytype('numpy')
        a = pygame.surfarray.pixels_alpha(surf)
        a[:] = int(255.0*alpha)
        del a

    textureData = pygame.image.tostring(surf, "RGBA", 1)

    ogl.glEnable(ogl.GL_TEXTURE_2D)
    ogl.glBindTexture(ogl.GL_TEXTURE_2D, txtr)
    width, height = surf.get_size()
    ogl.glTexImage2D( ogl.GL_TEXTURE_2D, 0, ogl.GL_RGBA, width, height, 0, 
      ogl.GL_RGBA, ogl.GL_UNSIGNED_BYTE, textureData )
    ogl.glTexParameterf(ogl.GL_TEXTURE_2D, ogl.GL_TEXTURE_MAG_FILTER, ogl.GL_NEAREST)
    ogl.glTexParameterf(ogl.GL_TEXTURE_2D, ogl.GL_TEXTURE_MIN_FILTER, ogl.GL_NEAREST)
    ogl.glDisable(ogl.GL_TEXTURE_2D)
    return txtr
Exemplo n.º 26
0
	def initTexture(self):
		"""
		init the texture - this has to happen after an OpenGL context
		has been created
		"""
		#data = np.flipud(lena())
		data = self.current_grid
		w,h = data.shape

		# generate a texture id, make it current
		self.mytexture = gl.glGenTextures(1)
		gl.glBindTexture(gl.GL_TEXTURE_2D,self.mytexture)

		# texture mode and parameters controlling wrapping and scaling
		gl.glTexEnvf( gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_MODULATE )
		gl.glTexParameterf( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_REPEAT )
		gl.glTexParameterf( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_REPEAT )
		gl.glTexParameterf( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR )
		gl.glTexParameterf( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR )


		# map the image data to the texture. note that if the input
		# type is GL_FLOAT, the values must be in the range [0..1]
		gl.glTexImage2D(gl.GL_TEXTURE_2D,0,gl.GL_RGB,w,h,0,
		    gl.GL_LUMINANCE,gl.GL_UNSIGNED_BYTE,data)
Exemplo n.º 27
0
    def generate_texture(self, width, height):
        data = [1.0, 0.0, 0.0] * (width * height)
        half_viewport_size = game_core.Point(width / 2.0 * self.heightmap.min_size, height / 2.0 * self.heightmap.min_size)
        viewport = game_core.BoundingBox2D(self.center - half_viewport_size, self.center + half_viewport_size)
        self.heightmap._generate_debug_texture(viewport, width, height, data)

        if self.texture_quad_vao is None:
            self.create_texture_vao()

        if self.texture is None:
            self.texture = GL.glGenTextures(1)
        # "Bind" the newly created texture : all future texture functions will modify this texture
        GL.glBindTexture(GL.GL_TEXTURE_2D, self.texture)

        # Give the image to OpenGL
        array_type = (GL.GLfloat * len(data))
        GL.glTexImage2D(
            GL.GL_TEXTURE_2D,
            0,
            GL.GL_RGB,
            width,
            height,
            0,
            GL.GL_RGB,
            GL.GL_FLOAT,
            array_type(*data)
        )

        GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST)
        GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST)
Exemplo n.º 28
0
    def upload(self):
        '''
        Upload atlas data into video memory.
        '''

        if not self.texid:
            self.texid = gl.glGenTextures(1)

        gl.glBindTexture( gl.GL_TEXTURE_2D, self.texid )
        gl.glTexParameteri( gl.GL_TEXTURE_2D,
                            gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP )
        gl.glTexParameteri( gl.GL_TEXTURE_2D,
                            gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP )
        gl.glTexParameteri( gl.GL_TEXTURE_2D,
                            gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR )
        gl.glTexParameteri( gl.GL_TEXTURE_2D,
                            gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR )
        if self.depth == 1:
            gl.glTexImage2D( gl.GL_TEXTURE_2D, 0, gl.GL_ALPHA,
                             self.width, self.height, 0,
                             gl.GL_ALPHA, gl.GL_UNSIGNED_BYTE, self.data )
        else:
            gl.glTexImage2D( gl.GL_TEXTURE_2D, 0, gl.GL_RGB,
                             self.width, self.height, 0,
                             gl.GL_RGB, gl.GL_UNSIGNED_BYTE, self.data )
Exemplo n.º 29
0
   def quad(self, g, quad):
      # Enable alpha blending/transparency
      self.vbuffer.sync()

      gl.glUseProgram(self.program.id)
      gl.glEnable(gl.GL_BLEND)
      gl.glEnable(gl.GL_DEPTH_TEST)
      gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
      
      # Bind texture
      gl.glUniform1i(self.program.tex, 0) 
      gl.glBindTexture(gl.GL_TEXTURE_2D, quad.texture.id)
      
      # Set up geometry transforms
      worldMatrix = Matrix.scale(quad.width, quad.height, 1) 
      worldMatrix = Matrix.translate(quad.x, quad.y, 0) * worldMatrix
      worldViewProjectionMatrix = g.viewProjectionMatrix * worldMatrix
      #worldViewProjectionMatrix = g.viewProjectionMatrix
      gl.glUniformMatrix4fv(self.program.worldViewProjectionMatrix, 1, 0, 
                            worldViewProjectionMatrix.data)

      # Draw geometry
      gl.glBindVertexArray(self.vao)
      gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
      gl.glBindVertexArray(0)
Exemplo n.º 30
0
    def Enable(self):
        """ Enable the sprite, drawing points after calling this
        draws this sprite at each point. """
        
        if not self._texId and self._canUse in [None, True]:
            self.Create()
        
        if not self._canUse:
            gl.glEnable(gl.GL_POINT_SMOOTH)
            gl.glPointSize(self._width)
            return # proceed if None; canUse is assigned in Create()    
        
        # bind to texture
        gl.glEnable(gl.GL_TEXTURE_2D)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self._texId)

        # get allowed point size
        sizeRange = gl.glGetFloatv(gl.GL_ALIASED_POINT_SIZE_RANGE)
        gl.glPointParameterf( gl.GL_POINT_SIZE_MIN, sizeRange[0] );
        gl.glPointParameterf( gl.GL_POINT_SIZE_MAX, sizeRange[1] );

        # enable sprites and set params
        gl.glEnable(gl.GL_POINT_SPRITE)

        # tell opengl to iterate over the texture
        gl.glTexEnvf( gl.GL_POINT_SPRITE, gl.GL_COORD_REPLACE, gl.GL_TRUE )
    def render(self: 'GLQuadRenderer') -> None:
        if not self.__loaded:
            return

        if self.__new_texture is not None:
            self.__load_texture()
            self.__new_texture = None

        super().render()

        GL.glActiveTexture(GL.GL_TEXTURE0)
        GL.glBindTexture(GL.GL_TEXTURE_2D, self.__texture)
        GL.glActiveTexture(GL.GL_TEXTURE1)
        GL.glBindTexture(GL.GL_TEXTURE_2D, self.__data_texture)
        GL.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4)
Exemplo n.º 32
0
    def exit(self):
        if self.sceneNode.textureAtlas is None:
            return

        GL.glDisable(GL.GL_CULL_FACE)
        glutils.glActiveTexture(GL.GL_TEXTURE1)
        GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
        GL.glDisable(GL.GL_TEXTURE_2D)
        GL.glMatrixMode(GL.GL_TEXTURE)
        GL.glPopMatrix()

        glutils.glActiveTexture(GL.GL_TEXTURE0)
        GL.glDisable(GL.GL_TEXTURE_2D)
        GL.glMatrixMode(GL.GL_TEXTURE)
        GL.glPopMatrix()
Exemplo n.º 33
0
def setupTextures():
    global g_TextureID
    gl.glGenTextures(1, g_TextureID)
    gl.glBindTexture(gl.GL_TEXTURE_2D, g_TextureID)
    gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP)

    gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_REPLACE)
    gl.glBindTexture(gl.GL_TEXTURE_2D, 0)

    global g_isSetupTextures
    g_isSetupTextures = True
Exemplo n.º 34
0
    def draw(self):
        r"""Runs a given shader program on the block collection.  It is assumed
        that the GL Context has been set up, which is typically handled by the
        run_program method.
        """

        # clear the color and depth buffer
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        GL.glActiveTexture(GL.GL_TEXTURE0)

        for bi in self.block_order:
            tex_i, block = self.blocks[bi]
            ti = self.gl_texture_names[tex_i]
            GL.glBindTexture(GL.GL_TEXTURE_3D, ti)
            GL.glDrawArrays(GL.GL_TRIANGLES, tex_i * 36, 36)
Exemplo n.º 35
0
    def sendUniforms(self, uniloc: sha.UnilocGeneral, index: int) -> None:
        color: tuple = self.getColorRGB()
        gl.glUniform3f(uniloc.uDlightColors[index], color[0], color[1],
                       color[2])
        gl.glUniform3f(uniloc.uDlightDirs[index], self.__direction.x,
                       self.__direction.y, self.__direction.z)

        projViewMat = self.getProjViewMat()
        gl.glUniformMatrix4fv(uniloc.uDlightProjViewMat[index], 1, gl.GL_FALSE,
                              glm.value_ptr(projViewMat))

        gl.glActiveTexture(gl.GL_TEXTURE0 + self.__shadowMap.getTexId())
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.__shadowMap.getTexId())
        gl.glUniform1i(uniloc.uDlightDepthMap[index],
                       self.__shadowMap.getTexId())
Exemplo n.º 36
0
    def __init__(self, data):

        self.texture = GL.glGenTextures(1)

        GL.glBindTexture(GL.GL_TEXTURE_1D, self.texture)
        GL.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_WRAP_S,
                           GL.GL_CLAMP_TO_EDGE)
        GL.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MIN_FILTER,
                           GL.GL_LINEAR)
        GL.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MAG_FILTER,
                           GL.GL_LINEAR)
        GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1)
        GL.glTexImage1D(GL.GL_TEXTURE_1D, 0, GL.GL_RGBA, data.size // 4, 0,
                        GL.GL_RGBA, GL.GL_FLOAT, data)
        GL.glBindTexture(GL.GL_TEXTURE_1D, GL.GL_FALSE)
Exemplo n.º 37
0
def loadTexture(path):
    image = Image.open(path).convert("RGBA")
    imageData = image.tobytes("raw", "RGBA", 0, -1)
    texture = gl.glGenTextures(1)
    gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 4)
    gl.glBindTexture(gl.GL_TEXTURE_2D, texture)
    gl.glEnable(gl.GL_BLEND)  # включить смешивание
    gl.glEnable(gl.GL_ALPHA_TEST)  # разрешить прозрачность
    gl.glAlphaFunc(gl.GL_GEQUAL, 0.4)  # не пропускать прозрачность ниже 0.4
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)  # один из видов смешивания, подробнее читать в интернете
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_BASE_LEVEL, 0)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAX_LEVEL, 0)
    gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, image.size[0], image.size[1],
                    0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, imageData)
    return texture
Exemplo n.º 38
0
    def assign(self, array):
        gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, self.id_)

        if array.dtype == np.uint8:
            gl.glTexImage2D(gl.GL_TEXTURE_RECTANGLE, 0, self.internalFormat_,
                            self.width_, self.height_, 0, self.format,
                            gl.GL_UNSIGNED_BYTE, array)
        elif array.dtype == np.float32:
            gl.glTexImage2D(gl.GL_TEXTURE_RECTANGLE, 0, self.internalFormat_,
                            self.width_, self.height_, 0, self.format,
                            gl.GL_FLOAT, array)
        else:
            raise NotImplementedError("pixel type not implemented.")

        gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, 0)
Exemplo n.º 39
0
    def gen_texture(self):
        texture = gl.glGenTextures(1)

        gl.glBindTexture(gl.GL_TEXTURE_2D, texture)

        gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                           gl.GL_LINEAR)
        gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER,
                           gl.GL_LINEAR)

        gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, self.width,
                        self.height, 0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE,
                        pygame.image.tostring(self.pygame_surface, "RGBA"))

        return Texture2D(texture)
Exemplo n.º 40
0
def LoadOpenGLTexture(textFile):
    img = cv2.imread(textFile)
    GL.glEnable(GL.GL_TEXTURE_2D)
    texture = GL.glGenTextures(1)
    GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1)
    GL.glBindTexture(GL.GL_TEXTURE_2D, texture)
    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP)
    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP)
    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,
                       GL.GL_LINEAR)
    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,
                       GL.GL_LINEAR)
    GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, len(img[0]), len(img), 0,
                    GL.GL_BGR, GL.GL_UNSIGNED_BYTE, img)
    return texture
Exemplo n.º 41
0
    def set_texture(self, img):
        image = img.convert("RGBA").tobytes("raw", "RGBA", 0, 1)

        self._texture_id = gl.glGenTextures(1)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self._texture_id)

        gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER,
                           gl.GL_LINEAR)
        gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                           gl.GL_LINEAR)
        gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP)
        gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP)

        gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, img.size[0],
                        img.size[1], 0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, image)
Exemplo n.º 42
0
    def step(self):
        if time.time() > self.SCREENCAP_INTERVAL + self.t0:
            adb.pull_image()
            gl.glBindTexture(gl.GL_TEXTURE_2D, self.image_texture)
            gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, self.image_width,
                            self.image_height, 0, gl.GL_RGBA,
                            gl.GL_UNSIGNED_BYTE, self._get_image_data())
            gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER,
                               gl.GL_LINEAR)
            gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                               gl.GL_LINEAR)
            gl.glBindTexture(gl.GL_TEXTURE_2D, 0)
            adb.screencap()

            self.t0 += self.SCREENCAP_INTERVAL
Exemplo n.º 43
0
 def drawBackground(self, textId):
     k = 855.0 / 735.0  # aspect ratio of widget window
     gl.glEnable(gl.GL_TEXTURE_2D)
     gl.glBindTexture(gl.GL_TEXTURE_2D, textId)
     gl.glBegin(gl.GL_QUADS)
     gl.glTexCoord2f(0, 1)
     gl.glVertex2f(-10.0, -10.0 * k)
     gl.glTexCoord2f(1, 1)
     gl.glVertex2f(10.0, -10.0 * k)
     gl.glTexCoord2f(1, 0)
     gl.glVertex2f(10.0, 10.0 * k)
     gl.glTexCoord2f(0, 0)
     gl.glVertex2f(-10.0, 10.0 * k)
     gl.glEnd()
     gl.glDisable(gl.GL_TEXTURE_2D)
Exemplo n.º 44
0
    def paintGL(self):
        GL.glClearColor(0.5, 0.5, 0.5, 1.0)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glLoadIdentity()

        translateX = (len(self._texture) * self._width) / 2

        if len(self._texture) > 0:
            GL.glTranslatef(-translateX, -self._height / 2, -self._zoom)

            GL.glDisable(GL.GL_TEXTURE_2D)
            GL.glColor4f(0.5, 0.5, 0.5, 1.0)
            GL.glBegin(GL.GL_QUADS)
            GL.glVertex3f(20, -20, -.001)
            GL.glVertex3f(20, 20, -.001)
            GL.glVertex3f(-20, 20, -.001)
            GL.glVertex3f(-20, -20, -.001)
            GL.glEnd()

            GL.glColor4f(1, 1, 1, 1.0)

            GL.glEnable(GL.GL_TEXTURE_2D)

            for texture_index in range(0, len(self._texture)):
                if texture_index > 0: GL.glTranslatef(self._width, 0, 0)

                GL.glBindTexture(GL.GL_TEXTURE_2D,
                                 self._texture[texture_index])

                if self._mouseRightDown:
                    self.drawVideo(self._width, self._height,
                                   self._x - (self._lastGlX - self._glX),
                                   self._y - (self._lastGlY - self._glY), 0.0)
                else:
                    self.drawVideo(self._width, self._height, self._x, self._y,
                                   0.0)

            if self._mouseDown:
                modelview = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)
                projection = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX)
                viewport = GL.glGetIntegerv(GL.GL_VIEWPORT)
                winX = float(self._mouseX)
                winY = float(viewport[3] - self._mouseY)
                winZ = GL.glReadPixels(winX, winY, 1, 1, GL.GL_DEPTH_COMPONENT,
                                       GL.GL_FLOAT)
                self._glX, self._glY, self._glZ = GLU.gluUnProject(
                    winX, winY, winZ[0][0], modelview, projection, viewport)
Exemplo n.º 45
0
def render(window, resources):
    gl.glClearColor(0.6, 0.5, 0.7, 1.0)
    window.clear()

    gl.glUseProgram(resources.shader_program)

    gl.glUniform1f(resources.uniforms.fade_factor, 0.5)

    gl.glActiveTexture(gl.GL_TEXTURE0)
    gl.glBindTexture(gl.GL_TEXTURE_2D, resources.textures[0])
    gl.glUniform1i(resources.uniforms.textures[0], 0)

    gl.glActiveTexture(gl.GL_TEXTURE1)
    gl.glBindTexture(gl.GL_TEXTURE_2D, resources.textures[1])
    gl.glUniform1i(resources.uniforms.textures[1], 1)

    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, resources.vertex_buffer)
    gl.glEnableVertexAttribArray(resources.attributes.position)
    gl.glVertexAttribPointer(
        resources.attributes.position,
        2,  # size (position has 2 components?)
        gl.GL_FLOAT,  # type
        gl.GL_FALSE,  # normalized?
        sizeof(gl.GLfloat) * 2,  # stride
        gl.GLuint(0),  # array buffer offset
    )

    #gl.glColor3ub(100, 150, 50)
    #gl.glBegin(gl.GL_TRIANGLES)
    #scale = 1.0/500
    #gl.glVertex(100.0 * scale, +100.0 * scale)
    #gl.glVertex(200.0 * scale, +300.0 * scale)
    #gl.glVertex(300.0 * scale, +100.0 * scale)
    #gl.glEnd()

    gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, resources.element_buffer)

    gl.glDrawElements(
        gl.GL_TRIANGLE_STRIP,  # mode
        len(element_data),  # element count
        gl.GL_UNSIGNED_SHORT,  # type TODO, may not be bytes in future
        0  # element array buffer offset
    )

    gl.glDisableVertexAttribArray(resources.attributes.position)

    window.invalid = False
    return pyglet.event.EVENT_HANDLED
Exemplo n.º 46
0
    def render_mesh(self,
                    position,
                    uv,
                    normal,
                    face=None,
                    clear_color=[0, 0, 0, 0],
                    texture=None,
                    modelview=np.eye(4)):
        MVP = modelview.T.dot(self.proj_matrix())
        MVP = np.ascontiguousarray(MVP, np.float32)
        MV = np.ascontiguousarray(modelview, np.float32)
        position = np.ascontiguousarray(position, np.float32)
        with self.fbo:
            gl.glClearColor(*clear_color)
            gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

            with self.shader, self._bind_attrib(0,
                                                position), self._bind_attrib(
                                                    1, uv), self._bind_attrib(
                                                        2, normal):
                gl.glUniformMatrix4fv(self.shader['MVP'], 1, gl.GL_FALSE, MVP)
                gl.glUniformMatrix4fv(self.shader['MV'], 1, gl.GL_TRUE, MV)
                if not texture is None:
                    gl.glUniform1i(self.shader['texture1'], 0)
                    gl.glActiveTexture(gl.GL_TEXTURE0 + 0)
                    gl.glBindTexture(gl.GL_TEXTURE_2D, texture)
                    texture.push_tex()
                gl.glEnable(gl.GL_DEPTH_TEST)
                if face is not None:
                    face = np.ascontiguousarray(face, np.uint32)
                    gl.glDrawElements(gl.GL_TRIANGLES, face.size,
                                      gl.GL_UNSIGNED_INT, face)
                else:
                    vert_n = position.size // position.shape[-1]
                    gl.glDrawArrays(gl.GL_TRIANGLES, 0, vert_n)
                gl.glDisable(gl.GL_DEPTH_TEST)
                if not texture is None:
                    gl.glBindTexture(gl.GL_TEXTURE_2D, 0)

            w, h = self.size
            frame = gl.glReadPixels(0, 0, w, h, gl.GL_RGBA, gl.GL_FLOAT)
            frame = frame.reshape(h, w, 4)  # fix PyOpenGL bug
            frame = frame[::-1]  # verical flip to match GL convention
            depth = gl.glReadPixels(0, 0, w, h, gl.GL_DEPTH_COMPONENT,
                                    gl.GL_FLOAT)
            depth = depth.reshape(h, w, 1)  # fix PyOpenGL bug
            depth = depth[::-1]  # verical flip to match GL convention
            return frame, depth
Exemplo n.º 47
0
    def _draw_texture(self):
        extern_conn = self._get_extern_conn()

        GL.glPushAttrib(GL.GL_ALL_ATTRIB_BITS)
        GL.glActiveTexture(GL.GL_TEXTURE0)
        GL.glBindTexture(GL.GL_TEXTURE_2D, self.tex)
        image = extern_conn.get_image()
        if image:
            GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB8, image['x'],
                            image['y'], 0, GL.GL_BGR, GL.GL_UNSIGNED_BYTE,
                            image['bytes'])
        GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,
                           GL.GL_NEAREST)
        GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,
                           GL.GL_NEAREST)

        GL.glDisable(GL.GL_DEPTH_TEST)
        GL.glDisable(GL.GL_CULL_FACE)
        GL.glDisable(GL.GL_STENCIL_TEST)
        GL.glEnable(GL.GL_TEXTURE_2D)

        GL.glClearColor(0, 0, 1, 1)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT)

        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPushMatrix()
        GL.glLoadIdentity()
        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glPushMatrix()
        GL.glLoadIdentity()

        GL.glBegin(GL.GL_QUADS)
        GL.glColor3f(1.0, 1.0, 1.0)
        GL.glTexCoord2f(0.0, 0.0)
        GL.glVertex3i(-1, -1, 0)
        GL.glTexCoord2f(1.0, 0.0)
        GL.glVertex3i(1, -1, 0)
        GL.glTexCoord2f(1.0, 1.0)
        GL.glVertex3i(1, 1, 0)
        GL.glTexCoord2f(0.0, 1.0)
        GL.glVertex3i(-1, 1, 0)
        GL.glEnd()

        GL.glPopMatrix()
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPopMatrix()

        GL.glPopAttrib()
    def __load_texture(self: 'GLQuadRenderer') -> None:
        img_data = self.__new_texture

        GL.glActiveTexture(GL.GL_TEXTURE0)
        GL.glBindTexture(GL.GL_TEXTURE_2D, 0)

        if self.__texture > 0:
            GL.glDeleteTextures([self.__texture])

        self.__texture = GL.glGenTextures(1)

        GL.glBindTexture(GL.GL_TEXTURE_2D, self.__texture)
        GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, self.__image_width,
                        self.__image_height, 0, GL.GL_RGBA,
                        GL.GL_UNSIGNED_BYTE, img_data)

        GL.glGenerateMipmap(GL.GL_TEXTURE_2D)

        GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,
                           GL.GL_LINEAR)
        GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,
                           GL.GL_LINEAR_MIPMAP_LINEAR)
        GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S,
                           GL.GL_CLAMP_TO_EDGE)
        GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T,
                           GL.GL_CLAMP_TO_EDGE)

        self.resize(self.gl_widget.width, self.gl_widget.height)

        GL.glBindTexture(GL.GL_TEXTURE_2D, self.__texture)
        GL.glUniform1i(self.__uniform_texture, 0)

        GL.glActiveTexture(GL.GL_TEXTURE1)
        self.__data = numpy.zeros(
            (self.__image_width * self.__image_height, 4), dtype=numpy.float32)

        if self.__data_texture > 0:
            GL.glDeleteTextures([self.__data_texture])

        self.__data_texture = GL.glGenTextures(1)
        GL.glBindTexture(GL.GL_TEXTURE_2D, self.__data_texture)
        GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA32F, self.__image_width,
                        self.__image_height, 0, GL.GL_RGBA, GL.GL_FLOAT,
                        self.__data)

        GL.glGenerateMipmap(GL.GL_TEXTURE_2D)
        GL.glBindTexture(GL.GL_TEXTURE_2D, self.__data_texture)
        GL.glUniform1i(self.__uniform_data_texture, 1)
Exemplo n.º 49
0
    def Render(self):
        GL.glBindTexture(GL.GL_TEXTURE_2D, self.texture)
        GL.glBegin(GL.GL_QUADS)
        GL.glNormal(0, 0, 1)
        GL.glTexCoord(0, 0)
        GL.glVertex(0, 0)
        GL.glTexCoord(1, 0)
        GL.glVertex(2048, 0)
        GL.glTexCoord(1, 1)
        GL.glVertex(2048, 2048)
        GL.glTexCoord(0, 1)
        GL.glVertex(0, 2048)
        GL.glEnd()

        for m in self.meshes:
            m.Render()
    def viewerDraw(self):
        """Function called to draw module in Workflow viewer"""
        if self._iconTexture == None:
            self._iconTexture = tools.LoadOpenGLTexture(self._iconTextureFile)

        GL.glPushMatrix()
        GL.glTranslatef(self._viewer_x, self._viewer_y, 0.0)
        GL.glColor4f(self._viewer_color[0], self._viewer_color[1],
                     self._viewer_color[2], 1.0)
        GL.glBindTexture(GL.GL_TEXTURE_2D, self._iconTexture)
        GL.glEnable(GL.GL_TEXTURE_2D)

        tools.drawGLCircle(self._viewer_radius)

        GL.glDisable(GL.GL_TEXTURE_2D)
        GL.glPopMatrix()
Exemplo n.º 51
0
    def assign(self, array: np.array, format: gl.GLenum):
        gl.glBindTexture(gl.GL_TEXTURE_1D, self.id_)

        if array.dtype == np.uint8:
            gl.glTexImage1D(gl.GL_TEXTURE_1D, 0, self.internalFormat_,
                            self.width_, 0, format, gl.GL_UNSIGNED_BYTE, array)
        elif array.dtype == np.uint32:
            gl.glTexImage1D(gl.GL_TEXTURE_1D, 0, self.internalFormat_,
                            self.width_, 0, format, gl.GL_UNSIGNED_INT, array)
        elif array.dtype == np.float32:
            gl.glTexImage1D(gl.GL_TEXTURE_1D, 0, self.internalFormat_,
                            self.width_, 0, format, gl.GL_FLOAT, array)
        else:
            raise NotImplementedError("pixel type not implemented.")

        gl.glBindTexture(gl.GL_TEXTURE_2D, 0)
Exemplo n.º 52
0
    def render(self) -> None:
        GL.glBindTexture(GL.GL_TEXTURE_2D, self._texture_id)

        GL.glBindVertexArray(self._vao)
        GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self._vbo)
        GL.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, self._ibo)

        GL.glEnableVertexAttribArray(0)
        GL.glVertexAttribPointer(0, 3, GL.GL_FLOAT, GL.GL_FALSE, 0, None)

        GL.glDrawElements(GL.GL_TRIANGLES, 4 * self._index_count,
                          GL.GL_UNSIGNED_INT, None)

        GL.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0)
        GL.glBindBuffer(GL.GL_ARRAY_BUFFER, 0)
        GL.glBindVertexArray(0)
Exemplo n.º 53
0
 def createEmptyTexture(self, width, height):
     textureId = gl.glGenTextures(1, gl.GLuint * 1)
     gl.glBindTexture(gl.GL_TEXTURE_2D, textureId)
     gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S,
                        gl.GL_CLAMP_TO_EDGE)
     gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T,
                        gl.GL_CLAMP_TO_EDGE)
     gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER,
                        gl.GL_NEAREST)
     gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                        gl.GL_NEAREST)
     # None means reserve texture memory, but texels are undefined
     gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA8, width, height, 0,
                     gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, None)
     gl.glBindTexture(gl.GL_TEXTURE_2D, 0)
     return textureId
Exemplo n.º 54
0
    def draw(self):
        """  Draw background image using a quad. """
        GL.glUseProgram(self.shader.glid)

        # projection geometry
        loc = GL.glGetUniformLocation(self.shader.glid, 'modelviewprojection')
        GL.glUniformMatrix4fv(loc, 1, True, np.eye(4))

        loc = GL.glGetUniformLocation(self.shader.glid, 'color')
        GL.glUniform3fv(loc, 1, self.color)

        self.vertex_array.execute(GL.GL_TRIANGLES)

        # leave clean state for easier debugging
        GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
        GL.glUseProgram(0)
Exemplo n.º 55
0
 def loadTex(self, image):
     im = open(image)
     ix, iy, image = im.size[0], im.size[1], im.tobytes("raw", "RGB")
     imdata = np.fromstring(image, np.uint8)
     # Create new texture ID for OpenGL
     ID = gl.glGenTextures(1)
     # Make 1D Texture
     gl.glBindTexture(gl.GL_TEXTURE_1D, ID)
     gl.glTexParameteri(gl.GL_TEXTURE_1D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST);
     gl.glTexParameteri(gl.GL_TEXTURE_1D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST);
     gl.glTexParameteri(gl.GL_TEXTURE_1D, gl.GL_TEXTURE_WRAP_S, gl.GL_REPEAT);
     gl.glTexImage1D(
         gl.GL_TEXTURE_1D, 0, gl.GL_RGB8, 256, 0,
         gl.GL_RGB, gl.GL_UNSIGNED_BYTE, imdata
     )
     return ID
Exemplo n.º 56
0
 def gl_program_configure(self, program: ShaderProgram) -> None:
     if self.base_texture is not None:
         GL.glActiveTexture(GL.GL_TEXTURE0)
         GL.glBindTexture(GL.GL_TEXTURE_2D, self.base_texture.texture)
         program.set_uniform_if("uMaterial.base_texture",
                                lambda u: GL.glUniform1i(u, 0))
         pass
     program.set_uniform_if(
         "uMaterial.base_color", lambda u: GL.glUniform4f(
             u,
             self.color[0],
             self.color[1],
             self.color[2],
             self.color[3],
         ))
     pass
Exemplo n.º 57
0
    def draw(self):
        loc = gl.glGetUniformLocation(self.program, "tex")
        gl.glUniform1i(loc, 0)
        gl.glActiveTexture(gl.GL_TEXTURE0)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.tex)
        gl.glGenerateMipmap(gl.GL_TEXTURE_2D)

        loc = gl.glGetUniformLocation(self.program, "lamptex")
        gl.glUniform1i(loc, 1)
        gl.glActiveTexture(gl.GL_TEXTURE1)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.lamptex)

        loc = gl.glGetUniformLocation(self.program, "max_id")
        gl.glUniform1i(loc, len(self.lamps))

        super(signalgenerator, self).draw()
Exemplo n.º 58
0
    def on_display():
        #gl.glClearColor(0,0,0,1)
        gl.glClearColor(1, 1, 1, 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glBindTexture(gl.GL_TEXTURE_2D, atlas.texid)
        for label in labels:
            label.draw()

        gl.glColor(0, 0, 0, 1)
        gl.glBegin(gl.GL_LINES)
        gl.glVertex2i(15, 0)
        gl.glVertex2i(15, 330)
        gl.glVertex2i(225, 0)
        gl.glVertex2i(225, 330)
        gl.glEnd()
        glut.glutSwapBuffers()
Exemplo n.º 59
0
 def Draw_Power_Ups(self,powerups):
   i = 0
   for powerup in powerups:
     # power-up
     OGL.glBindTexture(OGL.GL_TEXTURE_2D,self.textures[powerup])
     OGL.glBegin(OGL.GL_QUADS)
     OGL.glTexCoord2d(0,0)
     OGL.glVertex2d((SCREEN_SIZE[0]-74),(SCREEN_SIZE[1]-74-(64*i)))
     OGL.glTexCoord2d(1,0)
     OGL.glVertex2d((SCREEN_SIZE[0]-10),(SCREEN_SIZE[1]-74-(64*i)))
     OGL.glTexCoord2d(1,1)
     OGL.glVertex2d((SCREEN_SIZE[0]-10),(SCREEN_SIZE[1]-10-(64*i)))
     OGL.glTexCoord2d(0,1)
     OGL.glVertex2d((SCREEN_SIZE[0]-74),(SCREEN_SIZE[1]-10-(64*i)))
     OGL.glEnd()
     i = i + 1
Exemplo n.º 60
0
    def render(self, parent: Actor, uniLoc: UniformLocs) -> None:
        gl.glBindVertexArray(self.vao_i)

        gl.glActiveTexture(gl.GL_TEXTURE0)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.diffuseMap_i)

        gl.glUniformMatrix4fv(uniLoc.modelMatrix, 1, gl.GL_FALSE,
                              self.getModelMatrix(parent))

        gl.glUniform1f(uniLoc.textureVerNum_f, self.textureVerNum_f)
        gl.glUniform1f(uniLoc.textureHorNum_f, self.textureHorNum_f)

        gl.glUniform1f(uniLoc.shininess, self.shininess_f)
        gl.glUniform1f(uniLoc.specularStrength, self.specularStrength_f)

        gl.glDrawArrays(gl.GL_TRIANGLES, 0, self.vertexSize_i)