Уведомления

Группа в Telegram: @pythonsu

#1 Март 5, 2011 17:06:28

norn
От:
Зарегистрирован: 2011-03-05
Сообщения: 2
Репутация: +  0  -
Профиль   Отправить e-mail  

Python + OpenGL в Ubuntu

Здравствуйте!

Заинтересовался темой программирования 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



Отредактировано (Март 5, 2011 17:07:50)

Офлайн

#2 Март 5, 2011 20:21:15

norn
От:
Зарегистрирован: 2011-03-05
Сообщения: 2
Репутация: +  0  -
Профиль   Отправить e-mail  

Python + OpenGL в Ubuntu

Все указал, кроме имени файла проекта. Я его назвал OpenGL.py… В общем, без комментариев… :D

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

Всем спасибо.



Отредактировано (Март 5, 2011 20:22:43)

Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version