嗨,我在运行这个代码时遇到了一个非常奇怪的问题。我也不认为它应该与openglapi冲突。代码如下:
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()
尝试运行程序时出现以下错误:
^{pr2}$我在惠普电脑上运行Windows7。在
块模型模块如下所示:
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
谢谢你的回答!:)
你可能已经解决了这个问题,但我猜你的边上可能有奇数个顶点。glEnd()上的1282错误只意味着整个操作有问题。GL_线要求给定偶数个顶点,因为GL_线是成对点来定义每个线段的,而不是一个连续的点串来形成一条大的多段线。再次检查每个边是否有两个点。在
看起来你没有正确地结束GL_QUADS进程。你在叫格伦德,而不是格伦()。我不知道这是否是问题所在,但这绝对是错误的。如果有多个going,可能需要指定要结束的进程,例如当前准备了多个going时的glEnd(GL_LINES)或glEnd(GL_QUADS),这就是成功的glEnd()调用发生错误的原因;您没有告诉它应该结束哪个进程。在
希望这有帮助
您应该从
glEnd()
第37行中删除()
,代码应该可以正常工作。在相关问题 更多 >
编程相关推荐