A maior rede de estudos do Brasil

433 pág.
Apostila PyOpenGL

Pré-visualização | Página 4 de 50

the effort you put into trying 
to understand and utilize the concepts. 
4 For Mac enthusiasts, as long as you have Python, PyOpenGL, and a programming editor you 
should also be able to run the example programs. 
5 In other words, as much as possible do your own work! If you get help from someone or 
somewhere, and we all do, acknowledge the help. Claiming original work in programs or problem 
solutions that are actually not your own is dishonest at best 
6 You should look up the history of how programming errors came to be called “bugs”. 
7 A company specializing in interactive sports games. 
Section 2.5 Justifications 
Back in the early days of our computer science curriculum, graphics 
programming was synonymous with gaming and we didn't buy those computers so that 
students could play games.8 Gradually as time passed and the personal computer world 
became more graphically oriented thanks to the Mac and Windows operating systems, 
computer graphics became more mainstream. We began to realize that being able to 
produce computer graphics meant that not only did you have to understand something 
about programming, you also had to understand something about mathematics and 
science if your computer graphics were to look and behave realistically. I am stubborn, 
though, and it indeed took me two decades to realize that I could teach computer 
programming utilizing computer graphics. My students seem to enjoy the experience 
and so do I. I don't know and don't care whether or not this is acceptable practice in 
other schools… it works for us. 
 The choice of Python from dozens of other languages is a personal preference. 
Python is a relatively simple language, but it is easily expanded through external 
modules such as the PyOpenGL module. Python is object-oriented9 and is a very 
popular language. Plus, Python is freely available! The downside is that program 
execution is somewhat slow10, but I believe the advantages outweigh the loss of speed. 
Finally, once you learn Python, it is relatively easy to go on to other languages if you 
desire (and you may not... Python is a very powerful language!). See section 2.6 below 
for instructions on how to obtain a copy of Python for your computer. 
The choice of which graphics environment to implement was a bit easier. There 
are two major graphic API’s11 available today, DirectX and OpenGL. DirectX is a 
windows specific graphics API and OpenGL12 is available on all platforms. Both are free 
for programmers to download and use. I personally like OpenGL13 and think it’s a bit 
better at creating and displaying graphics than DirectX, but I could be wrong. 
 DrPython is my current Python programming editor. It is freely available and 
allows interactive access to the Python console. The only minor drawback is that 
DrPython needs the wxWindows library to function properly, but that is also a free 
download. DrPython is actually written in Python! However, Scite, or any other 
programming IDE that supports Python (and most of them do) will suffice. If you use 
another editor, the only difference you will see is that the images in the initial chapters 
8 I remember that one school board member didn't think that we were ready for computers in 
1980. I translated that to mean that HE wasn't ready for them. When we purchased the 
computers, we were expected to compute… whatever that meant, and not "play". 
9 Object-oriented programming is a mainstay of modern computer languages. 
10 Python is an interpreted language (for the most part) rather than optimized and compiled like C. 
This isn't all bad, because it allows us to use Python interactively from a command prompt. Look 
up interpreted languages for further information. 
11 Computer jargon for a set of commands specific to a particular task, such as graphics. 
12 Originally created by Jim Clark and available on Silicon Graphics (SGI) workstations as GL 
(graphics language). It used to be a commercial package, but was eventually made available as 
Open Source software, hence OpenGL. 
13 Prof. Francis was strong influence on my preference. He uses OpenGL/GLUT in his illiMath 
display the DrPython editor rather than the one you chose. All Python compatible 
editors will have syntax highlighting. What this means is that all valid Python commands 
will appear in color, as opposed to simple black on white text. This will allow you to 
check to see if you’ve spelled the command correctly! The program listings in this text 
are in black type, so don’t be surprised to see blue, green, or red text (depending on the 
editor) in your editor window. As in the art and science of programming, the choice of a 
programming IDE or editor is yours. 
 There may be other modules or programs that we will use as the course 
progresses. I will introduce these when the need arises. 
Section 2.6 Python Installation 
 If you are working in the Microsoft Windows environment, I would recommend 
that you visit http://www.python.org in order to download the latest stable version of 
Python.14 You will also need to visit http://pyopengl.sourceforge.net/ to download the 
PyOpenGL module. In addition, if you wish to install DrPython (recommended), you 
should go to http://drpython.sourceforge.net/ to download this program editor. There is 
link on this website to download wxWindows if needed. 
As another option for Windows environment, I would recommend that you take a 
close look at the Enthought Python distribution (http://www.enthought.com). Enthought 
provides a complete Python package with an enormous number of libraries available, 
including the Scite programming editor at no charge for individuals and academic users. 
The only drawback to the Enthought distribution is that the installation file over 200 
megabytes in size, so you would need a fast internet connection to download the entire 
If you are working on a linux platform, check the online package repositories for 
Python, DrPython and/or Scite, and the PyOpenGL library. Ubuntu linux and its apt 
repositories allow for easy installation of everything you need. I would also recommend 
the Python Psyco compiler for Windows and/or Linux. If you are unsure about how to 
proceed, do some research online. There are many pages devoted to installing and 
using Python and its multitude of libraries. 
 The examples I use in this text are based on a Windows environment, but I also 
have a linux system (Ubuntu Linux) on the same computer in order to make certain the 
programs run properly in both environments. My current students work entirely in 
Ubuntu Linux, so I make certain that the programming examples are compatible with 
both operating systems. Linux has a few minor quirks (features?) in certain programs, 
but there are no major problems. 
 That’s enough for the preliminary information. Let’s get ready to program! 
14 I used Python 2.5 and PyOpenGL 3.0.0a under Windows for these program examples. I know 
that earlier versions of both packages also work properly under both Windows and Linux. 
1. Go to the www.python.org website and spend some time looking at the resources 
that are available there. You'll find various tutorials and answers to your Python 
questions. You should bookmark this site in your browser! 
2. Go the www.opengl.org website and see what OpenGL is all about. 
3. Visit Professor Francis' home page www.new.math.uiuc.edu/~gfrancis and 
http://new.math.uiuc.edu/ to see how he uses OpenGL in his mathematics 
classes at U of I. 
4. Visit http://pyopengl.sourceforge.net for the PyOpenGL home page. You'll find 
documentation and the

Crie agora seu perfil grátis para visualizar sem restrições.