Beispiel #1
0
    def on_draw(self):
        """
        Render the screen.
        """
        start = time.time()

        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glDisable(GL.GL_BLEND)

        GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.vertex_vbo_id)
        GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
        GL.glVertexPointer(2, GL.GL_FLOAT, 0, 0)

        GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.color_vbo_id)
        GL.glEnableClientState(GL.GL_COLOR_ARRAY)
        GL.glColorPointer(3, GL.GL_FLOAT, 0, 0)

        offset = 0
        for shape in self.shape_list:
            render_rect_filled(shape, offset)
            offset += 4

        elapsed = time.time() - start
        print(elapsed)
Beispiel #2
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)
Beispiel #3
0
def vykresli():
     #Vykresleni hraciho pole
    
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    nakresli_obdelnik(0, 0, SIRKA, VYSKA, mode = gl.GL_LINE_STRIP)
    
    #vykresleni pulici cary   
    
    nakresli_caru(SIRKA//2, 0, SIRKA//2, VYSKA)
    
    #micek
       
    nakresli_obdelnik(*micek, mode = gl.GL_QUADS)
    
    #palky
    
    nakresli_obdelnik(*palka1, mode = gl.GL_QUADS)
    nakresli_obdelnik(*palka2, mode = gl.GL_QUADS)
    #nazev hry
    label = pyglet.text.Label("Hra PONG",
                              font_size = NADPIS_y,
                              x = window.width, y = window.height - NADPIS_y,
                              anchor_x = 'right')
    label.draw()   
    
    #vykresleni micku
    #vykresleni palek
    #nastaveni pocatecniho skore, zobrazeni skor   
    vypis_skore()
Beispiel #4
0
 def run(self):
     while not self.has_exit:
         dt = pyglet.clock.tick()
         self.dispatch_events()
         gl.glClear(gl.GL_COLOR_BUFFER_BIT)
         gl.glLoadIdentity()
         self.shader.use()
         self.shader["real"] = self.real
         self.shader["w"] = self.w
         self.shader["imag"] = self.imag
         self.shader["h"] = self.h
         gl.glBegin(gl.GL_QUADS)
         gl.glVertex3f(0.0, 0.0, 0.0)
         gl.glVertex3f(0.0, self.height, 0.0)
         gl.glVertex3f(self.width, self.height, 0.0)
         gl.glVertex3f(self.width, 0.0, 0.0)
         gl.glEnd()
         self.shader.stop()
         if self.show_fps:
             self.fps.draw()
         if self.auto_zoom_in:
             self.zoom_in(dt)
         if self.auto_zoom_out:
             self.zoom_out(dt)
         self.key_move(dt=dt)
         self.flip()
Beispiel #5
0
 def on_draw(self):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
     gl.glColor3ub(255,255,255)
     self.heading.draw()
     for row in self.items:
         for item in row:
             item.draw()
Beispiel #6
0
 def draw(self):
     gl.glClear(gl.GL_DEPTH_BUFFER_BIT)
     if self.game.game_over:
         if self.game.game_lost:
             gl.glBegin(gl.GL_QUADS)
             gl.glColor3f(1, 1, 1)
             gl.glVertex3f(0, 0, -0.9)
             gl.glVertex3f(0, defs.WINDOW_HEIGHT, -0.9)
             gl.glVertex3f(defs.WINDOW_WIDTH, defs.WINDOW_HEIGHT, -0.9)
             gl.glVertex3f(defs.WINDOW_WIDTH, 0, -0.9)
             gl.glEnd()
             self.you_died.draw()
             self.you_died2.draw()
             if not self.died:
                 for name in self.VALUES:
                     getattr(self, name + '_label').color = (0, 0, 0, 255)
             self.died = True
         else:
             gl.glBegin(gl.GL_QUADS)
             gl.glColor3f(0, 0, 0)
             gl.glVertex3f(0, 0, -0.9)
             gl.glVertex3f(0, defs.WINDOW_HEIGHT, -0.9)
             gl.glVertex3f(defs.WINDOW_WIDTH, defs.WINDOW_HEIGHT, -0.9)
             gl.glVertex3f(defs.WINDOW_WIDTH, 0, -0.9)
             gl.glEnd()
             self.you_win.draw()
     for name in self.VALUES:
         getattr(self, name + '_label').draw()
Beispiel #7
0
    def on_draw(self):
        gl.glClearColor(0.5, 0.69, 1.0, 1.0)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        self.cam.apply()

        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glEnable(gl.GL_LIGHTING)
        gl.glEnable(gl.GL_CULL_FACE)

        render_light((2, 10, -2))

        gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT_AND_DIFFUSE, to_gl_float([0.7, 0.7, 0.7, 1.0]))

        check_draw_distance(self.cam.current_chunk)

        if len(meshing_list) > 0:
            chunks[meshing_list.pop(0)].mesh()

        for chunk in active_chunks:
            chunks[chunk].vbo.draw()

        self.cam.ui_mode()

        self.cam.ui.draw()

        self.cam.perspective()
        self.cam.apply()
def on_draw():
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()

    # draw_obj(bear, bear_tex)
    draw_obj(ball, ball_tex)
Beispiel #9
0
	def on_draw(self, gl=pyglet.gl):
		"""Clear the current OpenGL context, reset the model/view matrix and
		invoke the `draw()` methods of the renderers in order
		"""
		gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
		gl.glLoadIdentity()
		BaseWorld.draw_renderers(self)
Beispiel #10
0
    def on_draw(self):
        self.parent.set_caption(str(pyglet.clock.get_fps()))
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        gl.glColor4ub(*[255,255,255,255])
        self.room.bg.blit(0,0)

        self.room.render()
        
        gl.glColor4ub(255,255,255,255)
        self.player.draw()
        self.room.lightbatch.draw()
        self.player.draw_eye()
        self.player.draw_integrity()
        
        if self.pause:
            gl.glColor4ub(50,50,50,150)
            left = self.message['text'].x-self.message['text'].width/2 -5
            down = self.message['text'].y-self.message['text'].height/2 -5
            right = self.message['text'].x+self.message['text'].width/2 + 5
            up = self.message['text'].y+self.message['text'].height/2 + 5
            gl.glRecti(left,down,right,up)
            gl.glLineWidth(2)
            gl.glColor4ub(200,200,200,200)
            gl.glBegin(gl.GL_LINE_LOOP)
            gl.glVertex2i(left,down)
            gl.glVertex2i(left,up)
            gl.glVertex2i(right,up)
            gl.glVertex2i(right,down)
            gl.glEnd()
            gl.glLineWidth(1)
            gl.glColor4ub(255,255,255,255)
            self.message['text'].draw()
            self.message['helper'].draw()
            self.message['sprite'].draw()
Beispiel #11
0
 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()
Beispiel #12
0
  def run(self, dt):
    ## UPDATE ##
    # timestep ala http://gafferongames.com/game-physics/fix-your-timestep/
    if dt > .25: # avoid spiral of death (updating taking longer than framerate)
      dt = .25
    self.accumulatedFrameTime += dt
    while self.accumulatedFrameTime >= self.updateRate:
      self.accumulatedFrameTime -= self.updateRate
      self.levelTime = time.time() - self.levelStartTime
      for entity in self.groups['updating']:
        entity.update(self.updateRate) # update all entities
      self._processRemoving()
      self._processAdding()
      for level in self.groups['level']:
        level.update(self.updateRate) # this will do the physics

    ## DRAW ##
    gl.glClearColor(0,0,0, 0)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    gl.glLoadIdentity()

    self.camera.track() # does camera work (such as what it focuses on)
    for name in self.drawLayerNames:
      shift = Vec2d() if name.startswith('UI') else None
      with self.camera.shiftView(shift):
        for entity in self.drawLayers[name]: # TODO: not iterate over batched things
          entity.draw()
        self.drawLayersBatch[name].draw()

    self.fps_display.draw()
Beispiel #13
0
 def on_draw(self):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
     self.grid.draw()
     self.score_bar.draw()
     self.time_bar.draw()
     if self.show_scores:
         self.grid.draw_scores()
Beispiel #14
0
 def OnDraw(self, *args, **kwargs):
     """Draw the window."""
     self.pygletcontext.set_current()
     glClearColor(*self.color_background)
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
     self.draw_objects()
     self.canvas.SwapBuffers()
Beispiel #15
0
 def clear_window(self, color):
     '''
     Clear window color and depth buffers, using the given color
     '''
     r, g, b, _ = color
     gl.glClearColor(r, g, b, 1.0)
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
def on_draw():
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()

    for block in blocks:
        draw_block(block)
    def render(self):
        try:
            if self._kill:
                pyg_stop()
                return
            if self.state:
                if self._create_draw:
                    self.create_drawable_objects()
                if self._to_update:
                    self._update_sprites()
                if self._rebuild_panel:
                    self.panel.from_list(
                            sorted([(score.points, k[0], score.str_nocolor()) for k, score in self.scores.items()],
                                   reverse=True))

                gl.glClear(gl.GL_COLOR_BUFFER_BIT)
                self._background.draw()
                for d in self._sprites.values():
                    d.draw()
                self.hud.draw()
                self.panel.draw()
                return True
            else:
                for d in self.get_welcome():
                    d.draw()
            return True
        except Exception, e:
            time.sleep(0.0001)
            print(e, traceback.print_exc())
            raise e
Beispiel #18
0
Datei: Snake.py Projekt: SDRU/had
def drawing():
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)  # smaz obsah okna (vybarvi na cerno)
    gl.glColor3f(0, 1, 0)  # nastav barvu kresleni na zelenu

    ### Plots the snake body
    for i in range(0,len(snake_position)-1):
        draw_rectangle(PIECE*snake_position[i][0],PIECE*snake_position[i][1],PIECE*(snake_position[i][0]+1),PIECE*(snake_position[i][1]+1))

    ### Snake head in blue
    gl.glColor3f(0, 0, 1)
    draw_rectangle(PIECE*snake_position[-1][0],PIECE*snake_position[-1][1],PIECE*(snake_position[-1][0]+1),PIECE*(snake_position[-1][1]+1))
    
    ### Food
    draw_rectangle(PIECE*food_position[0],PIECE*food_position[1],PIECE*(food_position[0]+1),PIECE*(food_position[1]+1))
    ### Score
    draw_text(str(N-20),PIECE*SCORE_POSITION[0],PIECE*SCORE_POSITION[1],'left', PIECE*FONT_SIZE)
    ### Walls
    gl.glColor3f(0, 1, 0)  # nastav barvu kresleni na zelenu   
    draw_rectangle(0, 0, PIECE*WALL_THICKNESS, PIECE*HEIGHT)
    draw_rectangle(0, 0, PIECE*WIDTH, PIECE*WALL_THICKNESS)
    draw_rectangle(PIECE*WIDTH-PIECE*WALL_THICKNESS,0,PIECE*WIDTH,PIECE*HEIGHT)
    draw_rectangle(0,PIECE*HEIGHT-PIECE*WALL_THICKNESS,PIECE*WIDTH,PIECE*HEIGHT)

    if QUIT_SIGNAL==1:
        draw_text('GAME OVER',PIECE*WIDTH//2-PIECE*FONT_SIZE*4,PIECE*HEIGHT//2-PIECE*FONT_SIZE//2,'left', PIECE*FONT_SIZE)
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)
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)
Beispiel #21
0
def start():
    gl.glClearColor(0.0, 0.0, 0.0, 1.0)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)

    global width, height, scale, pacman
    pacman = Pacman()
    scale = 20

    w = board_width * scale
    h = board_height * scale + 100

    window.set_size(w, h)
    x, y = window.get_location()
    window.set_location(x, y - 150)

    width = w // scale
    height = h // scale

    enemies['red'] = Enemy('red')
    enemies['pink'] = Enemy('pink')
    enemies['cyan'] = Enemy('cyan')
    enemies['orange'] = Enemy('orange')

    parse_board()
    draw_board()
    draw_dots()
    draw_ui()
    draw_score()
    draw_lives()
    set_speeds(0.075)

    pyglet.clock.schedule_once(toggle_mode, 7)
    pyglet.clock.schedule_interval(game_loop, 1 / 60)

    pyglet.app.run()
Beispiel #22
0
 def on_draw(self):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
     if self.app.show_fps:
         self.fps_display.draw()
     self.app.on_draw()
Beispiel #23
0
def on_draw():
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    #flip_origin_top_left()
    #plot_test_box()
    sprite.scale = min(window.width / sprite.image.width,
                       window.height / sprite.image.height)
    sprite.draw()
    plot_box_label_yml(my_yml_dict, sprite.scale_x, sprite.scale_y)
Beispiel #24
0
 def OnDraw(self, *args, **kwargs):
     "Draw the window."
     # clear the context
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     # draw objects
     self.draw_objects()
     # update screen
     self.SwapBuffers()
Beispiel #25
0
def start_render():
    """
    Get set up to render. Required to be called before drawing anything to the
    screen.
    """
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
Beispiel #26
0
 def update_drawing(self):
     # self.draw_rect(0,0,self.width,self.height,(0,0,0))
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
     self.clear()
     self.main_batch.draw()
     print('drwa')
     self.main_batch = pyglet.graphics.Batch()
     self.save_drawing()
Beispiel #27
0
    def paintGL(self):
        """
        Clears the back buffer than calls the on_draw method
        """
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glLoadIdentity()

        self.on_draw()
Beispiel #28
0
def on_draw():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glLoadIdentity()
    glTranslatef(0, 0, -4)
    glRotatef(rz, 0, 0, 1)
    glRotatef(ry, 0, 1, 0)
    glRotatef(rx, 1, 0, 0)
    torus.draw()
Beispiel #29
0
 def clear(self, color):
     "Clear the window background with the given color"
     glClearColor(
         color[0] / 255,
         color[1] / 255,
         color[2] / 255,
         1.0)
     glClear(GL_COLOR_BUFFER_BIT)
Beispiel #30
0
def draw_camera():
    gl.glViewport(0, 0, w, h)
    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    gl.glOrtho(0, w, 0, h, -1, 1)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    gl.glLoadIdentity()
Beispiel #31
0
def start_render():
    """
    Get set up to render. Required to be called before drawing anything to the
    screen.
    """
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
Beispiel #32
0
                def on_expose():
                    gl.glClearColor(1.0, 1.0, 1.0, 1.0)
                    gl.glClear(gl.GL_COLOR_BUFFER_BIT)

                    img.blit(
                        (win.width - img.width) / 2,
                        (win.height - img.height) / 2
                    )
Beispiel #33
0
    def activate(self):

        gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, self._buffer)

        gl.glPushAttrib(gl.GL_VIEWPORT_BIT)
        gl.glViewport(0, 0, *self.render_target_size)

        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
Beispiel #34
0
    def on_draw(self, gl=pyglet.gl):
        """Clear the current OpenGL context, reset the model/view matrix and
		invoke the `draw()` methods of the renderers in order
		"""
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glLoadIdentity()
        for renderer in self.renderers:
            renderer.draw()
Beispiel #35
0
                def on_expose():
                    gl.glClearColor(1.0, 1.0, 1.0, 1.0)
                    gl.glClear(gl.GL_COLOR_BUFFER_BIT)

                    img.blit(
                        (win.width - img.width) / 2,
                        (win.height - img.height) / 2
                    )
Beispiel #36
0
 def OnDraw(self, *args, **kwargs):
     "Draw the window."
     #clear the context
     gl.glClear(gl.GL_COLOR_BUFFER_BIT|gl.GL_DEPTH_BUFFER_BIT)
     #draw objects
     self.draw_objects()
     #update screen
     self.SwapBuffers()
Beispiel #37
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)
Beispiel #38
0
    def on_draw():
        #w.clear()
        global parent
        global parentdiff
        global olddrawing,newdrawing
        global blitted
        global image_pixels
        global keeps
        global i

        if not blitted:
            """
            At the start we've not seen the target before,
            so draw it and store the pixel data.
            """
            gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, 0)
            gl.glClear(gl.GL_COLOR_BUFFER_BIT)
            pic.blit(0,0)
            blitted = 1
            image_pixels = (gl.GLubyte * (4*size))(0)
            gl.glReadPixels(0,
                            0,
                            newdrawing.width,
                            newdrawing.height,
                            gl.GL_RGBA,
                            gl.GL_UNSIGNED_BYTE,
                            image_pixels
                           )
            image_pixels = np.frombuffer(image_pixels, dtype=np.uint8).astype(np.int32)

        # Draw the new child
        newdrawing.draw()

        # Read the pixel data for the child and find out if its any good
        gl.glReadPixels(0,
                        0,
                        newdrawing.width,
                        newdrawing.height,
                        gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, a)
        diff = compute_diff(a)

        if parent == None or diff < parentdiff:
            # The new drawing is better.
            # Redraw the parent as this child.
            # Set this child's diff as the new one to beat.
            parent = image.ImageData(newdrawing.width,newdrawing.height,"RGBA",a)
            parentdiff = diff
            draw_parent(parent, newdrawing.width)
        else:
            # The new drawing sucks. Replace it
            newdrawing = olddrawing
        i += 1

        if (i % 20 == 0):
            # Use the window title to let the user know how we're doing
            w.set_caption(str(fps.get_fps())+" "+str(parentdiff) + " " + str(log(parentdiff,10))+ " " + str(i))

        fps.tick()
Beispiel #39
0
    def _endOfFlip(self, clearBuffer):
        """Override end of flip with custom color channel masking if required.
        """
        if clearBuffer:
            GL.glClear(GL.GL_COLOR_BUFFER_BIT)

        # nop if we are still setting up the window
        if hasattr(self, '_eyeBuffers'):
            self.setBuffer('left', clear=clearBuffer)
Beispiel #40
0
def on_draw():
    global started
    glClearColor(1, 0.9, 0.8, 0)
    glClear(GL_COLOR_BUFFER_BIT)
    if not started:
        return
    cur.draw()
    for line in lines:
        line.draw()
Beispiel #41
0
    def reset(self):
        """New frame"""
        pyglet.clock.tick()
        self.display_surface.dispatch_events()
        pyglet.gl.glClearColor(1, 1, 1, 1)
        from pyglet.gl import glClear
        glClear(pyglet.gl.GL_COLOR_BUFFER_BIT)

        self.main_batch = pyglet.graphics.Batch()
Beispiel #42
0
    def on_expose(self):
        gl.glClearColor(0.5, 0, 0, 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        gl.glLoadIdentity()
        self.draw()
        self.window.flip()

        if self.capture_regression_image():
            self.window.exit_handler.has_exit = True
Beispiel #43
0
def draw_board():
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)

    for x, y, direction in walls:
        [
            draw_sub_rect(x, height - y - 4, sx, sy, sw, sh, (0.0, 0.0, 1.0),
                          stage_batch)
            for sx, sy, sw, sh in wall_vertices[direction]
        ]
Beispiel #44
0
    def on_draw(self, context):
        self.camera.push_state()

        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        self.tilemap.draw(IndexGroup2D(self.static_grid, self.dynamic_grid))

        self.fps_counter.draw()

        self.camera.pop_state()
Beispiel #45
0
    def on_draw(self):
        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, _junk = self.scene.graph['camera']

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

        # dragging the mouse moves the view transform (but doesn't alter the
        # scene)
        transform_view = _view_transform(self.view)
        gl.glMultMatrixf(_gl_matrix(transform_view))

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

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

            # if the flag isn't defined, this will be None
            # by checking False explicitly, it makes the default
            # behaviour to render meshes with no flag defined.
            # if self.node_flag(name_node, 'visible') is False:
            #    continue

            transform, geometry_name = self.scene.graph[current_node]

            if geometry_name is None:
                continue

            mesh = self.scene.geometry[geometry_name]

            if (hasattr(mesh, 'visual') and
                    mesh.visual.transparency):
                # put the current item onto the back of the queue
                if count < count_original:
                    node_names.append(current_node)
                    continue

            # add a new matrix to the model stack
            gl.glPushMatrix()
            # transform by the nodes transform
            gl.glMultMatrixf(_gl_matrix(transform))
            # 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()
Beispiel #46
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)
Beispiel #47
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)
Beispiel #48
0
def on_draw():
    """Clear the window on every frame and draw in game objects."""
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    gl.glColor4f(*SETTINGS.graphics.background)
    WINDOW.clear()
    helpers.draw_fan(SHAPES[0].shape.body.position, POINTS, (0.8, 0.3, 0.2, 1))
    FPS.draw()
    for id_, shape in SHAPES.items():
        if id_ == 0:
            helpers.draw_shape(shape.shape, shape.properties)
Beispiel #49
0
def draw_board():
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)

    for x, y in board_visibility:
        draw_rect(x, y, (1.0, 1.0, 1.0))
        draw_number(x, y, board[y][x])

    [draw_rect(x, y, (1.0, 0.0, 0.0)) for x, y in flags]

    batch.draw()
Beispiel #50
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)
 def draw(self):
     """
     Draw the world.
     """
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
     gl.glClearColor(255, 255, 255, 255)
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
     for ent in self.ents.values():
         ent.draw()
Beispiel #52
0
def refresh_buffer():
    global passes, start_time
    with targetbuffer:
        gl.glViewport(0, 0, FB_WIDTH, FB_HEIGHT)

        gl.glClearColor(0.0, 0.0, 0.0, 1.0)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

    passes = 0
    start_time = time()
Beispiel #53
0
 def on_key_press(self, symbol, modifiers):
     if symbol == key.R:
         self.rotation_x = 90
         self.rotation_y = 0
         self.x = 0
         self.y = 0
         self.zoom_level = 4
         gl.glDisable(gl.GL_DEPTH_TEST)
         gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     return None
Beispiel #54
0
    def on_draw(self, context):
        self.camera.push_state()

        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        self.tilemap.draw()
        self.player.draw()
        self.origin_text.draw()
        self.origin_text_x.draw()
        self.origin_text_y.draw()

        self.camera.pop_state()
Beispiel #55
0
 def display(self, width, height):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glLoadIdentity()
     gl.glOrtho(0, width, 0, height, -1, 1)
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
     gl.glTranslatef(self.trans[0], self.trans[1], 0)
     gl.glScalef(self.trans[2], self.trans[2], self.trans[2])
     # FIXME draw only visible part?
     self.renderer.render()
Beispiel #56
0
    def set_up_perspective(self):
        glViewport(0, 0, self.width * 2, self.height * 2)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glEnable(GL_DEPTH_TEST)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(60., self.perspective, 1., 1000.)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        glRotatef(90, 1, 0, 0)
Beispiel #57
0
 def setup(self):
     """ Does some one-time OpenGL setup.
     """
     gl.glEnable(gl.GL_LIGHTING)
     gl.glClearColor(1, 1, 1, 1)
     gl.glColor3f(1, 0, 0)
     gl.glEnable(gl.GL_DEPTH_TEST)
     gl.glEnable(gl.GL_CULL_FACE)
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     gl.glLoadIdentity()
     self.is_setup = True
Beispiel #58
0
    def OnDraw(self, *args, **kwargs):
        """Draw the window."""
        # clear the context
        if not self.IsShown():
            return

        self.canvas.SetCurrent(GLPanel.SharedGLContext)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        # draw objects
        self.draw_objects()
        # update screen
        self.SwapBuffers()
Beispiel #59
0
def on_draw():
    glClear(GL_COLOR_BUFFER_BIT)
    BG_SPRITE.y = WINDOW.height - BG_SPRITE.height
    BG_SPRITE.draw()

    for row in board.board:
        for tile in row:
            if tile is not None:
                tile.batch.draw()
    if board.lost:
        LOST_TEXT.text = "Final Score: " + str(board.score)
        LOST_SCREEN.draw()