Найти - Пользователи
Полная версия: Python + OpenGL в Ubuntu
Начало » Python для новичков » Python + OpenGL в Ubuntu
1
norn
Здравствуйте!

Заинтересовался темой программирования OpenGL на Python. Версия интерпретатора 2.6, система Ubuntu 10.04 LTS. Нашел пример программы:
# -*- coding: utf-8 -*-

from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import sys

rot = 0

def InitGL(Width, Height):
glClearColor(0.0, 0.0, 0.0, 0.0)
glClearDepth(1.0)
glDepthFunc(GL_LESS)
glEnable(GL_DEPTH_TEST)
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glEnable(GL_COLOR_MATERIAL)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45.0, float(Width)/float(Height), 0.1, 1000.0)
glMatrixMode(GL_MODELVIEW)

def ReSizeGLScene(Width, Height):
if Height == 0: Height = 1
glViewport(0, 0, Width, Height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45.0, float(Width)/float(Height), 0.1, 100.0)
glMatrixMode(GL_MODELVIEW)

def DrawGLScene():
global rot
rot = (rot + 1) % 360 # увеличиваем угол поворота
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # очищаем экран
glLoadIdentity() # восстанавливаем мировые координаты
glTranslatef(0.0,0.0,-10.0)
glRotatef(rot,1.0,0.0,0.0)
glRotatef(rot,0.0,1.0,0.0)
glRotatef(rot,0.0,0.0,1.0)
glColor4f(0.0,0.7,0.1,1)
glutSolidCube(3)
glutSwapBuffers()

def KeyPressed(*args):
if args[0]=="\033": sys.exit()

def main():
glutInit(sys.argv)
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH)
glutInitWindowSize(400, 300)
glutInitWindowPosition(0, 0)
glutCreateWindow("OpenGL demo")
glutDisplayFunc(DrawGLScene)
glutIdleFunc(DrawGLScene)
glutReshapeFunc(ReSizeGLScene)
glutKeyboardFunc(KeyPressed)
InitGL(400, 300)
glutMainLoop()

main()
Как будто бы все верно, однако интерпретатор говорит:
Traceback (most recent call last):
File "/home/norn/Projects/Python/OpenGL.py", line 3, in <module>
from OpenGL.GL import *
File "/home/norn/Projects/Python/OpenGL.py", line 3, in <module>
from OpenGL.GL import *
ImportError: No module named GL
ВОПРОС: Как заставить работать OpenGL-программу.

P.S. Вот это уже пройдено:
sudo aptitude install gcc freeglut3 libgle3 python-dev python-setuptools python-virtualenv
sudo aptitude install python-pygame python-numpy python-imaging
easy_install PyOpenGL PyOpenGL-accelerate
norn
Все указал, кроме имени файла проекта. Я его назвал OpenGL.py… В общем, без комментариев… :D

P.S. НЕ НАЗЫВАЙТЕ ФАЙЛЫ ПРОЕКТА ИМЕНАМИ СТАНДАРТНЫХ БИБЛИОТЕК

Всем спасибо.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB