def render_to_texture():
    # select the target to draw into
    gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, framebuffer)
    draw_buffers = (gl.GLenum * 1)(gl.GL_COLOR_ATTACHMENT0)
    gl.glDrawBuffers(1, draw_buffers)
    gl.glViewport(0, 0, FB_WIDTH, FB_HEIGHT)

    # clear the destination
    gl.glClearColor(0.5, 0.6, 0.7, 1.0)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

    # prepare the rendering
    gl.glUseProgram(render_program)

    # send the vertex data
    data = (COLOR_VERTEX * 3)(((-0.6, -0.5), (1.0, 0.0, 0.0, 1.0)),
                      ((0.6, -0.5), (0.0, 1.0, 0.0, 1.0)),
                      ((0.0, 0.5), (0.0, 0.0, 1.0, 1.0)))

    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, render_vertexbuffer)
    gl.glBufferData(gl.GL_ARRAY_BUFFER, ctypes.sizeof(data), data, gl.GL_DYNAMIC_DRAW)

    # draw using the vertex array for vertex information
    gl.glBindVertexArray(render_vao)
    gl.glDrawArrays(gl.GL_TRIANGLES, 0, 3)
    gl.glBindVertexArray(0)
def copy_texture_to_screen():
    # select the target to draw into
    gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, 0)
    gl.glViewport(0, 0, window.width, window.height)

    # clear the destination
    gl.glClearColor(0.4, 0.4, 0.4, 1.0)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

    # select the program for drawing
    gl.glUseProgram(copy_program)

    # send the vertex data
    data = (TEXTURE_VERTEX * 8)(((-0.9, -0.9), (0.0, 0.0)),
                                ((0.5, -0.9), (1.0, 0.0)),
                                ((0.5, 0.5), (1.0, 1.0)),
                                ((-0.9, 0.5), (0.0, 1.0)),

                                ((0.6, 0.6), (0.0, 1.0)),
                                ((1.0, 0.6), (1.0, 1.0)),
                                ((1.0, 1.0), (1.0, 0.0)),
                                ((0.6, 1.0), (0.0, 0.0)),
                                )

    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, copy_vertexbuffer)
    gl.glBufferData(gl.GL_ARRAY_BUFFER, ctypes.sizeof(data), data, gl.GL_DYNAMIC_DRAW)


    # draw
    gl.glBindVertexArray(copy_vao)
    gl.glDrawArrays(gl.GL_QUADS, 0, 8)
    gl.glBindVertexArray(0)
示例#3
0
    def draw(self, win=None):
        """Draw the current frame to a particular visual.Window (or to the
        default win for this object if not specified). The current
        position in the movie will be determined automatically.

        This method should be called on every frame that the movie is
        meant to appear.
        """

        if (self.status == NOT_STARTED or
                (self.status == FINISHED and self.loop)):
            self.play()
        elif self.status == FINISHED and not self.loop:
            return
        if win is None:
            win = self.win
        self._selectWindow(win)
        self._updateFrameTexture()  # will check if it's needed

        # scale the drawing frame and get to centre of field
        GL.glPushMatrix()  # push before drawing, pop after
        # push the data for client attributes
        GL.glPushClientAttrib(GL.GL_CLIENT_ALL_ATTRIB_BITS)

        self.win.setScale('pix')
        # move to centre of stimulus and rotate
        vertsPix = self.verticesPix

        # bind textures
        GL.glActiveTexture(GL.GL_TEXTURE1)
        GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
        GL.glEnable(GL.GL_TEXTURE_2D)
        GL.glActiveTexture(GL.GL_TEXTURE0)
        GL.glBindTexture(GL.GL_TEXTURE_2D, self._texID)
        GL.glEnable(GL.GL_TEXTURE_2D)

        # sets opacity (1,1,1 = RGB placeholder)
        GL.glColor4f(1, 1, 1, self.opacity)

        array = (GL.GLfloat * 32)(
            1, 1,  # texture coords
            vertsPix[0, 0], vertsPix[0, 1], 0.,  # vertex
            0, 1,
            vertsPix[1, 0], vertsPix[1, 1], 0.,
            0, 0,
            vertsPix[2, 0], vertsPix[2, 1], 0.,
            1, 0,
            vertsPix[3, 0], vertsPix[3, 1], 0.,
        )

        # 2D texture array, 3D vertex array
        GL.glInterleavedArrays(GL.GL_T2F_V3F, 0, array)
        GL.glDrawArrays(GL.GL_QUADS, 0, 4)
        GL.glPopClientAttrib()
        GL.glPopAttrib()
        GL.glPopMatrix()
        # unbind the textures
        GL.glActiveTexture(GL.GL_TEXTURE0)
        GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
        GL.glEnable(GL.GL_TEXTURE_2D)  # implicitly disables 1D
示例#4
0
 def draw(self, transformation, **kwargs):
     transformation.scale(self.width, self.height, 1)
     color = self.color + (self.opacity,)
     gl.glColor4fv((gl.GLfloat * 4)(*color))
     gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
     gl.glVertexPointer(2, gl.GL_FLOAT, 0, self.vertices)
     gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
def update_display(verts,tex_coords,texture=bird_texture):
    gl.glClearColor(0.2, 0.4, 0.5, 1.0)

    gl.glEnable(texture.target)
    gl.glBindTexture(texture.target, texture.id)

    gl.glPushAttrib(gl.GL_COLOR_BUFFER_BIT)
   
    gl.glEnable(gl.GL_ALPHA_TEST)                                                            
    gl.glAlphaFunc (gl.GL_GREATER, .1)                             
    #gl.glEnable(gl.GL_BLEND)                                                            
    #gl.glBlendFunc (gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)                             
    gl.glEnable(gl.GL_DEPTH_TEST) 

    gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
    gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)

    n=len(verts[:])
    #TODO verts._buffer.ctypes.data is awkward
    gl.glVertexPointer(3, vert_dtype.gl, 0, verts[:].ctypes.data)
    gl.glTexCoordPointer(3, tex_dtype.gl, 0, tex_coords[:].ctypes.data)
    gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, n)
    #unset state
    gl.glPopAttrib()
    gl.glDisable(texture.target)
示例#6
0
    def draw(self):
        '''
        Draw the windows.
        '''
        self.program.use()

        data = list(self.root.get_data(0, 0))
        data = (gl.GLfloat * len(data))(*data)

        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.buffer)
        gl.glBufferData(gl.GL_ARRAY_BUFFER, sizeof(data), data, gl.GL_DYNAMIC_DRAW)

        gl.glActiveTexture(gl.GL_TEXTURE0)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.texture)
        if self.textmanager.dirty:
            # only upload the texture to the GPU if it has actually changed
            gl.glTexImage2D(gl.GL_TEXTURE_2D,
                     0,  # level
                     gl.GL_R8,
                     self.textmanager.width,
                     self.textmanager.height,
                     0,
                     gl.GL_RED,
                     gl.GL_UNSIGNED_BYTE,
                     ctypes.create_string_buffer(self.textmanager.img.tobytes()))
            self.textmanager.dirty = False
        self.program.uniform1i(b"tex", 0)  # set to 0 because the texture is bound to GL_TEXTURE0

        self.program.vertex_attrib_pointer(self.buffer, b"position", 4)
        # self.program.vertex_attrib_pointer(self.buffer, b"texcoord", 2, stride=4 * sizeof(gl.GLfloat), offset=2 * sizeof(gl.GLfloat))
        gl.glDrawArrays(gl.GL_QUADS, 0, len(data) // 4)
示例#7
0
    def on_draw(self):
        """
        Render the screen.
        """
        start = time.time()

        float_size = ctypes.sizeof(ctypes.c_float)
        record_len = 10 * float_size

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

        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glEnableClientState(GL.GL_VERTEX_ARRAY)

        GL.glColor4ub(255, 0, 0, 255)

        GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.rect_vbo.vbo_id)
        GL.glVertexPointer(2, GL.GL_FLOAT, record_len, 0)

        for i in range(len(self.shape_list)):
            shape = self.shape_list[i]
            GL.glLoadIdentity()
            GL.glTranslatef(shape.x, shape.y, 0)
            GL.glDrawArrays(GL.GL_QUADS, i * 8, 8)
        # GL.glDrawArrays(GL.GL_QUADS,
        #           0,
        #           self.rect_vbo.size)

        elapsed = time.time() - start
        print(elapsed)
示例#8
0
    def draw_bounding_box(self, x, y, screen_height):
        bb = self.get_bounding_box()
        bb = [bb['min_x'], bb['min_y'], bb['max_x'], bb['max_y']]
        vertices = ()
        for _ in bb:
            vertices += (_.x,)
            vertices += (screen_height - _.y,)

        # get opengl vertices of type GLfloat
        vertices_gl = (GLfloat * len(vertices))(*vertices)

        # set the color
        glColor4ub(0, 255, 0, 255);
        glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );

        # turn on blend for alpha channel
        glEnable(GL_BLEND)

        # tell open GL were passing a vertex array
        glEnableClientState(GL_VERTEX_ARRAY)

        # create a pointer to vertices_gl
        glVertexPointer(2, GL_FLOAT, 0, vertices_gl)
       
        # draw the array
        glDrawArrays(GL_POLYGON, 0, len(vertices) // 2)

        glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
示例#9
0
文件: movie3.py 项目: qenops/psychopy
    def draw(self, win=None):
        """Draw the current frame to a particular visual.Window (or to the
        default win for this object if not specified). The current
        position in the movie will be determined automatically.

        This method should be called on every frame that the movie is
        meant to appear.
        """

        if (self.status == NOT_STARTED or
                (self.status == FINISHED and self.loop)):
            self.play()
        elif self.status == FINISHED and not self.loop:
            return
        if win is None:
            win = self.win
        self._selectWindow(win)
        self._updateFrameTexture()  # will check if it's needed

        # scale the drawing frame and get to centre of field
        GL.glPushMatrix()  # push before drawing, pop after
        # push the data for client attributes
        GL.glPushClientAttrib(GL.GL_CLIENT_ALL_ATTRIB_BITS)

        self.win.setScale('pix')
        # move to centre of stimulus and rotate
        vertsPix = self.verticesPix

        # bind textures
        GL.glActiveTexture(GL.GL_TEXTURE1)
        GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
        GL.glEnable(GL.GL_TEXTURE_2D)
        GL.glActiveTexture(GL.GL_TEXTURE0)
        GL.glBindTexture(GL.GL_TEXTURE_2D, self._texID)
        GL.glEnable(GL.GL_TEXTURE_2D)

        # sets opacity (1,1,1 = RGB placeholder)
        GL.glColor4f(1, 1, 1, self.opacity)

        array = (GL.GLfloat * 32)(
            1, 1,  # texture coords
            vertsPix[0, 0], vertsPix[0, 1], 0.,  # vertex
            0, 1,
            vertsPix[1, 0], vertsPix[1, 1], 0.,
            0, 0,
            vertsPix[2, 0], vertsPix[2, 1], 0.,
            1, 0,
            vertsPix[3, 0], vertsPix[3, 1], 0.,
        )

        # 2D texture array, 3D vertex array
        GL.glInterleavedArrays(GL.GL_T2F_V3F, 0, array)
        GL.glDrawArrays(GL.GL_QUADS, 0, 4)
        GL.glPopClientAttrib()
        GL.glPopMatrix()
        # unbind the textures
        GL.glActiveTexture(GL.GL_TEXTURE0)
        GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
        GL.glEnable(GL.GL_TEXTURE_2D)  # implicitly disables 1D
示例#10
0
    def batch_draw(csl):
        glPushMatrix()
        glLoadIdentity()

        vertices = []
        for cs in csl:
            ax, ay = cs.abs_coords()
            if cs.ft_anim:
                qs = cs.question_scale
                bs = cs.back_scale
                aa = cs.ftanim_alpha
                ca = cs.ftanim_cardalpha
                if cs.gray:
                    c = (.66, .66, .66, ca)
                else:
                    c = (1., 1., 1., ca)
                vertices += cs.img.get_t2c4n3v3_vertices(c, ax, ay)

                n, s = cs.number, cs.suit
                if n: vertices += game_res.cardnum[s % 2 * 13 + n - 1].get_t2c4n3v3_vertices(c, ax + 5, ay + 105)
                if s: vertices += game_res.suit[s - 1].get_t2c4n3v3_vertices(c, ax + 6, ay + 94)

                c = (1, 1, 1, aa)

                if qs:
                    vertices += game_res.card_question.get_t2c4n3v3_vertices(c, ax+(1-qs)*45, ay, 0, qs*91)

                if bs:
                    vertices += game_res.card_hidden.get_t2c4n3v3_vertices(c, ax+(1-bs)*45, ay, 0, bs*91)
            else:
                a = cs.alpha
                if cs.gray:
                    c = (.66, .66, .66, a)
                else:
                    c = (1., 1., 1., a)
                vertices += cs.img.get_t2c4n3v3_vertices(c, ax, ay)
                resides_in = cs.card.resides_in
                if resides_in and resides_in.type == 'showncards':
                    vertices += game_res.card_showncardtag.get_t2c4n3v3_vertices(c, ax, ay)

                n, s = cs.number, cs.suit
                if n: vertices += game_res.cardnum[s % 2 * 13 + n - 1].get_t2c4n3v3_vertices(c, ax + 5, ay + 105)
                if s: vertices += game_res.suit[s-1].get_t2c4n3v3_vertices(c, ax+6, ay+94)

                vertices += game_res.card_shinesoft.get_t2c4n3v3_vertices(
                    (1., 1., 1., cs.shine_alpha), ax-6, ay-6
                )

        if vertices:
            n = len(vertices)
            buf = (GLfloat*n)()
            buf[:] = vertices
            glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT)
            glInterleavedArrays(GL_T2F_C4F_N3F_V3F, 0, buf)
            with get_atlas('card').texture:
                glDrawArrays(GL_QUADS, 0, n/12)
            glPopClientAttrib()

        glPopMatrix()
示例#11
0
    def draw(self):
        """Draw the text to the back buffer"""
        # Border width
        self.box.setLineWidth(
            self.palette['lineWidth'])  # Use 1 as base if border width is none
        #self.borderWidth = self.box.lineWidth
        # Border colour
        self.box.setLineColor(self.palette['lineColor'], colorSpace='rgb')
        #self.borderColor = self.box.lineColor
        # Background
        self.box.setFillColor(self.palette['fillColor'], colorSpace='rgb')
        #self.fillColor = self.box.fillColor

        if self._needVertexUpdate:
            #print("Updating vertices...")
            self._updateVertices()
        if self.fillColor is not None or self.borderColor is not None:
            self.box.draw()

        # self.boundingBox.draw()  # could draw for debug purposes
        gl.glPushMatrix()
        self.win.setScale('pix')

        gl.glActiveTexture(gl.GL_TEXTURE0)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.glFont.textureID)
        gl.glEnable(gl.GL_TEXTURE_2D)
        gl.glDisable(gl.GL_DEPTH_TEST)

        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
        gl.glEnableClientState(gl.GL_COLOR_ARRAY)
        gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)

        gl.glVertexPointer(2, gl.GL_DOUBLE, 0, self.verticesPix.ctypes)
        gl.glColorPointer(4, gl.GL_DOUBLE, 0, self._colors.ctypes)
        gl.glTexCoordPointer(2, gl.GL_DOUBLE, 0, self._texcoords.ctypes)

        self.shader.bind()
        self.shader.setInt('texture', 0)
        self.shader.setFloat('pixel', [1.0 / 512, 1.0 / 512])
        nVerts = len(self._text) * 4

        gl.glDrawArrays(gl.GL_QUADS, 0, nVerts)
        self.shader.unbind()

        # removed the colors and font texture
        gl.glDisableClientState(gl.GL_COLOR_ARRAY)
        gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY)
        gl.glDisableVertexAttribArray(1)
        gl.glDisableClientState(gl.GL_VERTEX_ARRAY)

        gl.glActiveTexture(gl.GL_TEXTURE0)
        gl.glBindTexture(gl.GL_TEXTURE_2D, 0)
        gl.glDisable(gl.GL_TEXTURE_2D)

        if self.hasFocus:  # draw caret line
            self.caret.draw()

        gl.glPopMatrix()
示例#12
0
 def on_draw(self):
     gl.glClearColor(0, 0, 0, 0)
     self.clear()
     gl.glViewport(0, 0, self.width, self.height)
     with self.shader:
         self.shader.uniformf("iTime",
                              time.perf_counter() - self._start_time)
         gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
示例#13
0
def drawArray(someArray):
    # x = (ctypes.c_float * len(someArray))(*someArray[:][0])
    # y = (ctypes.c_float * len(someArray))(*someArray[:][1])
    # vertPoints = list(zip(x,y))
    #someArray = np.array(someArray)
    vertPoints = someArray[:, :2].flatten().astype(ctypes.c_float)
    gl.glVertexPointer(2, gl.GL_FLOAT, 0, vertPoints.ctypes.data)
    gl.glDrawArrays(gl.GL_POINTS, 0, len(vertPoints) // 2)
示例#14
0
 def render(self):
     gl.glUseProgram(self.programA)
     gl.glUniform1i(self.tex_pos_A, 0)
     for i in range(args["outResolution"]):
         gl.glUniform1i(self.slice_pos_A, i)
         gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, self.framebufferA0[i])
         gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
         gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6)
示例#15
0
 def on_draw(self):
     gl.glClearColor(0, 0, 0, 0)
     self.clear()
     gl.glViewport(0, 0, self.width, self.height)
     now = time.clock() - self._start_time
     now *= 20
     with self.shader:
         self.shader.uniformf("iTime", now)
         gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
示例#16
0
    def draw(self):
        """TL.draw()

        Draws the triangle list on screen.
        """

        gl.glDrawArrays(
            gl.GL_TRIANGLES, 0,
            self.__count * VERTICES_PER_TRIANGLE)
示例#17
0
def render_rect_filled(shape, offset):
    """ Render the shape at the right spot. """
    # Set color
    GL.glLoadIdentity()
    GL.glColor3ub(shape.color[0], shape.color[1], shape.color[2])

    GL.glTranslatef(shape.x + shape.width / 2, shape.y + shape.height / 2, 0)

    GL.glDrawArrays(GL.GL_QUADS, offset, 4)
def stripped_render(shape: VertexBuffer):
    """
    Render an shape previously created with a ``create`` function.
    Used by ``ShapeElementList.draw()`` for drawing several shapes in a batch.
    """

    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, shape.vbo_vertex_id)
    gl.glVertexPointer(2, gl.GL_FLOAT, 0, 0)
    gl.glDrawArrays(shape.draw_mode, 0, shape.size)
示例#19
0
 def on_draw(self):
     #self.clear()
     #self.set_3d()
     # Draw world stuff
     #glColor3d(1, 1, 1)
     # self.world.batch.draw()
     glClearColor(0.5, 0.1, 0.1, 1.0)
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
     glBindVertexArray(self.world.chunk.vao)
     glDrawArrays(GL_TRIANGLES, 0, 3)
示例#20
0
def render(shape):
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    gl.glLoadIdentity()
    gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
    gl.glEnableClientState(gl.GL_COLOR_ARRAY)
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, shape.vbo_id)
    gl.glVertexPointer(2, gl.GL_FLOAT, 0, None)
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, shape.vbo_color_id)
    gl.glColorPointer(4, gl.GL_FLOAT, 0, None)
    gl.glDrawArrays(shape.draw_mode, 0, shape.size)
示例#21
0
def draw():
    data = (VERTEX * 3)(((-0.6, -0.5), (1.0, 0.0, 0.0, 1.0)),
                      ((0.6, -0.5), (0.0, 1.0, 0.0, 1.0)),
                      ((0.0, 0.5), (0.0, 0.0, 1.0, 1.0)))

    gl.glClearColor(0.5, 0.6, 0.7, 1.0)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vertexbuffer)
    gl.glBufferData(gl.GL_ARRAY_BUFFER, ctypes.sizeof(data), data, gl.GL_DYNAMIC_DRAW)
    gl.glDrawArrays(gl.GL_TRIANGLES, 0, 3)
示例#22
0
文件: graphix.py 项目: leovt/openpark
    def copy(self):
        ''' copy the contents of the texture to full window '''
        gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, 0)

        self.program.use()

        gl.glActiveTexture(gl.GL_TEXTURE0)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.rendered_texture)
        self.program.uniform1i(b"tex", 0)
        self.program.vertex_attrib_pointer(self.vertex_buffer, b"position", 4, stride=4 * sizeof(gl.GLfloat))
        gl.glDrawArrays(gl.GL_QUADS, 0, 4)
示例#23
0
    def on_draw(self):
        gl.glClearColor(0, 0, 0, 0)
        self.clear()
        gl.glViewport(0, 0, self.width, self.height)
        with self.shader:
            self.shader.uniformf("iTime", time.clock() - self._start_time)
            gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)

        if self.video_on and (self.frame_count % self.sample_rate == 0):
            self.write_video_frame()

        self.frame_count += 1
示例#24
0
 def _draw_mouse_cursor(self):
     """ If the mouse is over the image, draw a cursom crosshair. """
     if self.mouse_position is None:
         return
     x, y = self.mouse_position
     w, h = self.get_size()
     vm = self._make_cursor_view_matrix(x, y)
     with self.mouse_texture:
         gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA)
         gl.glUniformMatrix4fv(0, 1, gl.GL_FALSE, (gl.GLfloat * 16)(*vm))
         gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6)
         gl.glBlendFunc(gl.GL_ONE, gl.GL_ZERO)
def stripped_render_with_colors(shape: VertexBuffer):
    """
    Render an shape previously created with a ``create`` function.
    Used by ``ShapeElementList.draw()`` for drawing several shapes in a batch.
    This version also assumes there is a color list as part of the VBO.
    """

    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, shape.vbo_vertex_id)
    gl.glVertexPointer(2, gl.GL_FLOAT, 0, None)
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, shape.vbo_color_id)
    gl.glColorPointer(4, gl.GL_FLOAT, 0, None)
    gl.glDrawArrays(shape.draw_mode, 0, shape.size)
示例#26
0
    def draw(self):
        gl.glClearColor(0.2, 0.4, 0.5, 1.0)
        gl.glBlendFunc (gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)                             
        gl.glEnable (gl.GL_BLEND)                                                            
        gl.glEnable (gl.GL_LINE_SMOOTH);                                                     
        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
        gl.glEnableClientState(gl.GL_COLOR_ARRAY)

        #TODO verts._buffer.ctypes.data is awkward
        gl.glVertexPointer(2, self.vert_dtype.gl, 0, self.verts._buffer.ctypes.data)
        gl.glColorPointer(3,  self.color_dtype.gl, 0, self.colors._buffer.ctypes.data)
        gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, len(self.verts._buffer)//2)
示例#27
0
    def batch_draw_status(gcps):
        glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT)
        vertices = []
        for port in gcps:
            p = port.player
            if not getattr(p, 'ui_meta', False): continue

            hp = game_res.hp; hp_bg = game_res.hp_bg
            if getattr(p, 'dead', False):
                hp = hp.grayed
                hp_bg = hp_bg.grayed

            # hp bar
            w = hp.width
            x = port.x; y = port.y
            for i in xrange(getattr(p, 'maxlife', 0)):
                vertices.extend(
                    hp_bg.get_t4f_v4f_vertices(5+x+i*w, 56+y)
                )

            for i in xrange(max(getattr(p, 'life', 0), 0)):
                vertices.extend(
                    hp.get_t4f_v4f_vertices(5+x+i*w, 56+y)
                )

        nums = game_res.num
        for port in gcps:
            x, y, w, h = port.x, port.y, port.width, port.height
            p = port.player
            try:
                n = len(p.cards) + len(p.showncards)
                seq = str(n)
                ox = (32 - len(seq)*14)//2
                for i, ch in enumerate(seq):
                    n = ord(ch) - ord('0')
                    #x, y = w - 34 + ox + i*14, 68
                    vertices.extend(nums[n].get_t4f_v4f_vertices(
                        x + w - 34 + ox + i*14,
                        y + 68
                    ))
            except AttributeError:
                pass

        if vertices:
            with nums[0].owner:
                n = len(vertices)
                buf = (GLfloat*n)()
                buf[:] = vertices
                glInterleavedArrays(GL_T4F_V4F, 0, buf)
                glDrawArrays(GL_QUADS, 0, n/8)

        glPopClientAttrib()
示例#28
0
文件: particle.py 项目: fpietka/cocos
    def draw_fallback(self):
        """Called instead of :meth:`draw` when quads are used instead of
        Point Sprite.
        """
        self.make_delta_pos_to_vertex()
        self.update_vertexs_from_pos()
        self.update_per_vertex_colors()

        gl.glPushMatrix()
        self.transform()

        # color preserve - at least intel 945G needs that
        gl.glPushAttrib(gl.GL_CURRENT_BIT)

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

        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
        vertexs_ptr = PointerToNumpy(self.vertexs)
        gl.glVertexPointer(2, gl.GL_FLOAT, 0, vertexs_ptr)

        gl.glEnableClientState(gl.GL_COLOR_ARRAY)
        color_ptr = PointerToNumpy(self.per_vertex_colors)
        # gl.glColorPointer(4, gl.GL_UNSIGNED_BYTE, 0, color_ptr)
        gl.glColorPointer(4, gl.GL_FLOAT, 0, color_ptr)

        gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
        tex_coord_ptr = PointerToNumpy(self.tex_coords)
        gl.glTexCoordPointer(2, gl.GL_FLOAT, 0, tex_coord_ptr)

        gl.glPushAttrib(gl.GL_COLOR_BUFFER_BIT)
        gl.glEnable(gl.GL_BLEND)
        if self.blend_additive:
            gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE)
        else:
            gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        gl.glDrawArrays(gl.GL_QUADS, 0, len(self.vertexs) * 4)

        # un -blend
        gl.glPopAttrib()

        # color restore
        gl.glPopAttrib()

        # disable states
        gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY)
        gl.glDisableClientState(gl.GL_COLOR_ARRAY)
        gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
        gl.glDisable(gl.GL_TEXTURE_2D)

        gl.glPopMatrix()
示例#29
0
    def draw_fallback(self):
        """Called instead of :meth:`draw` when quads are used instead of
        Point Sprite.
        """
        self.make_delta_pos_to_vertex()
        self.update_vertexs_from_pos()
        self.update_per_vertex_colors()

        gl.glPushMatrix()
        self.transform()

        # color preserve - at least intel 945G needs that
        gl.glPushAttrib(gl.GL_CURRENT_BIT)

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

        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
        vertexs_ptr = PointerToNumpy(self.vertexs)
        gl.glVertexPointer(2, gl.GL_FLOAT, 0, vertexs_ptr)

        gl.glEnableClientState(gl.GL_COLOR_ARRAY)
        color_ptr = PointerToNumpy(self.per_vertex_colors)
        # gl.glColorPointer(4, gl.GL_UNSIGNED_BYTE, 0, color_ptr)
        gl.glColorPointer(4, gl.GL_FLOAT, 0, color_ptr)

        gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
        tex_coord_ptr = PointerToNumpy(self.tex_coords)
        gl.glTexCoordPointer(2, gl.GL_FLOAT, 0, tex_coord_ptr)

        gl.glPushAttrib(gl.GL_COLOR_BUFFER_BIT)
        gl.glEnable(gl.GL_BLEND)
        if self.blend_additive:
            gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE)
        else:
            gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        gl.glDrawArrays(gl.GL_QUADS, 0, len(self.vertexs) * 4)

        # un -blend
        gl.glPopAttrib()

        # color restore
        gl.glPopAttrib()

        # disable states
        gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY)
        gl.glDisableClientState(gl.GL_COLOR_ARRAY)
        gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
        gl.glDisable(gl.GL_TEXTURE_2D)

        gl.glPopMatrix()
示例#30
0
def render_rect_filled(shape, x, y):
    """ Render the shape at the right spot. """
    # Set color
    GL.glDisable(GL.GL_BLEND)
    GL.glColor4ub(shape.color[0], shape.color[1], shape.color[2], 255)

    GL.glBindBuffer(GL.GL_ARRAY_BUFFER, shape.vbo_id)
    GL.glVertexPointer(2, GL.GL_FLOAT, 0, 0)

    GL.glLoadIdentity()
    GL.glTranslatef(x + shape.width / 2, y + shape.height / 2, 0)

    GL.glDrawArrays(GL.GL_QUADS, 0, shape.size)
def update_display(render_verts, colors):
    gl.glClearColor(0.2, 0.4, 0.5, 1.0)
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
    gl.glEnable(gl.GL_BLEND)
    gl.glEnable(gl.GL_LINE_SMOOTH)
    gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
    gl.glEnableClientState(gl.GL_COLOR_ARRAY)

    n = len(render_verts[:])
    #TODO verts._buffer.ctypes.data is awkward
    gl.glVertexPointer(3, vert_dtype.gl, 0, render_verts[:].ctypes.data)
    gl.glColorPointer(3, color_dtype.gl, 0, colors[:].ctypes.data)
    gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, n)
def update_display(render_verts, colors):
    gl.glClearColor(0.2, 0.4, 0.5, 1.0)
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
    gl.glEnable(gl.GL_BLEND)
    gl.glEnable(gl.GL_LINE_SMOOTH)
    gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
    gl.glEnableClientState(gl.GL_COLOR_ARRAY)

    n = len(render_verts[:])
    # TODO verts._buffer.ctypes.data is awkward
    gl.glVertexPointer(3, vert_dtype.gl, 0, render_verts[:].ctypes.data)
    gl.glColorPointer(3, color_dtype.gl, 0, colors[:].ctypes.data)
    gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, n)
示例#33
0
    def batch_draw_status(gcps):
        glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT)
        vertices = []
        for port in gcps:
            char = port.character
            if not char: continue

            hp, hp_bg = L('thb-hp'), L('thb-hp_bg')
            if char.dead:
                hp = hp.grayed
                hp_bg = hp_bg.grayed

            # hp bar
            w = hp.width
            x, y = port.x, port.y
            for i in xrange(char.maxlife):
                vertices.extend(
                    hp_bg.get_t4f_v4f_vertices(5+x+i*w, 56+y)
                )

            for i in xrange(max(char.life, 0)):
                vertices.extend(
                    hp.get_t4f_v4f_vertices(5+x+i*w, 56+y)
                )

        nums = L('thb-num')
        for port in gcps:
            x, y, w = port.x, port.y, port.width
            char = port.character
            if not char: continue

            n = len(char.cards) + len(char.showncards)
            seq = str(n)
            ox = (32 - len(seq)*14)//2
            for i, ch in enumerate(seq):
                n = ord(ch) - ord('0')
                # x, y = w - 34 + ox + i*14, 68
                vertices.extend(nums[n].get_t4f_v4f_vertices(
                    x + w - 34 + ox + i*14,
                    y + 68
                ))

        if vertices:
            with nums[0].owner:
                n = len(vertices)
                buf = (GLfloat*n)()
                buf[:] = vertices
                glInterleavedArrays(GL_T4F_V4F, 0, buf)
                glDrawArrays(GL_QUADS, 0, n/8)

        glPopClientAttrib()
示例#34
0
    def batch_draw_status(gcps):
        glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT)
        vertices = []
        for port in gcps:
            char = port.character
            if not char: continue

            hp, hp_bg = L('thb-hp'), L('thb-hp_bg')
            if char.dead:
                hp = hp.grayed
                hp_bg = hp_bg.grayed

            # hp bar
            w = hp.width
            x, y = port.x, port.y
            for i in xrange(char.maxlife):
                vertices.extend(
                    hp_bg.get_t4f_v4f_vertices(5+x+i*w, 56+y)
                )

            for i in xrange(max(char.life, 0)):
                vertices.extend(
                    hp.get_t4f_v4f_vertices(5+x+i*w, 56+y)
                )

        nums = L('thb-num')
        for port in gcps:
            x, y, w = port.x, port.y, port.width
            char = port.character
            if not char: continue

            n = len(char.cards) + len(char.showncards)
            seq = str(n)
            ox = (32 - len(seq)*14)//2
            for i, ch in enumerate(seq):
                n = ord(ch) - ord('0')
                # x, y = w - 34 + ox + i*14, 68
                vertices.extend(nums[n].get_t4f_v4f_vertices(
                    x + w - 34 + ox + i*14,
                    y + 68
                ))

        if vertices:
            with nums[0].owner:
                n = len(vertices)
                buf = (GLfloat*n)()
                buf[:] = vertices
                glInterleavedArrays(GL_T4F_V4F, 0, buf)
                glDrawArrays(GL_QUADS, 0, n/8)

        glPopClientAttrib()
示例#35
0
    def render_points(self):
        renderPoints = []
        for point in self.points:
            renderPoints.extend(point.position.vector)

        self.ctPoints = (gl.GLfloat * len(renderPoints))(*renderPoints)

        point_ptr = ct.cast(self.ctPoints, ct.c_void_p)

        gl.glColor3f(1.0, 1.0, 1.0)
        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
        gl.glVertexPointer(2, gl.GL_FLOAT, 0, point_ptr)
        gl.glDrawArrays(gl.GL_POINTS, 0, len(renderPoints)//2)
        gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
示例#36
0
文件: main.py 项目: leovt/dungeon
    def on_draw(self):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        STRIDE = 8

        self.program.use()
        self.program.vertex_attrib_pointer(self.buffer, b'position', 4, stride=STRIDE * ctypes.sizeof(gl.GLfloat))
        self.program.vertex_attrib_pointer(self.buffer, b'tex_coord', 4, stride=STRIDE * ctypes.sizeof(gl.GLfloat), offset=4 * ctypes.sizeof(gl.GLfloat))

        nb_vertices = 6*40*40
        data = self.dungeon_map.vertex_data()
        data = (gl.GLfloat * (STRIDE * nb_vertices))(*data)
        gl.glBufferData(gl.GL_ARRAY_BUFFER, ctypes.sizeof(data), data, gl.GL_DYNAMIC_DRAW)
        gl.glDrawArrays(gl.GL_TRIANGLES, 0, nb_vertices)
示例#37
0
def draw(verts,colors):
    '''draw the numpy arrays `verts` and `colors`.'''

    gl.glClearColor(0.2, 0.4, 0.5, 1.0)
    gl.glBlendFunc (gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)                             
    gl.glEnable (gl.GL_BLEND)                                                            
    gl.glEnable (gl.GL_LINE_SMOOTH);                                                     
    gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
    gl.glEnableClientState(gl.GL_COLOR_ARRAY)

    gl.glVertexPointer(2, vert_dtype.gl_type, 0, verts.ctypes.data)
    gl.glColorPointer(3,  color_dtype.gl_type, 0, colors.ctypes.data)
    gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, len(verts)//2)
    fps_display.draw()
示例#38
0
def draw(verts, colors):
    '''draw the numpy arrays `verts` and `colors`.'''

    gl.glClearColor(0.2, 0.4, 0.5, 1.0)
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
    gl.glEnable(gl.GL_BLEND)
    gl.glEnable(gl.GL_LINE_SMOOTH)
    gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
    gl.glEnableClientState(gl.GL_COLOR_ARRAY)

    gl.glVertexPointer(2, vert_dtype.gl_type, 0, verts.ctypes.data)
    gl.glColorPointer(3, color_dtype.gl_type, 0, colors.ctypes.data)
    gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, len(verts) // 2)
    fps_display.draw()
示例#39
0
    def on_draw(self):
        gl.glClearColor(0, 0, 0, 0)
        self.clear()

        # since we are rendering to the invisible framebuffer, the size is just the texture's size.
        self.set_viewport(self.tex_width, self.tex_height)
        with self.fbo:
            with self.reaction_shader:
                gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)

        # now we render to the actual window, hence the size is window's size.
        self.set_viewport(self.width, self.height)
        with self.render_shader:
            gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
示例#40
0
    def draw(self, uniforms: List[Uniform]):
        if not self.is_setup:
            self.setup()

        self.shader.bind()
        self.vao.bind()

        for uniform in self.uniforms + uniforms:
            uniform.bind(self.shader)

        glDrawArrays(GL_TRIANGLES, 0, len(self.vertex_buffer))

        self.vao.unbind()
        self.shader.unbind()
示例#41
0
    def on_draw(self):
        gl.glClearColor(0, 0, 0, 0)
        self.clear()

        # since we are rendering to the invisible framebuffer, the size is just the texture's size.
        self.set_viewport(self.tex_width, self.tex_height)
        with self.fbo:
            with self.reaction_shader:
                gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)

        # now we render to the actual window, hence the size is window's size.
        self.set_viewport(self.width, self.height)
        with self.render_shader:
            gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
示例#42
0
    def _on_draw(self):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        STRIDE = 8

        self.program.use()
        self.program.vertex_attrib_pointer(self.buffer,
                                           b"position",
                                           4,
                                           stride=STRIDE *
                                           ctypes.sizeof(gl.GLfloat))
        self.program.vertex_attrib_pointer(
            self.buffer,
            b"color",
            4,
            stride=STRIDE * ctypes.sizeof(gl.GLfloat),
            offset=4 * ctypes.sizeof(gl.GLfloat))

        if self.terrain.dirty or not self._cached_terrain_data:
            data = (float(d) for (x, y, z, c, u, v, (r, g, b, a),
                                  lum) in self.terrain.vertex_data()
                    for d in (x + u, y + v, z, 1, r * lum, g * lum, b * lum,
                              a))
            data = (gl.GLfloat * (STRIDE * self.terrain.nb_vertices()))(*data)
            self._cached_terrain_data = data
        else:
            data = self._cached_terrain_data
        gl.glBufferData(gl.GL_ARRAY_BUFFER, ctypes.sizeof(data), data,
                        gl.GL_DYNAMIC_DRAW)
        gl.glDrawArrays(gl.GL_TRIANGLES, 0, self.terrain.nb_vertices())

        self.sprite_program.use()
        gl.glActiveTexture(gl.GL_TEXTURE0)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.sprite_texture)
        self.sprite_program.uniform1i(b'tex', 0)
        x, y, cp = self.pointed

        utex = [0.0, 1.0 / 16, 1.0 / 16, 0.0]
        vtex = [0.0, 0.0, 1.0 / 16, 1.0 / 16]

        data = (float(d) for (x, y, z, c, u, v, (r, g, b, a),
                              lum) in self.terrain.vertex_data_tile(x, y)
                for d in (x + u, y + v, z + 1.0 / 256, 1, utex[(c - cp) % 4],
                          vtex[(c - cp) % 4], 0.0, 0.0))
        data = (gl.GLfloat * (STRIDE * 6))(*data)

        gl.glBufferData(gl.GL_ARRAY_BUFFER, ctypes.sizeof(data), data,
                        gl.GL_DYNAMIC_DRAW)
        gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6)
示例#43
0
def _render_rect_filled(shape, offset, texture_id, texture_coord_vbo):
    """
    Render the rectangle at the right spot.
    """
    # Set color
    GL.glLoadIdentity()
    GL.glTranslatef(shape.center_x, shape.center_y, 0)

    if shape.angle != 0:
        GL.glRotatef(shape.angle, 0, 0, 1)

    GL.glBindTexture(GL.GL_TEXTURE_2D, texture_id)

    GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, texture_coord_vbo)
    GL.glDrawArrays(GL.GL_QUADS, offset, 4)
示例#44
0
    def render_road(self):
        if self.initialized < 3:
            vertices = []
            colors = []

            def vert(a, b, c):
                for v in (a, b, c):
                    vertices.append(v)
                for c in color:
                    colors.append(c)

            color = (0.4, 0.8, 0.4, 1.0)
            vert(-PLAYFIELD, +PLAYFIELD, 0)
            vert(+PLAYFIELD, +PLAYFIELD, 0)
            vert(+PLAYFIELD, -PLAYFIELD, 0)
            vert(-PLAYFIELD, -PLAYFIELD, 0)
            color = (0.4, 0.9, 0.4, 1.0)
            k = PLAYFIELD / 20.0
            for x in range(-20, 20, 2):
                for y in range(-20, 20, 2):
                    vert(k * x + k, k * y + 0, 0)
                    vert(k * x + 0, k * y + 0, 0)
                    vert(k * x + 0, k * y + k, 0)
                    vert(k * x + k, k * y + k, 0)
            for poly, col in self.road_poly:
                color = (col[0], col[1], col[2], 1)
                for p in poly:
                    vert(p[0], p[1], 0)
            self.initialized += 1
            gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
            gl_vertices = (gl.GLfloat * len(vertices))(*vertices)
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER_ARB, self.vertex_vbo_id)
            gl.glBufferData(gl.GL_ARRAY_BUFFER_ARB,
                            len(vertices) * 4, gl_vertices, gl.GL_STATIC_DRAW)

            gl_colors = (gl.GLfloat * len(colors))(*colors)
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER_ARB, self.color_vbo_id)
            gl.glBufferData(gl.GL_ARRAY_BUFFER_ARB,
                            len(colors) * 4, gl_colors, gl.GL_STATIC_DRAW)
            self.numdraw = len(vertices) // 3
        gl.glBindBuffer(gl.GL_ARRAY_BUFFER_ARB, self.vertex_vbo_id)
        gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0)

        gl.glEnableClientState(gl.GL_COLOR_ARRAY)
        gl.glBindBuffer(gl.GL_ARRAY_BUFFER_ARB, self.color_vbo_id)
        gl.glColorPointer(4, gl.GL_FLOAT, 0, 0)

        gl.glDrawArrays(gl.GL_QUADS, 0, self.numdraw)
示例#45
0
文件: sprite.py 项目: mquinson/arcade
def _render_rect_filled(shape: Sprite, offset: int, texture_id: str,
                        texture_coord_vbo: gl.GLuint):
    """
    Render the rectangle at the right spot.
    """
    # Set color
    gl.glLoadIdentity()
    gl.glTranslatef(shape.center_x, shape.center_y, 0)

    if shape.angle != 0:
        gl.glRotatef(shape.angle, 0, 0, 1)

    gl.glBindTexture(gl.GL_TEXTURE_2D, texture_id)

    gl.glTexCoordPointer(2, gl.GL_FLOAT, 0, texture_coord_vbo)
    gl.glDrawArrays(gl.GL_QUADS, offset, 4)
示例#46
0
def _render_rect_filled(offset: int, texture_id: str,
                        texture_coord_vbo: gl.GLuint, batch_count):
    """
    Render the rectangle at the right spot.
    """
    # Set color
    # gl.glLoadIdentity()
    # gl.glTranslatef(shape.center_x, shape.center_y, 0)

    # if shape.angle != 0:
    #     gl.glRotatef(shape.angle, 0, 0, 1)

    gl.glBindTexture(gl.GL_TEXTURE_2D, texture_id)

    gl.glTexCoordPointer(2, gl.GL_FLOAT, 0, texture_coord_vbo)
    gl.glDrawArrays(gl.GL_QUADS, offset, batch_count)
示例#47
0
 def _draw_mouse_cursor(self):
     """ If the mouse is over the image, draw a cursor crosshair. """
     if self.mouse_position is None:
         return
     x, y = self.mouse_position
     tw, th = self.mouse_texture.size
     gl.glViewport(x - tw, y - th - 1, tw * 2 + 1, th * 2 + 1)
     with self.vao, self.copy_program:
         with self.mouse_texture:
             gl.glEnable(gl.GL_BLEND)
             gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA)
             gl.glUniformMatrix4fv(0, 1, gl.GL_FALSE, EYE4)
             gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6)
             gl.glBlendFunc(gl.GL_ONE, gl.GL_ZERO)
     ww, wh = self.get_pixel_aligned_size()
     gl.glViewport(0, 0, int(ww), int(wh))
示例#48
0
文件: main.py 项目: Sticky-Bits/fort
    def on_draw(self):
        glClearColor(0.1, 0.1, 0.1, 1.0)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
        self.projection = pyrr.matrix44.create_perspective_projection(
            radians(self.camera.zoom), self.width / self.height, 0.1, 1000.0)
        self.view = self.camera.get_view_matrix()
        self.shader.set_uniform("projection", self.projection)
        self.shader.set_uniform("view", self.view)

        # Draw!
        glBindVertexArray(self.chunk.vao)
        # Normally we'd translate before drawing a chunk
        model = pyrr.Matrix44()
        self.shader.set_uniform("model", model)
        glDrawArrays(GL_TRIANGLES, 0, len(self.chunk.vertices) // 3)
示例#49
0
文件: gl.py 项目: GaZ3ll3/enable
    def draw_image(self, img, rect=None, force_copy=False):
        """ Renders a GraphicsContextArray into this GC """
        xform = self.get_ctm()
        x0 = xform[4]
        y0 = xform[5]

        image = image_as_array(img)
        shape = image.shape
        if shape[2] == 4:
            fmt = "RGBA"
        else:
            fmt = "RGB"
        aii = ArrayImage(image, format=fmt)
        texture = aii.texture

        # The texture coords consists of (u,v,r) for each corner of the
        # texture rectangle.  The coordinates are stored in the order
        # bottom left, bottom right, top right, top left.
        x, y, w, h = rect
        texture.width = w
        texture.height = h
        t = texture.tex_coords
        points = array([
            [x,   y+h],
            [x+w, y+h],
            [x+w, y],
            [x,   y],
        ])
        p = transform_points(affine_from_values(*xform), points)
        a = (gl.GLfloat*32)(
            t[0],   t[1],   t[2],  1.,
            p[0,0], p[0,1], 0,     1.,
            t[3],   t[4],   t[5],  1.,
            p[1,0], p[1,1], 0,     1.,
            t[6],   t[7],   t[8],  1.,
            p[2,0], p[2,1], 0,     1.,
            t[9],   t[10],  t[11], 1.,
            p[3,0], p[3,1], 0,     1.,
        )
        gl.glPushAttrib(gl.GL_ENABLE_BIT)
        gl.glEnable(texture.target)
        gl.glBindTexture(texture.target, texture.id)
        gl.glPushClientAttrib(gl.GL_CLIENT_VERTEX_ARRAY_BIT)
        gl.glInterleavedArrays(gl.GL_T4F_V4F, 0, a)
        gl.glDrawArrays(gl.GL_QUADS, 0, 4)
        gl.glPopClientAttrib()
        gl.glPopAttrib()
示例#50
0
    def on_draw(self):
        gl.glClearColor(0.0, 0.0, 0.0, 0.0)
        self.clear()

        if time.time() - self.start_time > 0.1:
            gl.glViewport(0, 0, self.tex_width, self.tex_height)
            with self.fbo:
                with self.reaction_shader:
                    gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)

            gl.glViewport(0, 0, self.width, self.height)
            with self.render_shader:
                gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
                self.frame_count += 1

        if self.video_on and (self.frame_count % self.sample_rate == 0):
            self.write_video_frame()
示例#51
0
    def batch_draw(csl):
        glPushMatrix()
        glLoadIdentity()
        vertices = []
        for cs in csl:
            ax, ay = cs.abs_coords()
            vertices += cs.img.get_t4f_v4f_vertices(ax, ay)

            s = cs.card.suit
            n = cs.card.number

            ssuit = L('thb-smallsuit')
            snum = L('thb-smallnum')

            if n == 10:  # special case
                # g[0].blit(1+g[0].vertices[0], 33+g[0].vertices[1])
                # g[1].blit(5+g[1].vertices[0], 33+g[1].vertices[1])
                vertices += snum[s % 2 * 14 + 10].get_t4f_v4f_vertices(
                    ax - 1, ay + 31)
                vertices += snum[s % 2 * 14 + 0].get_t4f_v4f_vertices(
                    ax + 3, ay + 31)
            else:
                vertices += snum[s % 2 * 14 + n].get_t4f_v4f_vertices(
                    ax + 1, ay + 31)

            vertices += ssuit[s - 1].get_t4f_v4f_vertices(ax + 1, ay + 22)

            if cs.selected:
                vertices += L('thb-card-small-selected').get_t4f_v4f_vertices(
                    ax, ay)
            else:
                vertices += L('thb-card-small-frame').get_t4f_v4f_vertices(
                    ax, ay)

        n = len(vertices)
        buf = (GLfloat * n)()
        buf[:] = vertices
        glColor3f(1., 1., 1.)
        glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT)
        glInterleavedArrays(GL_T4F_V4F, 0, buf)
        with get_atlas('card').texture:
            glDrawArrays(GL_QUADS, 0, n / 8)

        glPopClientAttrib()
        glPopMatrix()
示例#52
0
文件: actors.py 项目: pavlog/Printrun
    def _display_travels(self, has_vbo):
        self.travel_buffer.bind()
        glVertexPointer(3, GL_FLOAT, 0, self.travel_buffer.ptr)

        # Prevent race condition by using the number of currently loaded layers
        max_layers = self.layers_loaded
        # TODO: show current layer travels in a different color
        end = self.layer_stops[min(self.num_layers_to_draw, max_layers)]
        end_index = self.count_travel_indices[end]
        glColor4f(*self.color_travel)
        if self.only_current:
            if self.num_layers_to_draw < max_layers:
                end_prev_layer = self.layer_stops[self.num_layers_to_draw - 1]
                start_index = self.count_travel_indices[end_prev_layer + 1]
                glDrawArrays(GL_LINES, start_index, end_index - start_index + 1)
        else:
            glDrawArrays(GL_LINES, 0, end_index)

        self.travel_buffer.unbind()
示例#53
0
    def _display_travels(self, has_vbo):
        self.travel_buffer.bind()
        glVertexPointer(3, GL_FLOAT, 0, self.travel_buffer.ptr)

        # Prevent race condition by using the number of currently loaded layers
        max_layers = self.layers_loaded
        # TODO: show current layer travels in a different color
        end = self.layer_stops[min(self.num_layers_to_draw, max_layers)]
        end_index = self.count_travel_indices[end]
        glColor4f(*self.color_travel)
        if self.only_current:
            if self.num_layers_to_draw < max_layers:
                end_prev_layer = self.layer_stops[self.num_layers_to_draw - 1]
                start_index = self.count_travel_indices[end_prev_layer + 1]
                glDrawArrays(GL_LINES, start_index,
                             end_index - start_index + 1)
        else:
            glDrawArrays(GL_LINES, 0, end_index)

        self.travel_buffer.unbind()
示例#54
0
    def draw(self):
        if self.buffers["vertex"] is not None:
            gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
            self.vertex()

        if self.buffers["color"] is not None:
            gl.glEnableClientState(gl.GL_COLOR_ARRAY)
            self.color()

        if self.buffers["normal"] is not None:
            gl.glEnableClientState(gl.GL_NORMAL_ARRAY)
            self.normal()

        if self.buffers["texture_coords"] is not None:
            gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
            gl.glEnable(gl.GL_TEXTURE_2D)
            gl.glBindTexture(texture.target, texture.id)
            self.texture()

        gl.glDrawArrays(gl.GL_QUADS, 0, self.vertex_count)
示例#55
0
文件: Entity.py 项目: bm1362/atlas-py
    def draw(self, offset_x, offset_y, screen_height):
        vertices = self.get_screen_relative_vertices(offset_x, offset_y, screen_height)
        
        # get opengl vertices of type GLfloat
        vertices_gl = (GLfloat * len(vertices))(*vertices)

        # set the color
        glColor4ub(*self.color);

        # turn on blend for alpha channel
        glEnable(GL_BLEND)

        # tell open GL were passing a vertex array
        glEnableClientState(GL_VERTEX_ARRAY)

        # create a pointer to vertices_gl
        glVertexPointer(2, GL_FLOAT, 0, vertices_gl)
       
        # draw the array
        glDrawArrays(GL_POLYGON, 0, len(vertices) // 2)
示例#56
0
    def _display_travels(self, has_vbo):
        self.travel_buffer.bind()
        if has_vbo:
            glVertexPointer(3, GL_FLOAT, 0, None)
        else:
            glVertexPointer(3, GL_FLOAT, 0, self.travel_buffer.ptr)

        # TODO: show current layer travels in a different color
        end = self.layer_stops[min(self.num_layers_to_draw, self.max_layers)]
        end_index = self.count_travel_indices[end]
        glColor4f(*self.color_travel)
        if self.only_current:
            if self.num_layers_to_draw < self.max_layers:
                end_prev_layer = self.layer_stops[self.num_layers_to_draw - 1]
                start_index = self.count_travel_indices[end_prev_layer + 1]
                glDrawArrays(GL_LINES, start_index, end_index - start_index + 1)
        else:
            glDrawArrays(GL_LINES, 0, end_index)

        self.travel_buffer.unbind()
示例#57
0
文件: zgl2.py 项目: znah/yoxel-voxel
def draw_arrays(primitive, verts=None, colors=None, tc0=None, tc1=None, tc2=None, tc3=None):
    states = []
    if verts is not None:
        verts = ascont(verts)
        assert verts.ndim >= 2 and verts.shape[-1] <= 4
        gl.glVertexPointer( verts.shape[-1], arrayToGLType(verts), verts.strides[-2], verts.ctypes.data)
        states.append( gl.GL_VERTEX_ARRAY )
    if colors is not None:
        colors = ascont(colors)
        gl.glColorPointer( colors.shape[-1], arrayToGLType(colors), colors.strides[-2], colors.ctypes.data)
        states.append( gl.GL_COLOR_ARRAY )
    protect = []
    for i, tc in enumerate([tc0, tc1, tc2, tc3]):
        if tc is not None:
            tc = ascont(tc)
            protect.append(tc)
            gl.glClientActiveTexture(GL_TEXTURE0 + i) 
            gl.glTexCoordPointer(tc.shape[-1], arrayToGLType(tc), tc.strides[-2], tc.ctypes.data)
            states.append( (GL_TEXTURE_COORD_ARRAY, i) )
    with glstate(*states):
        gl.glDrawArrays( primitive, 0, np.prod(verts.shape[:-1]) )
示例#58
0
    def batch_draw(csl):
        glPushMatrix()
        glLoadIdentity()
        vertices = []
        for cs in csl:
            ax, ay = cs.abs_coords()
            vertices += cs.img.get_t4f_v4f_vertices(ax, ay)

            s = cs.card.suit
            n = cs.card.number

            ssuit = game_res.smallsuit
            snum = game_res.smallnum

            if n == 10:  # special case
                # g[0].blit(1+g[0].vertices[0], 33+g[0].vertices[1])
                # g[1].blit(5+g[1].vertices[0], 33+g[1].vertices[1])
                vertices += snum[s % 2 * 14 + 10].get_t4f_v4f_vertices(ax - 1, ay + 31)
                vertices += snum[s % 2 * 14 + 0].get_t4f_v4f_vertices(ax + 3, ay + 31)
            else:
                vertices += snum[s % 2 * 14 + n].get_t4f_v4f_vertices(ax + 1, ay + 31)

            vertices += ssuit[s - 1].get_t4f_v4f_vertices(ax + 1, ay + 22)

            if cs.selected:
                vertices += game_res.scardframe_selected.get_t4f_v4f_vertices(ax, ay)
            else:
                vertices += game_res.scardframe_normal.get_t4f_v4f_vertices(ax, ay)

        n = len(vertices)
        buf = (GLfloat*n)()
        buf[:] = vertices
        glColor3f(1., 1., 1.)
        glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT)
        glInterleavedArrays(GL_T4F_V4F, 0, buf)
        with get_atlas('card').texture:
            glDrawArrays(GL_QUADS, 0, n/8)

        glPopClientAttrib()
        glPopMatrix()