2015-07-03 151 views
0

嗨我運行此代碼時,得到一個非常奇怪的問題。我看不出它應該如何與OpenGL API衝突。繼承人的代碼:PyOpenGL錯誤glEnd錯誤= 1282

import sys 
sys.path.append("..\Blocks") 
print sys.path 
import pygame 
from pygame.locals import * 
from OpenGL.GL import * 
from OpenGL.GLU import * 

import random 

try: 
    import BlockModel 
except: 
    print "Cant Find Block Model" 

def createBlock(): 
    block = BlockModel.Block() 

    blockVertices = block.returnVertices() 

    blockEdges = block.returnEdges() 

    blockSurface = block.returnSurface() 

    glBegin(GL_QUADS) 

    for surface in blockSurface: 
     for faceVertex in surface: 
      glVertex3fv(blockVertices[faceVertex]) 

    glEnd 

    glBegin(GL_LINES) 
    for edge in blockEdges: 
     for vertex in edge: 
      glVertex3fv(blockVertices[vertex]) 
    glEnd() 

def main(): 
    pygame.init() 
    display = (800, 600) 
    pygame.display.set_mode(display, DOUBLEBUF|OPENGL) 
    gluPerspective(15, (display[0]/display[1]), 0.1, 50.0) 

    glTranslatef(random.randrange(-5,5),random.randrange(-5,5), -40) 

    exit = False 

    while not exit: 
     pygame.time.wait(10) 
     glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) 
     createBlock() 
     pygame.display.flip() 
     for event in pygame.event.get(): 
      if event.type == pygame.QUIT: 
       pygame.quit() 
       quit() 


main() 

我在嘗試運行該程序時,這個錯誤:

C:\Users\Haavard\Desktop\MinecraftPythonProject\framework>python main.py 
['C:\\Users\\Haavard\\Desktop\\MinecraftPythonProject\\framework', 'C:\\Windows\ 
\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python 
27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\ 
lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\PIL', '..\\Blocks'] 
Traceback (most recent call last): 
    File "main.py", line 60, in <module> 
    main() 
    File "main.py", line 52, in main 
    createBlock() 
    File "main.py", line 37, in createBlock 
    glEnd() 
    File "latebind.pyx", line 44, in OpenGL_accelerate.latebind.Curry.__call__ (c: 
\Users\mcfletch\OpenGL-dev\OpenGL-ctypes\OpenGL_accelerate\src\latebind.c:1201) 
    File "C:\Python27\lib\site-packages\OpenGL\GL\exceptional.py", line 46, in glE 
nd 
    return baseFunction() 
    File "C:\Python27\lib\site-packages\OpenGL\platform\baseplatform.py", line 402 
, in __call__ 
    return self(*args, **named) 
    File "errorchecker.pyx", line 53, in OpenGL_accelerate.errorchecker._ErrorChec 
ker.glCheckError (c:\Users\mcfletch\OpenGL-dev\OpenGL-ctypes\OpenGL_accelerate\s 
rc\errorchecker.c:1218) 
OpenGL.error.GLError: GLError(
     err = 1282, 
     description = 'invalid operation', 
     baseOperation = glEnd, 
     cArguments =() 
) 

IM在一個HP的機器上運行Windows 7。

塊模型模塊看起來是這樣的:

class Block: 

    # initializing the basic functions of a block 
    def __init__(self, blockID = "0", blockType = "stone", verticesCords = ((1,-1,-1),(1,1,-1),(-1,1,-1),(-1,-1,-1),(1,-1,1),(1,1,1),(-1,-1,1),(-1,1,1)), edges = ((0,1),(0,3),(0,4),(2,1),(2,3),(2,7),(6,3),(6,4),(6,7),(5,1),(5,4),(5,7)), surfaces = (((0,1,2,3),(3,2,7,6),(6,7,5,4),(4,5,1,0),(1,5,7,2),(4,0,3,6)))): 
     # Block Placement 
     self.PLACEMENT = verticesCords 
     # Block identity in the world 
     self.EDGES = edges 
     self.SURFACE = surfaces 
     self.BLOCKID = blockID 
     # The block type 
     self.BLOCKTYPE = blockType 

    # A function letting the framework know its placement. 
    def returnVertices(self): 
     return self.PLACEMENT 

    def returnEdges(self): 
     return self.EDGES 

    def returnSurface(self): 
     return self.SURFACE 

    # A function to make the block fetch its own texture. 
    def defineTexture(): 
     pass 

謝謝你的任何answears! :)

回答

0

您可能已經解決了這個問題,但我的猜測是您的邊上可能有奇數個頂點。 glEnd()上的1282錯誤意味着整個操作有問題。 GL_LINES需要給定偶數個頂點,因爲GL_LINES在成對的點中定義每個線段,而不是連續的一串點來構成一條大折線。仔細檢查每條邊有兩個點。