def rectangle(self, x1, y1, x2, y2, material_index = 0): self.materials[material_index].activate() if self.materials[material_index].is_alpha(): opengl.glEnable(opengl.GL_BLEND) # opengl.glBegin (opengl.GL_QUADS) # opengl.glTexCoord2f(0.0, 0.0); opengl.glVertex2i(x1, y1) # opengl.glTexCoord2f(0.0, 1.0); opengl.glVertex2i(x1, y2) # opengl.glColor4f(*self.corner_colors[material_index]) # opengl.glTexCoord2f(1.0, 1.0); opengl.glVertex2i(x2, y2) # opengl.glColor4f(*self.materials[material_index].diffuse) # opengl.glTexCoord2f(1.0, 0.0); opengl.glVertex2i(x2, y1) # opengl.glEnd() if self.corner_colors[material_index]: if (x2 - x1) // 2 < y2 - y1: opengl.glBegin (opengl.GL_QUADS) opengl.glVertex2i(x1, y1) opengl.glVertex2i(x1, y2) opengl.glVertex2i(x2, y2 - (x2 - x1) // 2) opengl.glVertex2i(x2, y1) opengl.glEnd() opengl.glBegin (opengl.GL_TRIANGLES) opengl.glVertex2i(x2, y2 - (x2 - x1) // 2) opengl.glVertex2i(x1, y2) opengl.glColor4f(*self.corner_colors[material_index]) opengl.glVertex2i(x2, y2) opengl.glEnd() else: opengl.glBegin (opengl.GL_QUADS) opengl.glVertex2i(x1, y1) opengl.glVertex2i(x1, y2) opengl.glVertex2i(x2 - 2 * (y2 - y1), y2) opengl.glVertex2i(x2, y1) opengl.glEnd() opengl.glBegin (opengl.GL_TRIANGLES) opengl.glVertex2i(x2, y1) opengl.glVertex2i(x2 - 2 * (y2 - y1), y2) opengl.glColor4f(*self.corner_colors[material_index]) opengl.glVertex2i(x2, y2) opengl.glEnd() else: opengl.glBegin (opengl.GL_QUADS) opengl.glTexCoord2f(0.0, 0.0); opengl.glVertex2i(x1, y1) opengl.glTexCoord2f(0.0, 1.0); opengl.glVertex2i(x1, y2) opengl.glTexCoord2f(1.0, 1.0); opengl.glVertex2i(x2, y2) opengl.glTexCoord2f(1.0, 0.0); opengl.glVertex2i(x2, y1) opengl.glEnd() soya.DEFAULT_MATERIAL.activate() if self.line_width and self.line_colors[material_index][3]: opengl.glColor4f(*self.line_colors[material_index]) opengl.glLineWidth(self.line_width) opengl.glBegin (opengl.GL_LINE_LOOP) opengl.glVertex2i(x1, y1) opengl.glVertex2i(x1, y2) opengl.glVertex2i(x2, y2) opengl.glVertex2i(x2, y1) opengl.glEnd() opengl.glLineWidth(1.0)
def triangle(self, side, x1, y1, x2, y2, material_index = 0): self.materials[material_index].activate() if self.materials[material_index].is_alpha(): opengl.glEnable(opengl.GL_BLEND) opengl.glBegin (opengl.GL_TRIANGLES) if side == 0: opengl.glTexCoord2f(0.0, 0.5); opengl.glVertex2i(x1, (y1 + y2) // 2) opengl.glTexCoord2f(1.0, 1.0); opengl.glVertex2i(x2, y2) opengl.glTexCoord2f(1.0, 0.0); opengl.glVertex2i(x2, y1) elif side == 1: opengl.glTexCoord2f(1.0, 0.5); opengl.glVertex2i(x2, (y1 + y2) // 2) opengl.glTexCoord2f(0.0, 0.0); opengl.glVertex2i(x1, y1) opengl.glTexCoord2f(0.0, 1.0); opengl.glVertex2i(x1, y2) elif side == 2: opengl.glTexCoord2f(0.5, 0.0); opengl.glVertex2i((x1 + x2) // 2, y1) opengl.glTexCoord2f(0.0, 1.0); opengl.glVertex2i(x1, y2) opengl.glTexCoord2f(1.0, 1.0); opengl.glVertex2i(x2, y2) elif side == 3: opengl.glTexCoord2f(0.5, 1.0); opengl.glVertex2i((x1 + x2) // 2, y2) opengl.glTexCoord2f(1.0, 0.0); opengl.glVertex2i(x2, y1) opengl.glTexCoord2f(0.0, 0.0); opengl.glVertex2i(x1, y1) opengl.glEnd() soya.DEFAULT_MATERIAL.activate() if self.line_width and self.line_colors[material_index][3]: opengl.glColor4f(*self.line_colors[material_index]) opengl.glLineWidth(self.line_width) opengl.glBegin (opengl.GL_LINE_LOOP) if side == 0: opengl.glVertex2i(x1, (y1 + y2) // 2) opengl.glVertex2i(x2, y1) opengl.glVertex2i(x2, y2) elif side == 1: opengl.glVertex2i(x2, (y1 + y2) // 2) opengl.glVertex2i(x1, y1) opengl.glVertex2i(x1, y2) elif side == 2: opengl.glVertex2i((x1 + x2) // 2, y1) opengl.glVertex2i(x1, y2) opengl.glVertex2i(x2, y2) elif side == 3: opengl.glVertex2i((x1 + x2) // 2, y2) opengl.glVertex2i(x1, y1) opengl.glVertex2i(x2, y1) opengl.glEnd() opengl.glLineWidth(1.0)