Let's now try to make a square using OpenGL, but before we do we need to understand the coordinate system that OpenGL follows. Now, if we wish to draw any shapes or make any other kind of graphics, we need to do that in our "showScreen" function. You should see a white square dimension screen pop up.
GlutMainLoop() # Keeps the window created above displaying/running in a loopĬopy the imports above, as well as this code in a single python (.py) file, and execute it. GlutIdleFunc(showScreen) # Draw any graphics or shapes in the showScreen function at all times GlutDisplayFunc(showScreen) # Tell OpenGL to call the showScreen method continuously Wind = glutCreateWindow( "OpenGL Coding Practice") # Give your window a title GlutInitWindowPosition( 0, 0) # Set the position at which this windows should appear GlutInitWindowSize( 500, 500) # Set the width and height of your window GlutInitDisplayMode(GLUT_RGBA) # Set the display mode to be colored GlutInit() # Initialize a glut instance which will allow us to customize our window GlClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Remove everything from screen (i.e. The code for that is given below, along with its explanation in the comments: Now that we are done with the necessary imports, let's first create a window in which our graphics will be shown. Print( "Imports successful!") # If you see this printed to the console then installation was successful Below is the code for those imports: import OpenGL.GL To do that, run the following command: import OpenGLīefore we proceed, there are a few other libraries that you need to import whenever you intend to use this library in your program. The first thing we need to do to use OpenGL in our code is to import it. Now that we have successfully installed OpenGL on our system, let's get our hands dirty with it. It is pertinent to mention that you require Visual C++ 14.0 build tools installed on your system in order to work with OpenGL libraries in Python. After that, navigate to the folder where you downloaded those files, and run the following command in the terminal or command prompt: $ python setup.py
For that, this link, scroll down to the 'downloading and installation' heading, and download all the files over there. If this doesn't work, you can also download it manually. Once this command finishes execution, if the installation is successful, you should get the following output at the end: Successfully installed PyOpenGL-3.1.0 PyOpenGL-accelerate-3.1.0