2014-02-14 40 views
0

我正在使用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 =() 
) 

我要去哪裏錯了?

回答

2

我認爲問題在於你需要撥打glBegin()而不是GL_LINE來撥打GL_LINES。它們是用於2種不同事物的2個不同的值。

+0

你能告訴我最新的區別?至於它們用於什麼?無效的入口是因爲在glBegin()中指定了錯誤的關鍵字? –

+0

如果你看看OpenGL的頭文件,你會發現你可以傳遞給各種gl函數的所有枚舉值。 GL_LINES被定義爲1,'GL_LINE'被定義爲0x1B01。 'GL_LINES'用於立即模式繪製一系列直線,而'GL_LINE'用於設置多邊形模式(可以是點,線或填充)。有關這方面的更多信息,請參見['glPolygonMode()'](http://www.opengl.org/sdk/docs/man4/html/glPolygonMode.xhtml)。 – user1118321