pyopengl icon indicating copy to clipboard operation
pyopengl copied to clipboard

glReadPixels (OpenGL.error.GLError: b'invalid enumerant')

Open ty625911724 opened this issue 3 years ago • 1 comments

When I using glReadPixels to get the rendering results, it returns an error.

Traceback (most recent call last):
  File "test_opengl.py", line 29, in <module>
    buffer = glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE)
  File "/home/model/pyopengl/OpenGL/GL/images.py", line 372, in glReadPixels
    imageData
  File "/home/model/pyopengl/OpenGL/platform/baseplatform.py", line 415, in __call__
    return self( *args, **named )
  File "/home/model/pyopengl/OpenGL/error.py", line 234, in glCheckError
    baseOperation = baseOperation,
OpenGL.error.GLError: GLError(
        err = 1280,
        description = b'invalid enumerant',
        baseOperation = glReadPixels,
        cArguments = (
                0,
                0,
                300,
                300,
                GL_RGB,
                GL_UNSIGNED_BYTE,
                array([[[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [...,
        )
)

How should I fix this error?

My environment: Ubuntu18.04 PyOpenGL 3.1.5 Python 3.6.9 I use ssh with X11 to get remote results.

The code is also very simple. It could render correct results, but return error with glReadPixels.

from OpenGL.GLUT import *
from OpenGL.GL import *
from OpenGL.GLU import *

from PIL import Image
from PIL import ImageOps

import sys
import numpy as np

width, height = 300, 300

glutInit(sys.argv)

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
glutInitWindowSize(width, height)
glutCreateWindow(b"OpenGL Offscreen")
#glutHideWindow()

glClearColor(0.0, 0.0, 0.0, 0.0)
glMatrixMode(GL_PROJECTION)
glOrtho(-5,5,-5,5,5,15)
glMatrixMode(GL_MODELVIEW)
gluLookAt(0,0,10,0,0,0,0,1,0)
glClear(GL_COLOR_BUFFER_BIT)
glutWireTeapot(3)
glFlush()

#glutMainLoop()

buffer = glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE)

Thanks!

ty625911724 avatar Sep 09 '21 01:09 ty625911724

Almost posted a COMPLETELY wrong solution. I think I have found the issue. The error is 'invalid enumerate'.

buffer = glReadPixels(0,0,width,height, GL_RGB, GL_UNSIGNED_BYTE)

formatdata type****<----Important stuff!

the 'invalid enumerate' error description means either the format and the data type are not compatible. Your format is GL_RGB. Your data type is GL_UNSIGNED_BYTE So one of these two must be changed.

If you want a quick and easy fix, change GL_UNSIGNED_BYTE to GL_FLOAT. This should kill the 1280 error.

Hope this helps, good luck!

JTFrye avatar Dec 18 '21 04:12 JTFrye