You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PyOpenGL调用glEnd触发OpenGL错误1282的原因排查

OpenGL错误1282(glEnd()调用失败)排查

问题背景

我遵循Stack Abuse的PyOpenGL教程开发时,调用glEnd()触发了OpenGL错误1282(错误描述为“无效操作”)。我的环境是Windows10+Python3.12.3虚拟环境,手动安装了freeglut.dll,因安装报错未安装PyOpenGL_accelerate。

相关代码

import OpenGL
import OpenGL.GL
from OpenGL.GLUT import *
import OpenGL.GLU
from OpenGL.raw.GL.VERSION.GL_1_1 import *
import time

def square():
    glBegin(GL_QUADS)
    glVertex2f(100,100)
    glVertex2f(200,100)
    glVertex2f(200, 200)
    glVertex2f(100, 200)
    glEnd()


def iterate():
    glViewport(0, 0, 500,500)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    glOrtho(0.0, 500, 0.0, 500, 0.0, 1.0)
    glMatrixMode (GL_MODELVIEW)
    glLoadIdentity()

def showScreen():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glLoadIdentity()
    iterate()
    glColor3f(1.0, 0.0, 3.0)
    square()
    glutSwapBuffers()
    time.sleep(0.017)

glutInit()
glutInitDisplayMode(GLUT_RGBA)
glutInitWindowSize(500,500)
glutInitWindowPosition(0, 0)
wind = glutCreateWindow(b'OpenGL Coding Practice')
glutDisplayFunc(showScreen)
glutIdleFunc(showScreen)
glutMainLoop()

依赖配置(requirements.txt)

numpy==2.1.2
PyOpenGl==3.1.7

终端报错信息

Traceback (most recent call last):
  File "C:\Users\foo\OPENGLProject\.venv\Lib\site-packages\OpenGL\GLUT\special.py", line 130, in safeCall
    return function( *args, **named )
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\foo\OPENGLProject\src\main.py", line 37, in showScreen
    square()
  File "C:\Users\foo\OPENGLProject\src\main.py", line 14, in square
    glEnd()
  File "C:\Users\foo\OPENGLProject\.venv\Lib\site-packages\OpenGL\platform\baseplatform.py", line 415, in __call__
    return self( *args, **named )
           ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\foo\OPENGLProject\.venv\Lib\site-packages\OpenGL\error.py", line 230, in glCheckError
    raise self._errorClass(
OpenGL.error.GLError: GLError(
    err = 1282,
    description = b'operaci\xf3n no v\xe1lida',
    baseOperation = glEnd,
    cArguments = ()
)
GLUT Display callback <function showScreen at 0x000002BB62CCFEC0> with (),{} failed: returning None GLError(
    err = 1282,
    description = b'operaci\xf3n no v\xe1lida',
    baseOperation = glEnd,
    cArguments = ()
)

已尝试的解决方法

  • 修改glBegin的参数为GL_LINES、GL_TRIANGLES
  • 更换顶点函数为glVertex3f、glVertex3d

以上操作均未解决问题,请问该错误的原因是什么?


内容的提问来源于stack exchange,提问作者Pablo Rufián Jiménez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 04:58:14