예제 #1
0
파일: draw.py 프로젝트: noonat/deathbeam
 def flush_labels(self):
     gl.glClear(gl.GL_DEPTH_BUFFER_BIT)
     gl.glPushMatrix()
     gl.glTranslatef(-self.game.camera_x * defs.WINDOW_SCALE[0],
                     -self.game.camera_y * defs.WINDOW_SCALE[1], 0)
     for label, x, y, scale in self.labels:
         if scale:
             gl.glPushMatrix()
             label.anchor_x = 'center'
             label.anchor_y = 'center'
             gl.glTranslatef(x * defs.WINDOW_SCALE[0],
                             y * defs.WINDOW_SCALE[1], 0)
             gl.glScalef(*scale)
             label.x = label.y = 0
             label.draw()
             gl.glPopMatrix()
         else:
             label.x = x * defs.WINDOW_SCALE[0]
             label.y = y * defs.WINDOW_SCALE[1]
             label.draw()
     self.labels = []
     gl.glColor3f(1, 1, 1)
     gl.glEnable(gl.GL_DEPTH_TEST)
     gl.glPopMatrix()
     # self.fps_label.draw()
     self.game.score.draw()
예제 #2
0
파일: camera.py 프로젝트: Knio/miru
 def on(self):
     gl.glPushMatrix()
     gl.glEnable(gl.GL_DEPTH_TEST)
     gl.glPushAttrib(gl.GL_LIGHTING_BIT)
     gl.glEnable(gl.GL_LIGHTING)
     for l in self:
         l.on()
예제 #3
0
파일: gcview.py 프로젝트: faustreg/Printrun
    def draw_objects(self):
        '''called in the middle of ondraw after the buffer has been cleared'''
        self.create_objects()

        glPushMatrix()
        if self.orthographic:
            glTranslatef(0, 0, -3 * self.dist)  # Move back
        else:
            glTranslatef(0, 0, -self.dist)  # Move back
        # Rotate according to trackball
        glMultMatrixd(build_rotmatrix(self.basequat))
        # Move origin to bottom left of platform
        platformx0 = -self.build_dimensions[3] - self.parent.platform.width / 2
        platformy0 = -self.build_dimensions[4] - self.parent.platform.depth / 2
        glTranslatef(platformx0, platformy0, 0)

        for obj in self.parent.objects:
            if not obj.model \
               or not obj.model.loaded \
               or not obj.model.initialized:
                continue
            glPushMatrix()
            glTranslatef(*(obj.offsets))
            glTranslatef(*(obj.centeroffset))
            glRotatef(obj.rot, 0.0, 0.0, 1.0)
            glScalef(*obj.scale)

            obj.model.display()
            glPopMatrix()
        glPopMatrix()
예제 #4
0
 def draw_ents(self, ents):
     for ent in ents:
         glPushMatrix()
         glTranslatef(ent.body.position.x, ent.body.position.y, 0)
         glRotatef(ent.body.angle * 180 / pi, 0, 0, 1)
         ent.batch.draw()
         glPopMatrix()
예제 #5
0
파일: demo.py 프로젝트: irskep/Incontinents
 def on_draw(self):
     pyglet.gl.glClearColor(0.2,0.2,0.8,1)
     self.clear()
     gl.glPushMatrix()
     gl.glTranslatef(self.camera[0], self.camera[1], 0)
     pyglet.gl.glColor4f(1,1,1,1)
     for territory in self.landmass.land_terrs:
         for tri in territory.triangles:
             pyglet.gl.glColor4f(*territory.color)
             pyglet.graphics.draw(
                 3, pyglet.gl.GL_TRIANGLES, ('v2f', tri)
             )
         for line in territory.lines:
             pyglet.gl.glColor4f(*line.color)
             self.draw_line(line.a.x, line.a.y, line.b.x, line.b.y)
     for terr in self.landmass.sea_terrs:
         for line in terr.lines:
             pyglet.gl.glColor4f(*line.color)
             self.draw_line(line.a.x, line.a.y, line.b.x, line.b.y)
     if self.draw_capitals:
         for terr in itertools.chain(self.landmass.land_terrs, self.landmass.sea_terrs):
             pyglet.gl.glColor4f(1,1,1,1)
             w = terr.label.content_width/2+2
             h = terr.label.content_height/2
             self.draw_rect(terr.x-w, terr.y-h, terr.x+w, terr.y+h)
     pyglet.gl.glColor4f(1,1,1,1)
     self.batch.draw()
     gl.glPopMatrix()
예제 #6
0
파일: gluball.py 프로젝트: irskep/Gluball
 def on_draw(self, dt=0):
     env.dt = dt
     if self.load_countdown == 0:
         if self.music_countdown > 0:
             self.music_countdown -= dt
             if self.music_countdown <= 0:
                 music.new_song('The_Creature_Sneaks')
         if self.mode == GUI:
             gl.glLoadIdentity()
             if env.scale_factor != 1.0:
                 gl.glPushMatrix()
                 env.scale()
         
             gl.glClearColor(1,1,1,1)
             self.clear()
             gui.draw_card()
             if gui.current_card == gui.START: self.start_game()
             if gui.current_card == gui.QUIT: pyglet.app.exit()
             if gui.current_card == gui.LOAD: self.load_game()
         
             if env.scale_factor != 1.0:
                 gl.glPopMatrix()
     elif self.load_countdown > 1:
         self.draw_load_screen()
         self.load_countdown -= 1
     else:    
         self.init_resources()
         self.init_gui()
         self.load_countdown = 0
예제 #7
0
파일: actors.py 프로젝트: pavlog/Printrun
    def display(self, mode_2d=False):
        with self.lock:
            glPushMatrix()
            glTranslatef(self.offset_x, self.offset_y, 0)
            glEnableClientState(GL_VERTEX_ARRAY)

            has_vbo = isinstance(self.vertex_buffer, VertexBufferObject)
            if self.display_travels:
                self._display_travels(has_vbo)

            glEnable(GL_LIGHTING)
            glEnableClientState(GL_NORMAL_ARRAY)
            glEnableClientState(GL_COLOR_ARRAY)
            glMaterialfv(GL_FRONT, GL_SPECULAR, vec(1, 1, 1, 1))
            glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, vec(0, 0, 0, 0))
            glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50)

            glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
            self._display_movements(has_vbo)

            glDisable(GL_LIGHTING)

            glDisableClientState(GL_COLOR_ARRAY)
            glDisableClientState(GL_VERTEX_ARRAY)
            glDisableClientState(GL_NORMAL_ARRAY)

            glPopMatrix()
예제 #8
0
    def _drawLUTtoScreen(self):
        """(private) Used to set the LUT in Bits++ mode.

        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.glActiveTextureARB(GL.GL_TEXTURE0_ARB)
        GL.glEnable(GL.GL_TEXTURE_2D)
        GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
        GL.glActiveTextureARB(GL.GL_TEXTURE1_ARB)
        GL.glEnable(GL.GL_TEXTURE_2D)
        GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
        GL.glRasterPos2i(0,1)
        GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1)
        GL.glDrawPixels(len(self._HEADandLUT),1,
            GL.GL_RGB,GL.GL_UNSIGNED_BYTE,
            self._HEADandLUTstr)
        #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 )
예제 #9
0
 def draw(self):
     if self.graph:
         glPushMatrix()
         glScalef(self.scale, self.scale, 1.0)
         self.graph.draw()
         glPopMatrix()
     self.grid.batch.draw()
예제 #10
0
파일: camera.py 프로젝트: fos/fos-legacy
 def translate(self,dx,dy,dz):
     glPushMatrix()
     glLoadIdentity()
     glTranslatef(dx,dy,dz)
     glMultMatrixf(self.matrix)
     self.matrix=get_model_matrix()
     glPopMatrix()
예제 #11
0
파일: pool.py 프로젝트: xoryouyou/NetArgos
def circle(pos, radius, color=(1.0,1.0,1.0), alpha=1.0,segments=6):
    """
    Draws a circle with gluDisk 
    
    :param pos: center of the circle
    :type pos: 2-float tuple

    :param radius: radius of the circle
    :type radius: float

    :param color: the color in [0..1] range
    :type color: 3-float tuple

    :param alpha: the alpha value in [0..1] range

    :param segments: number of segments
    :type segments: int

    """

    glDisable(GL_TEXTURE_2D)

    c = gluNewQuadric()
    glColor4f(color[0], color[1], color[2], alpha)
    glPushMatrix()
    glTranslatef(pos[0], pos[1], 0)
    gluDisk(c, 0, radius, segments, 1)
    glPopMatrix()
    glColor4f(1.0,1.0,1.0,1.0)
    glEnable(GL_TEXTURE_2D)
예제 #12
0
파일: camera.py 프로젝트: fos/fos-legacy
 def rotate(self,ang,rx,ry,rz):
     glPushMatrix()
     glLoadIdentity()
     glRotatef(ang,rx,ry,rz)
     glMultMatrixf(self.matrix)
     self.matrix=get_model_matrix()
     glPopMatrix()
예제 #13
0
파일: Tanks.py 프로젝트: anden3/Python
    def render(self):
        gl.glPushMatrix()

        gl.glTranslatef(self.x + self.width / 2, self.y + self.height / 2, 0)
        gl.glRotatef(self.angle, 0, 0, 1)
        gl.glTranslatef(-self.x - self.width / 2, -self.y - self.height / 2, 0)

        self.batch.draw()

        gl.glPopMatrix()

        gl.glPushMatrix()

        cx, cy, cw, ch = cannon_rects[0]

        gl.glTranslatef(self.x + cx + cw / 2, self.y + cy + ch / 2, 0)
        gl.glRotatef(self.cannon_angle - 90, 0, 0, 1)
        gl.glTranslatef(-self.x - cx - cw / 2, -self.y - cy, 0)

        self.cannon_batch.draw()

        gl.glPopMatrix()

        self.batch = pyglet.graphics.Batch()
        self.cannon_batch = pyglet.graphics.Batch()
예제 #14
0
파일: view.py 프로젝트: bitcraft/pyglet
    def draw(self):
        # set up projection
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        gl.glViewport(self.x, self.y, self.width, self.height)
        gl.glOrtho(0, self.width, 0, self.height, self.near, self.far)
        gl.glMatrixMode(gl.GL_MODELVIEW)

        fx, fy = self._determine_focus()

        w2 = self.width / 2
        h2 = self.height / 2
        x1, y1 = fx - w2, fy - h2
        x2, y2 = fx + w2, fy + h2

        gl.glPushMatrix()
        gl.glTranslatef(self.width / 2 - fx, self.height / 2 - fy, 0)
        for layer in self.layers:
            if hasattr(layer, 'x'):
                translate = layer.x or layer.y
            else:
                translate = False
            if translate:
                gl.glPushMatrix()
                gl.glTranslatef(layer.x, layer.y, 0)
            layer.draw()
            if translate:
                gl.glPopMatrix()
        gl.glPopMatrix()
예제 #15
0
    def draw_objects(self):
        '''called in the middle of ondraw after the buffer has been cleared'''
        self.create_objects()

        glPushMatrix()
        # Rotate according to trackball
        glMultMatrixd(build_rotmatrix(self.basequat))
        # Move origin to bottom left of platform
        platformx0 = -self.build_dimensions[3] - self.parent.platform.width / 2
        platformy0 = -self.build_dimensions[4] - self.parent.platform.depth / 2
        glTranslatef(platformx0, platformy0, 0)

        light_z = max(self.parent.platform.width, self.parent.platform.depth)
        glLightfv(GL_LIGHT0, GL_POSITION, vec(0,
                                              self.parent.platform.depth / 2,
                                              light_z, 0))
        glLightfv(GL_LIGHT1, GL_POSITION, vec(self.parent.platform.width,
                                              self.parent.platform.depth / 2,
                                              light_z, 0))

        for obj in self.parent.objects:
            if not obj.model \
               or not obj.model.loaded \
               or not obj.model.initialized:
                continue
            glPushMatrix()
            glTranslatef(*(obj.offsets))
            glTranslatef(*(obj.centeroffset))
            glRotatef(obj.rot, 0.0, 0.0, 1.0)
            glScalef(*obj.scale)

            obj.model.display()
            glPopMatrix()
        glPopMatrix()
예제 #16
0
    def render(self, geometry):
        """ Add the sphere to the view.

        :param scene: The view to render the model into
        :type scene: pyglet_helper.objects.View
        """
        # Renders a simple sphere with the #2 level of detail.
        if self.radius == 0.0:
            return
        self.init_model(geometry)

        coverage_levels = [30, 100, 500, 5000]
        lod = self.lod_adjust(geometry, coverage_levels, self.pos, self.radius)
        gl.glPushMatrix()

        self.model_world_transform(geometry.gcf, self.scale).gl_mult()
        self.color.gl_set(self.opacity)

        if self.translucent:
            # Spheres are convex, so we don't need to sort
            gl.glEnable(gl.GL_CULL_FACE)

            # Render the back half (inside)
            gl.glCullFace(gl.GL_FRONT)
            geometry.sphere_model[lod].gl_render()

            # Render the front half (outside)
            gl.glCullFace(gl.GL_BACK)
            geometry.sphere_model[lod].gl_render()
        else:
            # Render a simple sphere.
            geometry.sphere_model[lod].gl_render()
        gl.glPopMatrix()
예제 #17
0
    def draw(self):
        glPushMatrix()

        glTranslatef(self.xoffset, self.yoffset, self.zoffset)

        def color(i):
            if i % self.graduations_major == 0:
                glColor4f(*self.color_grads_major)
            elif i % (self.graduations_major / 2) == 0:
                glColor4f(*self.color_grads_interm)
            else:
                if self.light: return False
                glColor4f(*self.color_grads_minor)
            return True

        # draw the grid
        glBegin(GL_LINES)
        for i in range(0, int(math.ceil(self.width + 1))):
            if color(i):
                glVertex3f(float(i), 0.0, 0.0)
                glVertex3f(float(i), self.depth, 0.0)

        for i in range(0, int(math.ceil(self.depth + 1))):
            if color(i):
                glVertex3f(0, float(i), 0.0)
                glVertex3f(self.width, float(i), 0.0)
        glEnd()

        # draw fill
        glColor4f(*self.color_fill)
        glRectf(0.0, 0.0, float(self.width), float(self.depth))

        glPopMatrix()
예제 #18
0
    def render(self, scene):
        """Add the cone to the scene.

        :param scene: The view to render the model into
        :type scene: pyglet_helper.objects.View
        """
        if self.radius == 0:
            return

        self.init_model(scene)

        coverage_levels = [10, 30, 90, 250, 450]
        lod = self.lod_adjust(scene, coverage_levels, self.pos, self.radius)

        length = self.axis.mag()
        gl.glPushMatrix()
        self.model_world_transform(scene.gcf, Vector([length, self.radius,
                                                      self.radius])).gl_mult()

        self.color.gl_set(self.opacity)
        if self.translucent:
            gl.glEnable(gl.GL_CULL_FACE)

            # Render the back half.
            gl.glCullFace(gl.GL_FRONT)
            scene.cone_model[lod].gl_render()

            # Render the front half.
            gl.glCullFace(gl.GL_BACK)
            scene.cone_model[lod].gl_render()
        else:
            scene.cone_model[lod].gl_render()
        gl.glPopMatrix()
예제 #19
0
파일: shapes.py 프로젝트: msarch/py
 def paint(self, peg):
     batch = self.get_batch()
     glPushMatrix()
     glTranslatef(peg.x, peg.y, 0)
     glRotatef(peg.angle, 0, 0, 1)
     batch.draw()
     glPopMatrix()
예제 #20
0
파일: layer.py 프로젝트: wwoods/pyglet_piss
    def _layerProjectLocalToScreen(self):
        """Maps self.coordLocal to self.coordScreen within OpenGL."""
        if self._scissorBox is None and self.localBounds is None:
            return
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPushMatrix()
        gl.glLoadIdentity()
        # gluOrtho2D declares the render space for the corners of the window.
        # So, we want to set it up in such a way that our layer renders in
        # the right place.  In other words, determine window corners that
        # map cl -> cs.  All clipping, etc is already handled by the coordsLocal
        # getter.
        cs = self.coordsScreen
        cl = self.coordsLocal
        sw = self.scene.width
        sh = self.scene.height

        # Determine the window width and height.  We want a local-sized chunk
        # of this to correspond to a screen-sized chunk of the screen.  That is,
        # cl[2] / ww == cs[2] / sw
        ww = cl[2] * sw / cs[2]
        wh = cl[3] * sh / cs[3]

        # cs[0] / sw = (x - nx) / ww
        nx = cl[0] - cs[0] * ww / sw
        ny = cl[1] - cs[1] * wh / sh
        gl.gluOrtho2D(nx, nx+ww, ny, ny+wh)
        gl.glMatrixMode(gl.GL_MODELVIEW)
예제 #21
0
파일: widget.py 프로젝트: mikedh/trimesh
    def set_state(self):
        gl.glPushMatrix()
        gl.glMultMatrixf(rendering.matrix_to_gl(self.transform))

        if self.texture:
            gl.glEnable(self.texture.target)
            gl.glBindTexture(self.texture.target, self.texture.id)
예제 #22
0
파일: draw.py 프로젝트: 1414648814/cocos
    def draw(self):
        if self._dirty:
            self._context = Context()
            self._parts = []
            self.free()
            self.render()
            self.build_vbo()
            self._dirty = False

        # set
        gl.glEnable(self._texture.target)
        gl.glBindTexture(self._texture.target, self._texture.id)
        gl.glPushAttrib(gl.GL_COLOR_BUFFER_BIT)

        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        gl.glPushMatrix()
        self.transform()
        # cuadric.begin()
        self._vertex_list.draw(gl.GL_TRIANGLES)
        # cuadric.end()

        # unset
        gl.glPopMatrix()
        gl.glPopAttrib()
        gl.glDisable(self._texture.target)
예제 #23
0
 def draw(self):
     if self.batch is not None:
         glPushMatrix()
         glScalef(self.scale, self.scale, 0)
         self.batch.draw()
         glPopMatrix()
     self.grid.batch.draw()
예제 #24
0
def draw():
    window.clear()

    for x in range(0, window.width+space_img.width, space_img.width):
        for y in range(0, window.height+space_img.height, space_img.height):
            space_img.blit(x=x, y=y)

    exhaust_batch.draw()
    for y_offset in (-window.height, 0, window.height):
        gl.glPushMatrix()
        gl.glTranslatef(0, y_offset, 0)
        ufo_batch.draw()
        gl.glPopMatrix()
    for x_offset in (-window.width, 0, window.width):
        for y_offset in (-window.height, 0, window.height):
            gl.glPushMatrix()
            gl.glTranslatef(x_offset, y_offset, 0)
            main_batch.draw()
            gl.glPopMatrix()

    for i in range(ship.lives):
        life_sprite.y = 40
        life_sprite.x = 30 + 40 * i
        life_sprite.draw()

    level_label.draw()
예제 #25
0
파일: debugger.py 프로젝트: eevee/flora
    def draw(self):
        # Update list of entities
        # TODO this should actually update instead of recomputing all day, but, whatever
        entity_batch = pyglet.graphics.Batch()
        for _, entity in self.map_layer.children_names['entities'].children:
            x, y = entity.position
            w, h = entity.size
            x0 = entity.position[0] - entity.image_anchor[0] * entity.scale
            y0 = entity.position[1] - entity.image_anchor[1] * entity.scale
            x1, y1 = x0 + w, y0 + h
            entity_batch.add(4, gl.GL_QUADS, self.outlines_group,
                ('v2f', (x0, y0, x0, y1, x1, y1, x1, y0)),
                ('c4f', (1.0, 1.0, 0.0, 0.5) * 4))

            # This is a diamond but at scale it looks enough like a dot
            D = 3
            entity_batch.add(4, gl.GL_QUADS, None,
                ('v2f', (x + D, y, x, y - D, x - D, y, x, y + D)),
                ('c4f', (1.0, 1.0, 0.0, 1.0) * 4))

            # Collision footprint...  kinda
            R = entity.entity_type.shape
            entity_batch.add(4, gl.GL_QUADS, None,
                ('v2f', (x - R, y - R, x + R, y - R, x + R, y + R, x - R, y + R)),
                ('c4f', (1.0, 1.0, 0.0, 0.2) * 4))


        # TODO wtf is GL_CURRENT_BIT
        gl.glPushMatrix()
        self.transform()
        self.grid_batch.draw()
        entity_batch.draw()
        gl.glPopMatrix()
예제 #26
0
파일: render.py 프로젝트: tartley/gloopy
    def draw_world_items(self, glyphs):
        '''
        Draw all passed glyphs
        '''
        shader = None
        for position, orientation, glyph in glyphs:

            gl.glPushMatrix()

            gl.glTranslatef(*position)
            if orientation and orientation != Orientation.Identity:
                gl.glMultMatrixf(orientation.matrix)

            if glyph.shader is not shader:
                shader = glyph.shader
                shader.use()

            gl_wrap.glBindVertexArray(glyph.vao)

            gl.glDrawElements(
                gl.GL_TRIANGLES,
                len(glyph.glindices),
                glyph.index_type,
                glyph.glindices
            )

            gl.glPopMatrix()

        gl_wrap.glBindVertexArray(0)
        Shader.unuse()
예제 #27
0
 def on_draw(self):
     self.window.clear()
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glPushMatrix()
     gl.glLoadIdentity()
     self.camera()
     gl.glEnable(self.grass.target)
     gl.glEnable(gl.GL_BLEND)
     gl.glBindTexture(self.grass.target, self.grass.id)
     W = 10000.
     graphics.draw(4, gl.GL_QUADS,
         ('v2f', (-W, -W, W, -W, W, W, -W, W)),
         ('t2f', (0., 0., W*5., 0., W*5., W*5., 0., W*5.))
     )
     gl.glDisable(self.grass.target)
     for lane in self.lanes:
         self.draw_lane_surface(lane)
     for lane in self.lanes:
         self.draw_lane_lines(lane)
     for obj in self.objects:
         self.draw_object(obj)
     for car in self.cars:
         if car!=self.main_car and car not in self.visible_cars:
             self.draw_car(self.anim_x[car], car.color)
     if self.heat is not None:
         self.draw_heatmap()
     for car in self.cars:
         if car==self.main_car or car in self.visible_cars:
             self.draw_car(self.anim_x[car], car.color)
     gl.glPopMatrix()
     if isinstance(self.main_car, Car):
         self.label.text = 'Speed: %.2f'%self.anim_x[self.main_car][3]
         self.label.draw()
     if self.output is not None:
         pyglet.image.get_buffer_manager().get_color_buffer().save(self.output.format(self.frame))
예제 #28
0
    def draw_axes(self):
        'draw x y z axis in r g b with text labels'
        gl.glPushMatrix()
        gl.glScalef( 1.1, 1.1, 1.1)

        o = 0, 0, 0
        x = 1, 0, 0
        y = 0, 1, 0
        z = 0, 0, 1

        verts  = numpy.array([ o, x, o, y, o, z], dtype=constants.DTYPE )
        colors = numpy.array([ x, x, y, y, z, z], dtype=constants.DTYPE )
        idxs   = numpy.cast[constants.INTDTYPE]( numpy.mgrid[:6] )

        self.drawlines( verts, colors, idxs)

        def draw_axis_label( name, xyz):
            'draw a single label'
            gl.glPushMatrix()
            gl.glTranslatef( xyz[0], xyz[1], xyz[2] )
            gl.glScalef( .01, .01, .01 )
            gl.glRotatef( 90, 0, 1, 0 )
            gl.glRotatef( 90, 0, 0, 1 )
            pyglet.text.Label(name).draw()
            gl.glPopMatrix()

        draw_axis_label( 'x', x)
        draw_axis_label( 'y', y)
        draw_axis_label( 'z', z)
        gl.glPopMatrix()
예제 #29
0
    def drawSpace(self, window):

        gl.glPushMatrix()

        # GL matrices are applied last-added-first, so this *is* the right
        # order for pushing them.
        gl.glTranslatef(-self.viewportOrigin[0], -self.viewportOrigin[1], 0.0)

        if self.shake is not None:
            # We want to rotate around the center of the current viewport
            # vpc = view port center
            vpc_x = self.viewportOrigin[0] + self.windowProps.windowWidth//2
            vpc_y = self.viewportOrigin[1] + self.windowProps.windowHeight//2
            
            gl.glTranslatef(vpc_x, vpc_y, 0.0)
            gl.glRotatef(self.shake.getAngle(), 0, 0, 1)
            gl.glTranslatef(-vpc_x, -vpc_y, 0.0)
        
        ge = self.gameElements

        ge.starField.draw()
        ge.swarm.draw()

        if not self.explodedMarker.done():
            ge.ship.draw()

        if self.endGame and not self.drawFrameMarker.done():
            self.endGame.draw(window)

        for shot in ge.shots:
            if shot.alive:
                shot.draw()
        
        gl.glPopMatrix()
예제 #30
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
예제 #31
0
파일: windowed.py 프로젝트: shuopei/trimesh
    def on_draw(self):
        """
        Run the actual draw calls.
        """

        if self._profile:
            profiler = self.Profiler()
            profiler.start()

        self._update_meshes()
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glLoadIdentity()

        # pull the new camera transform from the scene
        transform_camera = np.linalg.inv(self.scene.camera_transform)

        # apply the camera transform to the matrix stack
        gl.glMultMatrixf(rendering.matrix_to_gl(transform_camera))

        # we want to render fully opaque objects first,
        # followed by objects which have transparency
        node_names = collections.deque(self.scene.graph.nodes_geometry)
        # how many nodes did we start with
        count_original = len(node_names)
        count = -1

        # if we are rendering an axis marker at the world
        if self._axis and not self.view['axis'] == 'without_world':
            # we stored it as a vertex list
            self._axis.draw(mode=gl.GL_TRIANGLES)
        if self._grid:
            self._grid.draw(mode=gl.GL_LINES)

        while len(node_names) > 0:
            count += 1
            current_node = node_names.popleft()

            if current_node in self._nodes_hidden:
                continue

            # get the transform from world to geometry and mesh name
            transform, geometry_name = self.scene.graph.get(current_node)

            # if no geometry at this frame continue without rendering
            if geometry_name is None:
                continue

            # if a geometry is marked as fixed apply the inverse view transform
            if self.fixed is not None and geometry_name in self.fixed:
                # remove altered camera transform from fixed geometry
                transform_fix = np.linalg.inv(
                    np.dot(self._initial_camera_transform, transform_camera))
                # apply the transform so the fixed geometry doesn't move
                transform = np.dot(transform, transform_fix)

            # get a reference to the mesh so we can check transparency
            mesh = self.scene.geometry[geometry_name]
            if mesh.is_empty:
                continue

            # get the GL mode of the current geometry
            mode = self.vertex_list_mode[geometry_name]

            # if you draw a coplanar line with a triangle it will z-fight
            # the best way to do this is probably a shader but this works fine
            if mode == gl.GL_LINES:
                # apply the offset in camera space
                transform = util.multi_dot([
                    transform,
                    np.linalg.inv(transform_camera), self._line_offset,
                    transform_camera
                ])

            # add a new matrix to the model stack
            gl.glPushMatrix()
            # transform by the nodes transform
            gl.glMultMatrixf(rendering.matrix_to_gl(transform))

            # draw an axis marker for each mesh frame
            if self.view['axis'] == 'all':
                self._axis.draw(mode=gl.GL_TRIANGLES)
            elif self.view['axis'] == 'without_world':
                if count > 0:
                    self._axis.draw(mode=gl.GL_TRIANGLES)

            # transparent things must be drawn last
            if (hasattr(mesh, 'visual')
                    and hasattr(mesh.visual, 'transparency')
                    and mesh.visual.transparency):
                # put the current item onto the back of the queue
                if count < count_original:
                    # add the node to be drawn last
                    node_names.append(current_node)
                    # pop the matrix stack for now
                    gl.glPopMatrix()
                    # come back to this mesh later
                    continue

            # if we have texture enable the target texture
            texture = None
            if geometry_name in self.textures:
                texture = self.textures[geometry_name]
                gl.glEnable(texture.target)
                gl.glBindTexture(texture.target, texture.id)

            # draw the mesh with its transform applied
            self.vertex_list[geometry_name].draw(mode=mode)
            # pop the matrix stack as we drew what we needed to draw
            gl.glPopMatrix()

            # disable texture after using
            if texture is not None:
                gl.glDisable(texture.target)

        if self._profile:
            profiler.stop()
            print(profiler.output_text(unicode=True, color=True))
예제 #32
0
def on_draw():
    window.clear()

    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glEnable(gl.GL_LINE_SMOOTH)

    width, height = window.get_size()
    gl.glViewport(0, 0, width, height)

    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    gl.gluPerspective(60, width / float(height), 0.01, 20)

    gl.glMatrixMode(gl.GL_TEXTURE)
    gl.glLoadIdentity()
    # texcoords are [0..1] and relative to top-left pixel corner, add 0.5 to center
    gl.glTranslatef(0.5 / image_data.width, 0.5 / image_data.height, 0)
    # texture size may be increased by pyglet to a power of 2
    tw, th = image_data.texture.owner.width, image_data.texture.owner.height
    gl.glScalef(image_data.width / float(tw), image_data.height / float(th), 1)

    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()

    gl.gluLookAt(0, 0, 0, 0, 0, 1, 0, -1, 0)

    gl.glTranslatef(0, 0, state.distance)
    gl.glRotated(state.pitch, 1, 0, 0)
    gl.glRotated(state.yaw, 0, 1, 0)

    if any(state.mouse_btns):
        axes(0.1, 4)

    gl.glTranslatef(0, 0, -state.distance)
    gl.glTranslatef(*state.translation)

    gl.glColor3f(0.5, 0.5, 0.5)
    gl.glPushMatrix()
    gl.glTranslatef(0, 0.5, 0.5)
    grid()
    gl.glPopMatrix()

    psz = max(window.get_size()) / float(max(w, h)) if state.scale else 1
    gl.glPointSize(psz)
    distance = (0, 0, 1) if state.attenuation else (1, 0, 0)
    gl.glPointParameterfv(gl.GL_POINT_DISTANCE_ATTENUATION,
                          (gl.GLfloat * 3)(*distance))

    if state.lighting:
        ldir = [0.5, 0.5, 0.5]  # world-space lighting
        ldir = np.dot(state.rotation, (0, 0, 1))  # MeshLab style lighting
        ldir = list(ldir) + [0]  # w=0, directional light
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, (gl.GLfloat * 4)(*ldir))
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, (gl.GLfloat * 3)(1.0, 1.0,
                                                                   1.0))
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, (gl.GLfloat * 3)(0.75, 0.75,
                                                                   0.75))
        gl.glEnable(gl.GL_LIGHT0)
        gl.glEnable(gl.GL_NORMALIZE)
        gl.glEnable(gl.GL_LIGHTING)

    gl.glColor3f(1, 1, 1)
    texture = image_data.get_texture()
    gl.glEnable(texture.target)
    gl.glBindTexture(texture.target, texture.id)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                       gl.GL_NEAREST)

    # comment this to get round points with MSAA on
    gl.glEnable(gl.GL_POINT_SPRITE)

    if not state.scale and not state.attenuation:
        gl.glDisable(gl.GL_MULTISAMPLE)  # for true 1px points with MSAA on
    vertex_list.draw(gl.GL_POINTS)
    gl.glDisable(texture.target)
    if not state.scale and not state.attenuation:
        gl.glEnable(gl.GL_MULTISAMPLE)

    gl.glDisable(gl.GL_LIGHTING)

    gl.glColor3f(0.25, 0.25, 0.25)
    frustum(depth_intrinsics)
    axes()

    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    gl.glOrtho(0, width, 0, height, -1, 1)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()
    gl.glMatrixMode(gl.GL_TEXTURE)
    gl.glLoadIdentity()
    gl.glDisable(gl.GL_DEPTH_TEST)

    fps_display.draw()
예제 #33
0
 def draw(self):
     gl.glPushMatrix()
     self.transform()
     self.batch.draw()
     gl.glPopMatrix()
예제 #34
0
파일: ants.py 프로젝트: sinaheydariGIT/gym
 def enable(self):
     glPushMatrix()
     if self.flipx: glRotatef(180, 0, 1., 0)
     if self.flipy: glRotatef(180, 1., 0, 0)
예제 #35
0
 def mult_rot_matrix(self, rot):
     pgl.glPushMatrix()
     pgl.glLoadMatrixf(rot)
     pgl.glMultMatrixf(self._rot)
     self._rot = get_model_matrix()
     pgl.glPopMatrix()
예제 #36
0
파일: menu.py 프로젝트: pertrush1/cocos
 def draw(self):
     gl.glPushMatrix()
     self.transform()
     self.title_label.draw()
     gl.glPopMatrix()
예제 #37
0
 def hide(self):
     if not self.drawable:
         raise Exception('Trying to draw non-drawable shape')
     glPushMatrix()
     self.vlist = pyglet.graphics.vertex_list(0, ('v2f', []))
     glPopMatrix()
예제 #38
0
    def draw(self):
        gl.glLineWidth(1)

        ecsm = game_scene.ecsm

        phys_comp_list = ecsm.comps[phys.PhysicsEcsComponent.name()]
        grav_comp_list = ecsm.comps[phys.GravityEcsComponent.name()]
        coll_comp_list = ecsm.comps[collision.CollisionEcsComponent.name()]
        planet_comp_list = ecsm.comps[planet.PlanetEcsComponent.name()]
        ship_comp_list = ecsm.comps[ship.ShipEcsComponent.name()]
        base_comp_list = ecsm.comps[base.BaseEcsComponent.name()]

        entities = ecsm.entities

        player_entity_id = ecsm.get_system(
            player.PlayerEscSystem.name()).player_entity_id
        player_physc = ecsm.get_entity_comp(player_entity_id,
                                            phys.PhysicsEcsComponent.name())

        # if player_physc:
        #	tx = (-player_physc.pos.x * ZOOM) + const.WIDTH // 2
        #	ty = (-player_physc.pos.y * ZOOM) + const.HEIGHT // 2
        # else:
        tx = const.WIDTH // 2
        ty = const.HEIGHT // 2

        gl.glColor3f(0, 0, 0.2)
        for i in range(0, const.WIDTH, 50):
            gl.glBegin(gl.GL_LINES)
            gl.glVertex2f(i, 0.0)
            gl.glVertex2f(i, const.HEIGHT)
            gl.glEnd()

        for i in range(0, const.HEIGHT, 50):
            gl.glBegin(gl.GL_LINES)
            gl.glVertex2f(0.0, i)
            gl.glVertex2f(const.WIDTH, i)
            gl.glEnd()

        gl.glPushMatrix()
        gl.glLoadIdentity()

        gl.glTranslatef(tx, ty, 0.0)

        # planet orbots
        for idx, eid in enumerate(entities):
            planetc = planet_comp_list[idx]
            physc = phys_comp_list[idx]

            if planetc and physc.static:
                # rpc = rend_plan_comp_list[idx]
                # render.draw_circle(physc.pos.x * ZOOM, physc.pos.y * ZOOM, collc.radius * ZOOM)

                distance = physc.pos.length
                if distance:
                    render.draw_circle(0,
                                       0,
                                       distance * ZOOM,
                                       mode=gl.GL_LINES,
                                       color=(.5, .5, .5, 1))

        for idx, eid in enumerate(entities):
            shipc = ship_comp_list[idx]
            basec = base_comp_list[idx]
            planetc = planet_comp_list[idx]
            physc = phys_comp_list[idx]
            collc = coll_comp_list[idx]

            if basec and basec.crew_load > 0:
                render.draw_circle(physc.pos.x * ZOOM,
                                   physc.pos.y * ZOOM,
                                   TOKEN_SIZE * ZOOM,
                                   color=(1, 1, 0, 1))

            # show planet
            elif planetc:
                # rpc = rend_plan_comp_list[idx]
                render.draw_circle(physc.pos.x * ZOOM,
                                   physc.pos.y * ZOOM,
                                   collc.radius * ZOOM,
                                   color=(.8, .8, .8, 1))

                # gc = grav_comp_list[idx]
                # if gc and gc.gravity_radius:
            #	render.draw_circle(physc.pos.x * ZOOM, physc.pos.y * ZOOM, gc.gravity_radius * ZOOM, None, gl.GL_LINE_LOOP, color=(.3, .3, .3, 1))

        # labels
        for idx, eid in enumerate(entities):
            planetc = planet_comp_list[idx]
            physc = phys_comp_list[idx]
            collc = coll_comp_list[idx]

            if planetc:
                if planetc.pname:
                    label = pyglet.text.Label(
                        planetc.pname,
                        font_name=font.FONT_MONO.name,
                        font_size=12,
                        x=physc.pos.x * ZOOM,
                        y=(physc.pos.y + (collc.radius + 500)) * ZOOM,
                        # + collc.radius + 5
                        anchor_x='center',
                        anchor_y='center',
                        color=(255, 255, 255, 120))
                    label.draw()

        # show player position
        if player_physc:
            render.draw_circle(player_physc.pos.x * ZOOM,
                               player_physc.pos.y * ZOOM,
                               TOKEN_SIZE * ZOOM,
                               color=(1, 0, 0, 1))

        gl.glPopMatrix()
예제 #39
0
파일: t3emu.py 프로젝트: frenzymadness/t3
def pushed_matrix():
    gl.glPushMatrix()
    try:
        yield
    finally:
        gl.glPopMatrix()
예제 #40
0
    def on_draw(self):
        """
        Run the actual draw calls.
        """
        self._update_meshes()
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glLoadIdentity()

        # pull the new camera transform from the scene
        transform_camera = self.scene.graph.get(
            frame_to='world',
            frame_from=self.scene.camera.name)[0]

        # apply the camera transform to the matrix stack
        gl.glMultMatrixf(rendering.matrix_to_gl(transform_camera))

        # dragging the mouse moves the view
        # but doesn't alter the scene
        view = view_to_transform(self.view)
        # add the view transform to the stack
        gl.glMultMatrixf(rendering.matrix_to_gl(view))

        # we want to render fully opaque objects first,
        # followed by objects which have transparency
        node_names = collections.deque(self.scene.graph.nodes_geometry)
        # how many nodes did we start with
        count_original = len(node_names)
        count = -1

        # if we are rendering an axis marker at the world
        if self._axis:
            # we stored it as a vertex list
            self._axis.draw(mode=gl.GL_TRIANGLES)

        while len(node_names) > 0:
            count += 1
            current_node = node_names.popleft()

            # get the transform from world to geometry and mesh name
            transform, geometry_name = self.scene.graph[current_node]

            # if no geometry at this frame continue without rendering
            if geometry_name is None:
                continue

            # if a geometry is marked as fixed apply the inverse view transform
            if self.fixed is not None and geometry_name in self.fixed:
                transform = np.dot(np.linalg.inv(view), transform)

            # get a reference to the mesh so we can check transparency
            mesh = self.scene.geometry[geometry_name]
            if mesh.is_empty:
                continue

            # add a new matrix to the model stack
            gl.glPushMatrix()
            # transform by the nodes transform
            gl.glMultMatrixf(rendering.matrix_to_gl(transform))

            # draw an axis marker for each mesh frame
            if self.view['axis'] == 'all':
                self._axis.draw(mode=gl.GL_TRIANGLES)

            # transparent things must be drawn last
            if (hasattr(mesh, 'visual') and
                hasattr(mesh.visual, 'transparency')
                    and mesh.visual.transparency):
                # put the current item onto the back of the queue
                if count < count_original:
                    # add the node to be drawn last
                    node_names.append(current_node)
                    # pop the matrix stack for now
                    gl.glPopMatrix()
                    # come back to this mesh later
                    continue

            # if we have texture enable the target texture
            texture = None
            if geometry_name in self.textures:
                texture = self.textures[geometry_name]
                gl.glEnable(texture.target)
                gl.glBindTexture(texture.target, texture.id)

            # get the mode of the current geometry
            mode = self.vertex_list_mode[geometry_name]
            # draw the mesh with its transform applied
            self.vertex_list[geometry_name].draw(mode=mode)
            # pop the matrix stack as we drew what we needed to draw
            gl.glPopMatrix()

            # disable texture after using
            if texture is not None:
                gl.glDisable(texture.target)
예제 #41
0
 def enable(self):
     gl.glPushMatrix()
     # translate to GL loc ppint
     gl.glTranslatef(self.translation[0], self.translation[1], 0)
     gl.glRotatef(RAD2DEG * self.rotation, 0, 0, 1.0)
     gl.glScalef(self.scale[0], self.scale[1], 1)
예제 #42
0
 def enable(self):
     gl.glPushMatrix()
     gl.glScalef(self.scale[0], self.scale[1], 1)
     gl.glTranslatef(self.newpos[0], self.newpos[1], 0)
     gl.glRotatef(RAD2DEG * -self.rotation, 0, 0, 1.0)
     gl.glTranslatef(-self.centre[0], -self.centre[1], 0)
예제 #43
0
파일: camera.py 프로젝트: pennomi/overseer
 def pre_draw(self):
     gl.glPushMatrix()
     gl.glTranslatef(int(self.x), int(self.y), 0)
예제 #44
0
    def blit_to_texture(self, target, level, x, y, z, internalformat=None):
        '''Draw this image to to the currently bound texture at `target`.

        If `internalformat` is specified, glTexImage is used to initialise
        the texture; otherwise, glTexSubImage is used to update a region.
        '''

        data_format = self.format
        data_pitch = abs(self._current_pitch)

        # Determine pixel format from format string
        matrix = None
        format, type = self._get_gl_format_and_type(data_format)
        if format is None:
            if (len(data_format) in (3, 4)
                    and gl.gl_info.have_extension('GL_ARB_imaging')):

                # Construct a color matrix to convert to GL_RGBA
                def component_column(component):
                    try:
                        pos = 'RGBA'.index(component)
                        return [0] * pos + [1] + [0] * (3 - pos)
                    except ValueError:
                        return [0, 0, 0, 0]

                # pad to avoid index exceptions
                lookup_format = data_format + 'XXX'
                matrix = (component_column(lookup_format[0]) +
                          component_column(lookup_format[1]) +
                          component_column(lookup_format[2]) +
                          component_column(lookup_format[3]))
                format = {3: gl.GL_RGB, 4: gl.GL_RGBA}.get(len(data_format))
                type = gl.GL_UNSIGNED_BYTE

                gl.glMatrixMode(gl.GL_COLOR)
                gl.glPushMatrix()
                gl.glLoadMatrixf((gl.GLfloat * 16)(*matrix))
            else:
                # Need to convert data to a standard form
                data_format = {
                    1: 'L',
                    2: 'LA',
                    3: 'RGB',
                    4: 'RGBA'
                }.get(len(data_format))
                format, type = self._get_gl_format_and_type(data_format)

        # Workaround: don't use GL_UNPACK_ROW_LENGTH
        if gl.current_context._workaround_unpack_row_length:
            data_pitch = self.width * len(data_format)

        # Get data in required format (hopefully will be the same format it's
        # already in, unless that's an obscure format, upside-down or the
        # driver is old).
        data = self._convert(data_format, data_pitch)

        if data_pitch & 0x1:
            alignment = 1
        elif data_pitch & 0x2:
            alignment = 2
        else:
            alignment = 4
        row_length = data_pitch / len(data_format)
        gl.glPushClientAttrib(gl.GL_CLIENT_PIXEL_STORE_BIT)
        gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, alignment)
        gl.glPixelStorei(gl.GL_UNPACK_ROW_LENGTH, row_length)
        self._apply_region_unpack()
        gl.glTexParameteri(target, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE)
        gl.glTexParameteri(target, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE)
        gl.glTexParameteri(target, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
        gl.glTexParameteri(target, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)

        if target == gl.GL_TEXTURE_3D:
            assert not internalformat
            gl.glTexSubImage3D(target, level, x, y, z, self.width, self.height,
                               1, format, type, data)
        elif internalformat:
            gl.glTexImage2D(target, level, internalformat, self.width,
                            self.height, 0, format, type, data)
        else:
            gl.glTexSubImage2D(target, level, x, y, self.width, self.height,
                               format, type, data)
        gl.glPopClientAttrib()

        if matrix:
            gl.glPopMatrix()
            gl.glMatrixMode(gl.GL_MODELVIEW)
예제 #45
0
    def draw(self, _Stage, _View, _isClear=False):
        """ Draw current batch of triangle vertices, acknowledging the scaling
        and rotation of the current display (stage settings)
    """
        for iWin, win in enumerate(pyglet.app.windows):
            win.switch_to()

            xScale = _Stage.scalX_umPerPix * _Stage.winXCorrFact * win.scale
            yScale = _Stage.scalY_umPerPix * _Stage.winXCorrFact * win.scale
            yWin_5 = win.height // 2
            xWin_5 = win.width // 2
            xWin_25 = win.width // 4

            if len(win.caption) == 0:
                GL.glMatrixMode(GL.GL_PROJECTION)
                GL.glLoadIdentity()
                GL.glOrtho(-xWin_5, xWin_5, -yWin_5, yWin_5, -1, 1)
                GL.glMatrixMode(GL.GL_MODELVIEW)
                GL.glLoadIdentity()
                GL.glPushMatrix()
                GL.glTranslatef(_Stage.centOffX_pix, _Stage.centOffY_pix, 0)
                GL.glScalef(xScale, yScale, 0.0)
                GL.glRotatef(_Stage.rot_angle, 0, 0, 1)
                if not _isClear:
                    self.Batch.draw()
                self.BatchSpr.draw()
                GL.glPopMatrix()

            else:
                if _Stage.useScrOvl:
                    # Draw on first (left) screen
                    #
                    GL.glViewport(0, 0, win.width // 2, win.height)
                    GL.glMatrixMode(GL.GL_PROJECTION)
                    GL.glLoadIdentity()
                    GL.glOrtho(-xWin_25 * _Stage.hFlipScr1,
                               xWin_25 * _Stage.hFlipScr1,
                               -yWin_5 * _Stage.vFlipScr1,
                               yWin_5 * _Stage.vFlipScr1, -1, 1)
                    GL.glMatrixMode(GL.GL_MODELVIEW)
                    GL.glLoadIdentity()
                    GL.glPushMatrix()
                    x = _Stage.centOffX_pix
                    y = _Stage.centOffY_pix
                    GL.glTranslatef(x, y, 0)
                    GL.glScalef(xScale, yScale, 0.0)
                    GL.glRotatef(_Stage.rot_angle, 0, 0, 1)
                    if not _isClear:
                        self.Batch.draw()
                    self.BatchSpr.draw()
                    GL.glPopMatrix()

                    # Draw on second (right) screen
                    #
                    GL.glViewport(win.width // 2, 0, win.width // 2,
                                  win.height)
                    GL.glMatrixMode(GL.GL_PROJECTION)
                    GL.glLoadIdentity()
                    GL.glOrtho(-xWin_25 * _Stage.hFlipScr2,
                               xWin_25 * _Stage.hFlipScr2,
                               -yWin_5 * _Stage.vFlipScr2,
                               yWin_5 * _Stage.vFlipScr2, -1, 1)
                    GL.glMatrixMode(GL.GL_MODELVIEW)
                    GL.glLoadIdentity()
                    GL.glPushMatrix()

                    self.add_rect_data(win.Scr2Vert)

                    x = _Stage.centOffX_pix + _Stage.offXScr2_pix
                    y = _Stage.centOffY_pix + _Stage.offYScr2_pix
                    GL.glTranslatef(x, y, 0)
                    GL.glScalef(xScale, yScale, 0.0)
                    GL.glRotatef(_Stage.rot_angle, 0, 0, 1)
                    if not _isClear:
                        self.Batch2.draw()
                    self.Batch2Spr.draw()
                    GL.glPopMatrix()

                else:
                    GL.glMatrixMode(GL.GL_PROJECTION)
                    GL.glLoadIdentity()
                    GL.glOrtho(-xWin_5, xWin_5, -yWin_5, yWin_5, -1, 1)
                    GL.glMatrixMode(GL.GL_MODELVIEW)
                    GL.glLoadIdentity()
                    GL.glPushMatrix()
                    GL.glTranslatef(_Stage.centOffX_pix, _Stage.centOffY_pix,
                                    0)
                    GL.glScalef(xScale, yScale, 0.0)
                    GL.glRotatef(_Stage.rot_angle, 0, 0, 1)
                    if not _isClear:
                        self.Batch.draw()
                    self.BatchSpr.draw()
                    GL.glPopMatrix()
예제 #46
0
def on_draw():
    window.clear()

    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glEnable(gl.GL_LINE_SMOOTH)

    width, height = window.get_size()
    gl.glViewport(0, 0, width, height)

    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    gl.gluPerspective(60, width / float(height), 0.01, 20)

    gl.glMatrixMode(gl.GL_TEXTURE)
    gl.glLoadIdentity()
    # texcoords are [0..1] and relative to top-left pixel corner, add 0.5 to center
    gl.glTranslatef(0.5 / image_data.width, 0.5 / image_data.height, 0)
    # texture size may be increased by pyglet to a power of 2
    tw, th = image_data.texture.owner.width, image_data.texture.owner.height
    gl.glScalef(image_data.width / float(tw), image_data.height / float(th), 1)

    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()

    gl.gluLookAt(0, 0, 0, 0, 0, 1, 0, -1, 0)

    gl.glTranslatef(0, 0, state.distance)
    gl.glRotated(state.pitch, 1, 0, 0)
    gl.glRotated(state.yaw, 0, 1, 0)
    """ if any(state.mouse_btns):
        axes(0.1, 4) """

    gl.glTranslatef(0, 0, -state.distance)
    gl.glTranslatef(*state.translation)

    gl.glColor3f(0.5, 0.5, 0.5)
    gl.glPushMatrix()
    gl.glTranslatef(0, 0.5, 0.5)
    # grid()
    gl.glPopMatrix()

    psz = 1
    gl.glPointSize(psz)
    distance = (1, 0, 0)
    gl.glPointParameterfv(gl.GL_POINT_DISTANCE_ATTENUATION,
                          (gl.GLfloat * 3)(*distance))

    gl.glColor3f(1, 1, 1)
    texture = image_data.get_texture()
    gl.glEnable(texture.target)
    gl.glBindTexture(texture.target, texture.id)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                       gl.GL_NEAREST)

    # comment this to get round points with MSAA on
    gl.glEnable(gl.GL_POINT_SPRITE)

    gl.glDisable(gl.GL_MULTISAMPLE)  # for true 1px points with MSAA on
    vertex_list.draw(gl.GL_POINTS)
    gl.glDisable(texture.target)
    gl.glEnable(gl.GL_MULTISAMPLE)

    gl.glDisable(gl.GL_LIGHTING)

    gl.glColor3f(0.25, 0.25, 0.25)
    # frustum(depth_intrinsics)
    # axes()

    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    gl.glOrtho(0, width, 0, height, -1, 1)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()
    gl.glMatrixMode(gl.GL_TEXTURE)
    gl.glLoadIdentity()
    gl.glDisable(gl.GL_DEPTH_TEST)
예제 #47
0
def rotate(angle, axis=(0, 0, 1)):
    gl.glPushMatrix()
    gl.glRotatef(angle * 180 / pi, *axis)
    yield
    gl.glPopMatrix()
예제 #48
0
 def draw(self):
     gl.glPushMatrix()
     gl.glTranslatef(self.x, self.y, 0)
     gl.glRotatef(self.rot, 0, 0, 1)
     self.vertex_list.draw(gl.GL_TRIANGLES)
     gl.glPopMatrix()
예제 #49
0
 def render_component(self, component):
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glPushMatrix()
     gl.glTranslatef(component.layout.x, component.layout.y, 0.0)
     component.shape.vertex_list.draw(component.shape.gl_type)
     gl.glPopMatrix()
예제 #50
0
def translate(x, y=0, z=0):
    gl.glPushMatrix()
    gl.glTranslatef(x, y, z)
    yield
    gl.glPopMatrix()
예제 #51
0
파일: KcBoxA.py 프로젝트: tkrym02/anaconda
    def draw(self):
        gl.glDisable(gl.GL_TEXTURE_2D)
        border = True
        offset = False
        image = True
        color1 = self.border1
        color2 = self.border2
        if self.displayType == BUTTON:
            if not self.showBorder and not self.over:
                border = False
            if self.is_pressed():
                offset = True
                color1, color2 = color2, color1
        elif self.displayType == CHECKBOX:
            if not self.showBorder and not self.over:
                border = False
            value = self.checked or self.is_pressed()
            if self.imageCheckbox:
                if value:
                    border = True
                else:
                    image = False
            else:
                if value:
                    offset = True
                    color1, color2 = color2, color1
        elif self.displayType == HYPERLINK:
            if self.is_pressed():
                offset = True

        if not self.enabled:
            border = False
            offset = False

        draw_rectangle(self.x, self.y, self.x + self.width,
                       self.y - self.height, self.fill)
        gl.glPushAttrib(gl.GL_SCISSOR_BIT)
        gl.glPushMatrix()
        x, y, width, height = self.player.get_scissor_box(
            self.x, self.y - self.height, self.width, self.height)
        gl.glScissor(x, y, width, height)
        gl.glEnable(gl.GL_SCISSOR_TEST)
        if offset:
            gl.glTranslatef(2, -2, 0)
        sprite = self.imageSprite
        if self.imageVisible and image and sprite is not None:
            if self.pattern:
                startX = self.x
                startY = self.y
                width = sprite.width
                height = sprite.height
                for y in xrange(int(math.ceil(float(self.height) / height))):
                    sprite.y = startY - y * height
                    for x in xrange(int(math.ceil(float(self.width) / width))):
                        sprite.x = startX + x * width
                        sprite.render()
            else:
                self.imageSprite.render()
        if self.displayType != HYPERLINK and self.textColor is not None:
            self.label.draw()
        gl.glPopMatrix()
        if self.displayType == HYPERLINK:
            if self.over:
                color = self.hyperlinkColor
            else:
                color = self.textColor
            if color is not None:
                self.label.draw()
        gl.glPopAttrib()

        gl.glDisable(gl.GL_TEXTURE_2D)
        if border:
            # top left
            draw_rectangle(self.x, self.y, self.x + self.width, self.y - 1,
                           color1)
            draw_rectangle(self.x, self.y, self.x + 1, self.y - self.height,
                           color1)
            # bottom right
            draw_rectangle(self.x + self.width, self.y - self.height, self.x,
                           self.y - self.height + 1, color2)
            draw_rectangle(self.x + self.width, self.y - self.height,
                           self.x + self.width - 1, self.y, color2)
예제 #52
0
    def draw_objects(self):
        '''called in the middle of ondraw after the buffer has been cleared'''
        self.create_objects()

        glPushMatrix()
        glTranslatef(0, 0, -self.dist)
        glMultMatrixd(build_rotmatrix(
            self.basequat))  # Rotate according to trackball
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
                     vec(0.2, 0.2, 0.2, 1))
        glTranslatef(-self.build_dimensions[3] - self.platform.width / 2,
                     -self.build_dimensions[4] - self.platform.depth / 2,
                     0)  # Move origin to bottom left of platform
        # Draw platform
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
        glDisable(GL_LIGHTING)
        self.platform.draw()
        glEnable(GL_LIGHTING)
        # Draw mouse
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        inter = self.mouse_to_plane(self.mousepos[0],
                                    self.mousepos[1],
                                    plane_normal=(0, 0, 1),
                                    plane_offset=0,
                                    local_transform=False)
        if inter is not None:
            glPushMatrix()
            glTranslatef(inter[0], inter[1], inter[2])
            glBegin(GL_TRIANGLES)
            glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
                         vec(1, 0, 0, 1))
            glNormal3f(0, 0, 1)
            glVertex3f(2, 2, 0)
            glVertex3f(-2, 2, 0)
            glVertex3f(-2, -2, 0)
            glVertex3f(2, -2, 0)
            glVertex3f(2, 2, 0)
            glVertex3f(-2, -2, 0)
            glEnd()
            glPopMatrix()

        # Draw objects
        glDisable(GL_CULL_FACE)
        glPushMatrix()
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
                     vec(0.3, 0.7, 0.5, 1))
        for i in self.parent.models:
            model = self.parent.models[i]
            glPushMatrix()
            glTranslatef(*(model.offsets))
            glRotatef(model.rot, 0.0, 0.0, 1.0)
            glTranslatef(*(model.centeroffset))
            glScalef(*model.scale)
            model.batch.draw()
            glPopMatrix()
        glPopMatrix()
        glEnable(GL_CULL_FACE)

        # Draw cutting plane
        if self.parent.cutting:
            # FIXME: make this a proper Actor
            axis = self.parent.cutting_axis
            fixed_dist = self.parent.cutting_dist
            dist, plane_width, plane_height = self.get_cutting_plane(
                axis, fixed_dist)
            if dist is not None:
                glPushMatrix()
                if axis == "x":
                    glRotatef(90, 0, 1, 0)
                    glRotatef(90, 0, 0, 1)
                    glTranslatef(0, 0, dist)
                elif axis == "y":
                    glRotatef(90, 1, 0, 0)
                    glTranslatef(0, 0, -dist)
                elif axis == "z":
                    glTranslatef(0, 0, dist)
                glDisable(GL_CULL_FACE)
                glBegin(GL_TRIANGLES)
                glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
                             vec(0, 0.9, 0.15, 0.3))
                glNormal3f(0, 0, self.parent.cutting_direction)
                glVertex3f(plane_width, plane_height, 0)
                glVertex3f(0, plane_height, 0)
                glVertex3f(0, 0, 0)
                glVertex3f(plane_width, 0, 0)
                glVertex3f(plane_width, plane_height, 0)
                glVertex3f(0, 0, 0)
                glEnd()
                glEnable(GL_CULL_FACE)
                glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
                glEnable(GL_LINE_SMOOTH)
                orig_linewidth = (GLfloat)()
                glGetFloatv(GL_LINE_WIDTH, orig_linewidth)
                glLineWidth(4.0)
                glBegin(GL_LINE_LOOP)
                glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
                             vec(0, 0.8, 0.15, 1))
                glVertex3f(0, 0, 0)
                glVertex3f(0, plane_height, 0)
                glVertex3f(plane_width, plane_height, 0)
                glVertex3f(plane_width, 0, 0)
                glEnd()
                glLineWidth(orig_linewidth)
                glDisable(GL_LINE_SMOOTH)
                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
                glPopMatrix()

        glPopMatrix()
예제 #53
0
    def draw(self):
        self.plot._render_lock.acquire()
        self.camera.apply_transformation()

        calc_verts_pos, calc_verts_len = 0, 0
        calc_cverts_pos, calc_cverts_len = 0, 0

        should_update_caption = (clock() - self.last_caption_update >
                                 self.caption_update_interval)

        if len(self.plot._functions.values()) == 0:
            self.drawing_first_object = True

        try:
            dict.iteritems
        except AttributeError:
            # Python 3
            iterfunctions = iter(self.plot._functions.values())
        else:
            # Python 2
            iterfunctions = self.plot._functions.itervalues()

        for r in iterfunctions:
            if self.drawing_first_object:
                self.camera.set_rot_preset(r.default_rot_preset)
                self.drawing_first_object = False

            pgl.glPushMatrix()
            r._draw()
            pgl.glPopMatrix()

            # might as well do this while we are
            # iterating and have the lock rather
            # than locking and iterating twice
            # per frame:

            if should_update_caption:
                try:
                    if r.calculating_verts:
                        calc_verts_pos += r.calculating_verts_pos
                        calc_verts_len += r.calculating_verts_len
                    if r.calculating_cverts:
                        calc_cverts_pos += r.calculating_cverts_pos
                        calc_cverts_len += r.calculating_cverts_len
                except ValueError:
                    pass

        for r in self.plot._pobjects:
            pgl.glPushMatrix()
            r._draw()
            pgl.glPopMatrix()

        if should_update_caption:
            self.update_caption(calc_verts_pos, calc_verts_len,
                                calc_cverts_pos, calc_cverts_len)
            self.last_caption_update = clock()

        if self.plot._screenshot:
            self.plot._screenshot._execute_saving()

        self.plot._render_lock.release()
예제 #54
0
    def draw(self):
        if self.updateDraw:
            self.updateDraw = False

            current = self.height - self.borderPad
            for item in self.lines:
                line = item.get_label()
                line.y = current
                current -= line.height
            self.update_scrollbar()

        glDisable(GL_TEXTURE_2D)
        glPushMatrix()
        glTranslatef(self.x, self.y - self.height, 0)

        # border

        if self.border:
            if self.border3d:
                draw_rectangle(0, 0, self.width, self.height,
                               BORDER_COLOR_3D_1)
                draw_rectangle(1, 1, self.width - 1, self.height - 1,
                               BORDER_COLOR_3D_2)
                draw_rectangle(2, 2, self.width - 2, self.height - 2,
                               BORDER_COLOR_3D_3)
            else:
                draw_rectangle(0, 0, self.width, self.height, BORDER_COLOR)

        # background
        pad = self.borderPad
        glColor4ub(*(self.backColor + (255, )))
        glBegin(GL_QUADS)
        glVertex2f(pad, pad)
        glVertex2f(self.width - pad, pad)
        glVertex2f(self.width - pad, self.height - pad)
        glVertex2f(pad, self.height - pad)
        glEnd()

        glPushAttrib(GL_SCISSOR_BIT)
        x, y, width, height = self.player.get_scissor_box(
            self.x + self.borderPad, self.y - self.height + self.borderPad,
            self.listWidth, self.height - self.borderPad * 2)
        glScissor(x, y, width, height)
        glEnable(GL_SCISSOR_TEST)
        glTranslatef(0, self.yOffset, 0)
        for index, item in enumerate(self.lines):
            line = item.get_label()
            color = None
            if self.selected == index:
                color = (139, 190, 228)
            elif self.over == index:
                color = (191, 219, 240)
            if color is not None:
                draw_rectangle(pad, line.y - line.height,
                               self.listWidth + self.borderPad, line.y, color)
            line.draw()
        glPopAttrib()

        glPopMatrix()

        if self.scrollBar is not None:
            self.scrollBar.draw()
예제 #55
0
 def draw(self):
     gl.glColor4ub(255, 255, 255, 255)
     gl.glPushMatrix()
     self.transform()
     self.img.blit(0, 0)
     gl.glPopMatrix()
예제 #56
0
 def euler_rotate(self, angle, x, y, z):
     pgl.glPushMatrix()
     pgl.glLoadMatrixf(self._rot)
     pgl.glRotatef(angle, x, y, z)
     self._rot = get_model_matrix()
     pgl.glPopMatrix()
예제 #57
0
파일: kcclock.py 프로젝트: tkrym02/anaconda
    def draw(self):
        mid_x, mid_y = self.get_center()
        glLineWidth(2)
        if self.displayType == ANALOG_CLOCK:
            radius = min(self.width, self.height) / 2.0 - 10
            radius_end = radius - 10
            glPushMatrix()
            glTranslatef(mid_x, mid_y, 0)
            if self.clockLabels is not None or self.drawLines:
                for i in xrange(0, 12):
                    glPushMatrix()
                    angle = get_mark_angle(i + 1)
                    x_value = math.cos(angle)
                    y_value = math.sin(angle)
                    if self.drawLines:
                        glBegin(GL_LINES)
                        glColor3ub(*self.color)
                        glVertex2f(x_value * radius_end, y_value * radius_end)
                        glVertex2f(x_value * (radius - 20),
                                   y_value * (radius - 20))
                        glEnd()
                    if self.clockLabels is not None:
                        x = x_value * radius
                        y = y_value * radius
                        glTranslatef(x, y, 0)
                        self.clockLabels[-i].draw()
                    glPopMatrix()
            # second pointer
            second, minute, hour = self.get_time()
            if self.displaySeconds:
                display_pointer(get_second_minute_angle(second),
                                self.secondsColor, radius_end)

            if self.displayHours:
                display_pointer(get_hour_angle(hour + minute / 60.0),
                                self.hoursColor, radius_end / 1.5)

            if self.displayMinutes:
                display_pointer(
                    get_second_minute_angle(minute + second / 60.0),
                    self.minutesColor, radius_end)
            glPopMatrix()
            if self.border is not None:
                glPushMatrix()
                glTranslatef(self.x + 20, self.y - 20, 0.0)
                self.border.draw(GL_LINE_LOOP)
                glPopMatrix()

        elif self.displayType in (DIGITAL_CLOCK, CALENDAR):
            text = self.get_text()
            if text != self.text:
                self.label.text = text
                self.text = text
            glPushMatrix()
            glTranslatef(self.x, self.y, 0)
            self.label.draw()
            if self.displayType == DIGITAL_CLOCK and self.drawBorder:
                glBegin(GL_LINE_LOOP)
                glColor3ub(*self.color)
                glVertex2f(0, 0)
                glVertex2f(self.width, 0)
                glVertex2f(self.width, -self.height)
                glVertex2f(0, -self.height)
                glEnd()
            glPopMatrix()
예제 #58
0
    def draw(self):
        """Draw the particles system"""
        gl.glPushMatrix()
        self.transform()

        # color preserve - at least nvidia 6150SE needs that
        gl.glPushAttrib(gl.GL_CURRENT_BIT)
        # glPointSize(self.get_scaled_particle_size())

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

        gl.glEnable(gl.GL_POINT_SPRITE)
        gl.glTexEnvi(gl.GL_POINT_SPRITE, gl.GL_COORD_REPLACE, gl.GL_TRUE)

        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
        vertex_ptr = PointerToNumpy(self.particle_pos)
        gl.glVertexPointer(2, gl.GL_FLOAT, 0, vertex_ptr)

        gl.glEnableClientState(gl.GL_COLOR_ARRAY)
        color_ptr = PointerToNumpy(self.particle_color)
        gl.glColorPointer(4, gl.GL_FLOAT, 0, color_ptr)

        gl.glEnableVertexAttribArray(self.particle_size_idx)

        size_ptr = PointerToNumpy(self.particle_size_scaled)
        gl.glVertexAttribPointer(self.particle_size_idx, 1, gl.GL_FLOAT, False,
                                 0, size_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)

        # mode = GLint()
        # glTexEnviv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode )
        #
        # if self.color_modulate:
        #   glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE )
        # else:
        #   glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE )

        self.sprite_shader.install()
        self.sprite_shader.usetTex('sprite_texture', 0, gl.GL_TEXTURE_2D,
                                   self.texture.id)

        gl.glDrawArrays(gl.GL_POINTS, 0, self.total_particles)

        self.sprite_shader.uninstall()
        # un -blend
        gl.glPopAttrib()

        # color restore
        gl.glPopAttrib()

        # restore env mode
        # glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode)

        # disable states
        gl.glDisableVertexAttribArray(self.particle_size_idx)
        gl.glDisableClientState(gl.GL_COLOR_ARRAY)
        gl.glDisableClientState(gl.GL_VERTEX_ARRAY)

        gl.glDisable(gl.GL_POINT_SPRITE)
        gl.glDisable(gl.GL_PROGRAM_POINT_SIZE)
        gl.glDisable(gl.GL_TEXTURE_2D)

        gl.glPopMatrix()
예제 #59
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
예제 #60
0
 def init_rot_matrix(self):
     pgl.glPushMatrix()
     pgl.glLoadIdentity()
     self._rot = get_model_matrix()
     pgl.glPopMatrix()