python - 无效枚举

标签 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 = ()
)

我哪里出错了?

最佳答案

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

关于python - 无效枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21772238/

相关文章:

ios - 相邻的 CAShapeLayer 抗锯齿问题

python - 如何使用 dateutil.tz.tz.tzoffset 来本地化使用 strptime 创建的时区原始日期时间?

Python 2.7 - 使用 +01 :00 转换日期时间

python - GraphLab-Create 模块未安装在 Python 3.5 (ubuntu) 上

python - Pyglet OpenGL绘图抗锯齿

python - 将纹理传递给 GLSL

opengl - glReadPixels 不将数据写入数组

java - 找到第一个红色像素并裁剪图片

java - GUI 使用 JFrame 和 JPanel 绘制自定义形状

python - 初学者Python程序