无效的枚举

时间:2014-02-14 06:24:29

标签: python opengl graphics

我正在使用OpenGL绘制一条线。代码是:

from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import sys
def init():
    glClearColor(1.0, 1.0, 1.0, 1.0)
    gluOrtho2D(-100.0, 100.0, -100.0, 100.0)

def plotpoints():
    glClear(GL_COLOR_BUFFER_BIT)
    glColor3f(0.0, 0.5, 0.0)
    glPointSize(4.0)
    glBegin(GL_LINE)
    glVertex2f(50.0,0.0)
    glVertex2f(10.0,0.0)
    glEnd()
    glFlush()

def main():
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB)
    glutInitWindowSize(500,500)
    glutInitWindowPosition(100,100)
    glutCreateWindow("Again")
    glutDisplayFunc(plotpoints)
    init()
    glutMainLoop()

main()

问题是,在执行时我收到错误:

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\OpenGL\GLUT\special.py", line 121, in safeCall
    return function( *args, **named )
  File "C:\Users\Administrator\Desktop\eclipse\Python Projects\Serverclient\Try.py", line 16, in plotpoints
    glEnd()
  File "C:\Python27\lib\site-packages\OpenGL\latebind.py", line 61, in __call__
    return self.wrapperFunction( self.baseFunction, *args, **named )
  File "C:\Python27\lib\site-packages\OpenGL\GL\exceptional.py", line 57, in glEnd
    return baseFunction( )
  File "C:\Python27\lib\site-packages\OpenGL\error.py", line 208, in glCheckError
    baseOperation = baseOperation,
GLError: GLError(
    err = 1280,
    description = 'invalid enumerant',
    baseOperation = glEnd,
    cArguments = ()
)
GLUT Display callback <function plotpoints at 0x02D6FAB0> with (),{} failed: returning None GLError(
    err = 1280,
    description = 'invalid enumerant',
    baseOperation = glEnd,
    cArguments = ()
)

我哪里错了?

1 个答案:

答案 0 :(得分:2)

我认为问题是您在调用GL_LINES而不是glBegin()时需要GL_LINE。它们是2个不同的值,用于2种不同的东西。