from OpenGL.GL import * # Define vertices of triangle vertices = ((-0.5, -0.5), (0.5, -0.5), (0.0, 0.5)) def draw_triangle(): # Clear the color buffer glClear(GL_COLOR_BUFFER_BIT) # Begin drawing using triangles glBegin(GL_TRIANGLES) # Set color to red glColor3f(1.0, 0.0, 0.0) # Draw triangle glVertex2f(*vertices[0]) glVertex2f(*vertices[1]) glVertex2f(*vertices[2]) # End drawing glEnd() # Call the draw_triangle function to render the triangle draw_triangle()
from OpenGL.GL import * # Define vertices of square vertices = ((-0.5, -0.5), (-0.5, 0.5), (0.5, 0.5), (0.5, -0.5)) def draw_square(): # Clear the color buffer glClear(GL_COLOR_BUFFER_BIT) # Begin drawing using quads glBegin(GL_QUADS) # Set color to green glColor3f(0.0, 1.0, 0.0) # Draw square glVertex2f(*vertices[0]) glVertex2f(*vertices[1]) glVertex2f(*vertices[2]) glVertex2f(*vertices[3]) # End drawing glEnd() # Call the draw_square function to render the square draw_square()This example also uses the PyOpenGL library.