0
내가 어떤 마우스 기능을 glutMouseFunc를 사용할 필요가 파이썬이 PyOpenGL 사용에 프로그램을 작성하려고 만하고있어 나는 다음과 같은 오류 얻을 프로그램을 실행하면파이썬에서 glutMouseFunc를 사용하여 유효한 컨텍스트 없을 때
Traceback (most recent call last):
File "teapot.py", line 80, in <module>
glutMouseFunc(mouseHandle)
File "/usr/lib/python2.7/dist-packages/OpenGL/GLUT/special.py", line 137, in __call__
contextdata.setValue(self.CONTEXT_DATA_KEY, cCallback)
File "/usr/lib/python2.7/dist-packages/OpenGL/contextdata.py", line 57, in setValue
context = getContext(context)
File "/usr/lib/python2.7/dist-packages/OpenGL/contextdata.py", line 40, in getContext
"""Attempt to retrieve context when no valid context"""
OpenGL.error.Error: Attempt to retrieve context when no valid context
을
나는 그것을 인터넷 검색을 시도했지만 나는 어떤 관련 result.Here 내 코드입니다 찾을 수 없습니다 :
from OpenGL.GL import *
from OpenGL.GLUT import *
t = 0
def init():
r=1
g=0
b=0
glColor3f(r,g,b)
glClearColor(1.0,1.0,1.0,0.0)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
def display():
glClear(GL_COLOR_BUFFER_BIT)
glViewport(0,0,150,100)
drawSquare()
glViewport(0,100,150,200)
drawCircle()
glViewport(0,200,150,300)
drawTriangle()
glViewport(0,300,150,400)
drawFan()
if(t==1):
glViewport(150,0,800,600)
drawFan()
if(t==2):
glViewport(150,0,800,600)
drawTriangle()
if(t==3):
glViewport(150,0,800,600)
drawCircle()
if(t==4):
glViewport(150,0,800,600)
drawSquare()
glFlush()
def drawFan():
glBegin(GL_TRIANGLE_FAN)
glVertex2f(0.0,0.0)
glVertex2f(0.3,0.3)
glVertex2f(0.3,-0.3)
glVertex2f(-0.3,0.3)
glVertex2f(-0.3,-0.3)
glEnd()
def drawTriangle():
glBegin(GL_TRIANGLES)
glVertex2f(0.5,0.0)
glVertex2f(0.0,0.5)
glVertex2f(-0.5,0.0)
glEnd()
def drawCircle():
glutSolidSphere(0.5, 30 ,30)
def drawSquare():
glBegin(GL_POLYGON)
glVertex2f(0.5,0.5)
glVertex2f(-0.5,0.5)
glVertex2f(-0.5,-0.5)
glVertex2f(0.5,-0.5)
glEnd()
def mouseHandle(button, state, x, y):
if(button == GLUT_LEFT_BUTTON and x < 150 and y < 170):
t=1
glutPostRedisplay()
print "1: x=",x," y=",y,"\n"
elif(button == GLUT_LEFT_BUTTON and x < 150 and 170 < y and y < 280):
t=2
glutPostRedisplay()
elif(button == GLUT_LEFT_BUTTON and x < 150 and 345 < y and y < 451):
t=3
glutPostRedisplay()
elif(button == GLUT_LEFT_BUTTON and x < 150 and 525 < y and y < 578):
t=4
glutPostRedisplay()
else:
glutPostRedisplay()
glutInit('')
glutMouseFunc(mouseHandle)
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
glutInitWindowSize(800,600)
glutCreateWindow('Hello GLUT')
glutDisplayFunc(display)
init()
glutMainLoop()
모든 신체가 무엇을 알고 : 난 그냥 아래처럼
glutDisplayFunc
후glutMouseFunc
전화를 이동해야했습니다? –