gpt4 book ai didi

python - 尝试使用 pygame OpenGL 绘制平面 3D 网格时不断出现错误 1282 'invalid operation'

转载 作者:行者123 更新时间:2023-11-30 22:17:26 29 4
gpt4 key购买 nike

我正在尝试创建一个地形,但我似乎无法让这个网格工作?不断返回此错误:

OpenGL.error.GLError: GLError( err = 1282, description = b'invalid operation', baseOperation = glEnd, cArguments = ()

import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
import random

nptx=10
npty=10

def terrain2():
glBegin(GL_QUADS)
for ye in range(0,npty):
for xe in range(0,nptx):
glVertex3f(xe,ye+1,0)
glVertex3f(xe+1,ye+1,0)
glVertex3f(xe+1,ye,0)
glVertex3f(xe,ye,0)
glEnd()

def main():
pygame.init()
display=(800,600)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL)

gluPerspective(45, (display[0]/display[1]),0.1,200)
glTranslatef(0.0,0.0,-5)

while True:
for event in pygame.event.get():
if pygame.event==pygame.quit():
pygame.quit()
quit()
terrain2()
pygame.display.flip()
main()

最佳答案

当计算以下表达式时

if pygame.event==pygame.quit():

然后操作pygame.quit()被执行并且所有pygame模块都未初始化。

更改为

if event.type == pygame.QUIT:

event.type 与枚举 pygame.QUIT 进行比较。

关于python - 尝试使用 pygame OpenGL 绘制平面 3D 网格时不断出现错误 1282 'invalid operation',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49678008/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com