Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ty625911724 opened this issue Sep 9, 2021 · 1 comment
Open

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

ty625911724 opened this issue Sep 9, 2021 · 1 comment

Comments

@ty625911724
Copy link

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!

@JTFrye
Copy link

JTFrye commented Dec 18, 2021

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants