def on_draw(): # clears the background with the background color gl.glClearColor(*background) gl.glClear(gl.GL_COLOR_BUFFER_BIT) # draw in a loop boundary = winsize - 100 gap = (winsize - boundary) / 2 i_width = boundary / len(rgb1) i_height = boundary / 2 # the first line for idx, rgb in enumerate(rgb1): gl.glColor3f(*rgb) gl.glBegin( gl.GL_QUADS ) # start drawing a rectangle in counter-clockwise (CCW) order gl.glVertex2f(gap + idx * i_width, gap + i_height) # bottom left point gl.glVertex2f(gap + (idx + 1) * i_width, gap + i_height) # bottom right point gl.glVertex2f(gap + (idx + 1) * i_width, gap + boundary) # top right point gl.glVertex2f(gap + idx * i_width, gap + boundary) # top left point gl.glEnd() label = pyglet.text.Label(str(color1[idx]), font_size=7, x=gap + idx * i_width, y=gap + boundary + 20) label.draw() # # # the second line for idx, rgb in enumerate(rgb2): gl.glColor3f(*rgb) gl.glBegin( gl.GL_QUADS ) # start drawing a rectangle in counter-clockwise (CCW) order gl.glVertex2f(gap + idx * i_width, gap) # bottom left point gl.glVertex2f(gap + (idx + 1) * i_width, gap) # bottom right point gl.glVertex2f(gap + (idx + 1) * i_width, gap + i_height) # top right point gl.glVertex2f(gap + idx * i_width, gap + i_height) # top left point gl.glEnd() label = pyglet.text.Label(str(color2[idx]), font_size=7, x=gap + idx * i_width, y=gap - 20) label.draw()
def on_draw(): # clears the screen with the background color gl.glClear(gl.GL_COLOR_BUFFER_BIT) # sets wire-frame mode gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE) # draws the current model self.current_model.draw()
def clear_and_setup_window(self): gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glMatrixMode(gl.GL_PROJECTION) # Select The Projection Matrix gl.glLoadIdentity() # Reset The Projection Matrix field_of_view_y = 100 aspect_ratio = self.window.width if self.window.height == 0 else self.window.width / self.window.height z_clip_near = 0.1 z_clip_far = 1000.0 glu.gluPerspective(field_of_view_y, aspect_ratio, z_clip_near, z_clip_far)
def on_draw(): gl.glColorMask(True, True, True, True) window.clear() with rc.default_shader, rc.default_states: with camera.right: gl.glColorMask(False, True, True, True) monkey.draw() gl.glClear(gl.GL_DEPTH_BUFFER_BIT) with camera.left: gl.glColorMask(True, False, False, True) monkey.draw()
def draw(self): # clears the screen with the background color gl.glClear(gl.GL_COLOR_BUFFER_BIT) gl.glClear(gl.GL_DEPTH_BUFFER_BIT) gl.glLoadIdentity() # # sets the position for the camera gl.glTranslatef(self.x, self.y, self.z) # sets the rotation for the camera gl.glRotatef(self.rx, 1, 0, 0) gl.glRotatef(self.ry, 0, 1, 0) gl.glRotatef(self.rz, 0, 0, 1) # self.draw_axes() for box in self.boxes: self.render_model(box, fill=False) # TODO Note: won't account for changing number of boids if that is ever implemented for i, (boids_m, atts) in enumerate(self.swarm_models): swarm = self.swarms[i] for j, boid_m in enumerate(boids_m): # experimental: invert colour if feeding # if swarm.boids[j].feeding: # boid_m.color = invert_colour(boid_m.color) new_loc = list(swarm.boids[j].location)[:3] boid_m.x, boid_m.y, boid_m.z = new_loc # boid direction based on velocity new_vel = list(normalise(swarm.boids[j].velocity[:3])) # TODO completely wrong and also stupid but seems to be good enough if you don't look too hard # boid_m.rx = -90-math.degrees(math.asin(new_vel[2]/math.sqrt(new_vel[1]**2 + new_vel[2]**2))) boid_m.ry = (90-math.degrees(math.asin(new_vel[0]/math.sqrt(new_vel[2]**2 + new_vel[0]**2)))) boid_m.rz = -(90-math.degrees(math.asin(new_vel[1]/math.sqrt(new_vel[0]**2 + new_vel[1]**2)))) self.render_model(boid_m) for j, att in enumerate(atts): new_att = list(swarm.attractors[j].location)[:3] att.x, att.y, att.z = new_att if swarm.attractors[j].is_active: self.render_model(att, frame=True)
def draw(self, viewport): gl.glClearColor(183 / 255.0, 196 / 255.0, 200 / 255.0, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) x1 = viewport.tl.x x2 = viewport.br.x backgrounds = [ (self.clouds, self.clouds.width), (self.fg, self.fg.width), ] for img, w in backgrounds: cx = x1 - x1 % w - w while cx < x2: img.blit(cx, 0) cx += w
def draw(self): # clears the screen with the background color gl.glClear(gl.GL_COLOR_BUFFER_BIT) gl.glClear(gl.GL_DEPTH_BUFFER_BIT) gl.glLoadIdentity() # # sets the position gl.glTranslatef(self.x, self.y, self.z) # sets the rotation gl.glRotatef(self.rx, 1, 0, 0) gl.glRotatef(self.ry, 0, 1, 0) gl.glRotatef(self.rz, 0, 0, 1) self.draw_ground_plane() for model in self.models: self._model_render(model)
def draw(self): # clears the screen with the background color gl.glClear(gl.GL_COLOR_BUFFER_BIT) gl.glClear(gl.GL_DEPTH_BUFFER_BIT) gl.glLoadIdentity() # # sets the position for the camera gl.glTranslatef(self.x, self.y, self.z) # sets the rotation for the camera gl.glRotatef(self.rx, 1, 0, 0) gl.glRotatef(self.ry, 0, 1, 0) gl.glRotatef(self.rz, 0, 0, 1) self.render_model(self.box_model, fill=False) for colour_model in self.colour_models: self.render_model(colour_model, frame=False) for rc_model in self.rand_col_models: self.render_model(rc_model, frame=False)
def draw(self, viewport): gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) alt = viewport.bl.y h = viewport.height w = viewport.width c1 = self.gradient.colour(alt) c2 = self.gradient.colour(alt + 10000) o = v(0, 0) x = v(w, 0) y = v(0, h) vs = [o, x, x + y, y] cs = [c1, c1, c2, c2] pyglet.graphics.draw(4, gl.GL_QUADS, ('v2f', list(walk(vs))), ('c3f', list(walk(cs))) )
def drawChessBoardGl(self): self.setupGl() # clears the background with the background color gl.glClear(gl.GL_COLOR_BUFFER_BIT) # square color gl.glColor3f(*self.greenF3) squareWidth = 0.4 minF = -1.6 maxF = 1.6 for h in np.arange(0.0, 2 * maxF, 2 * squareWidth): #Draws the chess board 2 lines by 2 lines for i in np.arange(minF, maxF, 2 * squareWidth): # draws a square gl.glBegin(gl.GL_QUADS) gl.glVertex3f(i + squareWidth, minF + squareWidth + h, 0) gl.glVertex3f(i, minF + squareWidth + h, 0) gl.glVertex3f(i, minF + h, 0) gl.glVertex3f(i + squareWidth, minF + h, 0) gl.glEnd() gl.glBegin(gl.GL_QUADS) gl.glVertex3f(i + 2 * squareWidth, minF + 2 * squareWidth + h, 0) gl.glVertex3f(i + squareWidth, minF + 2 * squareWidth + h, 0) gl.glVertex3f(i + squareWidth, minF + squareWidth + h, 0) gl.glVertex3f(i + 2 * squareWidth, minF + squareWidth + h, 0) gl.glEnd() pyglet.graphics.draw( 8, pyglet.gl.GL_LINES, ("v2f", (minF, minF, minF, maxF, maxF, minF, maxF, maxF, minF, minF, maxF, minF, minF, maxF, maxF, maxF)), ('c3B', (0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0)))
def init(): gl.glClearColor(0.9, 0.9, 0.9, 1.0) gl.glClear(gl.GL_COLOR_BUFFER_BIT)