Even if your operating system is a 64 bit OS, you may still find you're running a 32 bit version of Python. So, if you are using 32 bit Python, you need to use 32 bit modules, and so on. Most of the time, the error is either you've downloaded the wrong Python version of PyGame or OpenGL, or the wrong bit version. If you are getting errors, something went wrong. If you can type those statements and run them without any errors, then you are ready to proceed. Once you have everything, go ahead and open up IDLE and type in: import pygame If you are a Windows user, then I highly recommend downloading PyGame and PyOpenGL from this source of Windows binaries for Python Modules. So that's the abstract concept of how OpenGL works, let's go ahead and do it!įirst, you will need to have the following: Python PyOpenGL PyGame This basically notifies OpenGL how you want it to handle your statements. These are constants, and contain things like GL_QUADS or GL_LINES.
In the glBegin statement, you specify the "type" of code that you are about to pass. To do this, you have glBegin and glEnd statements that you call, and between these is where the OpenGL-specific code goes. Once you do that, then you're ready to write the OpenGL code. You can then pre-define some rules like what vertices make up a "surface" and between what vertices are the "edges," or lines that we want to have drawn between the vertices. Defining the vertices is done with a simple list or tuple in Python. In this example, we want to draw lines between them. Once you define the vertices, you can then do things with them. You may also see them referred to as a node (singular) or nodes (plural). For a cube, for example, you specify the "corners." Corners are referred to as vertices (plural) or as a vertex (singular).
So, the way OpenGL works is you just specify the objects within space. OpenGL is a cross-language API, so you can take your knowledge of OpenGL to other languages. Hopefully I can help you all learn it much faster than I did.įirst off, PyOpenGL is just some Python bindings (some Python code that acts like a sort of wrapper around native code), so you can manipulate OpenGL within the context of Python. I did not, so this was a massive hurdle for me. I had a very hard time figuring out OpenGL, mainly because most of the OpenGL with PyOpenGL tutorials that I could find were clearly written for someone who already knew OpenGL. This first tutorial is quite long, but I wanted to go ahead and put everything into this video. As such, I have compiled this first video to include everything from acquiring Python, PyOpenGL, and PyGame, to creating the necessary code to make a rotating cube.
I don't think I am alone, since this seems to be the pinnacle of understanding the basics of OpenGL.
When I first began looking into OpenGL with Python, my main goal was to figure out how to make a rotating cube.