#!/usr/bin/python3 # =================================================================== # pip3 install PyOpenGL PyOpenGL_acclerate # sudo apt-get install python-opengl # # Example From: stackabuse.com/ # brief-introduction-to-opengl-in-python-with-pyopengl/ # =================================================================== from OpenGL.GL import * from OpenGL.GLUT import * from OpenGL.GLU import * import sys # ------------------------------------------------------------------- # we have to declare the points in this instance: # bottom left, bottom right, top right, top left def square(): glBegin(GL_QUADS) glVertex2f(100,100) # bottom left glVertex2f(200,100) # bottom right glVertex2f(200,200) # top right glVertex2f(100,200) # top left glEnd() # ------------------------------------------------------------------- def iterate(): glViewport(0,0,500,500) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0.0,500,0.0,500,0.0,1.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() #-------------------------------------------------------------------- def showScreen(): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() iterate() glColor3f(1.0,0.0,3.0) square() glutSwapBuffers() glutInit() glutInitDisplayMode(GLUT_RGBA) glutInitWindowSize(500,500) glutInitWindowPosition(0,0) wind = glutCreateWindow("OpenGL Coding Practice") glutDisplayFunc(showScreen) glutIdleFunc(showScreen) glutMainLoop()