thusharajayan
Posts: 17
Joined: Tue May 05, 2015 5:21 am

Opengl es2.0 glreadpixels filling all zeros

Tue May 05, 2015 5:29 am

Hi,
I am new to opengl ES programming. I a musing ES2.0 version.
I am facing some issue while trying to read back the display content from frame buffer using glreadpixels api. I am using textures to render a rgb image on screen. I am able to display it properly but when i use glreadpixels to tap the rgb values , the buffer populated is having all zeros. I am calling glReadPixels just after my call to glDrawElements.
I have tried googling it but couldn't find any solutions. Please help me in zeroing down the issue.

Regards,
Thushara

User avatar
paddyg
Posts: 2616
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Opengl es2.0 glreadpixels filling all zeros

Tue May 05, 2015 10:19 am

You may get some more specific help if you post the code that doesn't work. This is the way we do it (in python!)
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

thusharajayan
Posts: 17
Joined: Tue May 05, 2015 5:21 am

Re: Opengl es2.0 glreadpixels filling all zeros

Tue May 05, 2015 1:08 pm

Hi,
Ill post one simple code i tried which draws a triangle. I am trying to read color buffer using glreadpixels. But the values are all zeros.

My render function is like this

Code: Select all

glViewport(0, 0, width,height);
 glClearColor(0.5, 0.5, 0.5, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays ( GL_TRIANGLES, 0, 3 );
eglSwapBuffers(gl.display, gl.surface);
glReadPixels(0, 0, width,height, GL_RGB, GL_UNSIGNED_BYTE, data);


My fragment shader is as follows

Code: Select all

 void main()                                  
 {                                            
   gl_FragColor = vec4 ( 1.0, 0.0, 0.0, 1.0 );
 } 
My vertex shader is as follows

Code: Select all

void main()                 
{                            
      gl_Position = vPosition;  
 } 

with glVertexAttribPointer populated with following values
GLfloat vVertices[] = { 0.0f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f };




Regards
Thushara.

User avatar
PeterO
Posts: 6095
Joined: Sun Jul 22, 2012 4:14 pm

Re: Opengl es2.0 glreadpixels filling all zeros

Tue May 05, 2015 1:15 pm

Does the grReadPixels need to go before the eglSwapBuffers ?

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

thusharajayan
Posts: 17
Joined: Tue May 05, 2015 5:21 am

Re: Opengl es2.0 glreadpixels filling all zeros

Tue May 05, 2015 1:17 pm

Hi,
I tried both ways, but no luck
Regards
Thushara

User avatar
PeterO
Posts: 6095
Joined: Sun Jul 22, 2012 4:14 pm

Re: Opengl es2.0 glreadpixels filling all zeros

Tue May 05, 2015 1:52 pm

I'm clutching at straws because I don't have access to my working code at the moment, but have you tried GL_RGBA for the format. Some distant mempry is telling me that GL_RGB doesn't work.

PeterO

Ah my memory is correct !
viewtopic.php?f=68&t=101903
Last edited by PeterO on Tue May 05, 2015 1:59 pm, edited 1 time in total.
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

thusharajayan
Posts: 17
Joined: Tue May 05, 2015 5:21 am

Re: Opengl es2.0 glreadpixels filling all zeros

Tue May 05, 2015 1:56 pm

Hi,
When I try to use GL_RGBA with glreadpixels, I am getting following error message:
PVR:(Error): glReadPixels: Failed to get strided data

Regards
Thushara

User avatar
PeterO
Posts: 6095
Joined: Sun Jul 22, 2012 4:14 pm

Re: Opengl es2.0 glreadpixels filling all zeros

Tue May 05, 2015 2:02 pm

thusharajayan wrote:Hi,
When I try to use GL_RGBA with glreadpixels, I am getting following error message:
PVR:(Error): glReadPixels: Failed to get strided data

Regards
Thushara
openGL ES does not produce error messages, so what is PVR ?
What extra software are you running that you havn't told us about ?

Also, what is the colour format you are using ?

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

thusharajayan
Posts: 17
Joined: Tue May 05, 2015 5:21 am

Re: Opengl es2.0 glreadpixels filling all zeros

Tue May 05, 2015 2:11 pm

Hi,
I am using libdrm. This is used for creating my opengl display and surface.Following is a sample code which shows how I am using libdrm.

Code: Select all

drm.fd = drmOpen(omapdrm, NULL);
gbm.dev=gbm_create_device(drm.fd);
gl.display = eglGetDisplay(gbm.dev);

 gbm.surface = gbm_surface_create(gbm.dev,
            width, height,
            GBM_FORMAT_XRGB8888,
            GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);

gl.surface = eglCreateWindowSurface(gl.display, gl.config, gbm.surface, NULL);


Regards
Thushara.

User avatar
Paeryn
Posts: 3531
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Opengl es2.0 glreadpixels filling all zeros

Tue May 05, 2015 4:53 pm

libdrm... Are you trying to use Eric Ahnolt's drivers? Because the current way the RPi's EGL/OpenGLES works doesn't use DRM.

Your drmOpen() call references a variable omapdrm - that sounds like TI's SoC, and the PVR:(Error): looks like a PowerVR error message - neither of which the RPi has.

You should call glReadPixels() before you call eglSwapBuffers(). The colour buffer will only be preserved over a swapbuffer if the config used to create the surface has EGL_SWAP_BEHAVIOR_PRESERVED_BIT set in EGL_SURFACE_TYPE, and EGL_SWAP_BEHAVIOR is set to EGL_BUFFER_PRESERVED with eglSurfaceAttrib(). The default state is implementation dependent.
She who travels light — forgot something.
Please note that my name doesn't start with the @ character so can people please stop writing it as if it does!

thusharajayan
Posts: 17
Joined: Tue May 05, 2015 5:21 am

Re: Opengl es2.0 glreadpixels filling all zeros

Wed May 06, 2015 5:43 am

Hi,
Yes I am using Omapdrm (DRM kernel for Display subsystem in the target I use,TI jacinto 6)

I have tried to read first before swapping also, but the filled pixel values were all zeroes.

Regards
Thushara

User avatar
Paeryn
Posts: 3531
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Opengl es2.0 glreadpixels filling all zeros

Wed May 06, 2015 7:07 am

thusharajayan wrote:Hi,
Yes I am using Omapdrm (DRM kernel for Display subsystem in the target I use,TI jacinto 6)

I have tried to read first before swapping also, but the filled pixel values were all zeroes.

Regards
Thushara
These forums are for the Raspberry Pi, different product using a different SoC so chances are people aren't going to have the hardware you have.

All I can say is that your glReadPixels() call looks ok, as long as the format and type are the same as the buffer it should work. Does glGetError() report anything straight after?
She who travels light — forgot something.
Please note that my name doesn't start with the @ character so can people please stop writing it as if it does!

thusharajayan
Posts: 17
Joined: Tue May 05, 2015 5:21 am

Re: Opengl es2.0 glreadpixels filling all zeros

Wed May 06, 2015 9:59 am

Hi,

I am not getting any error with glGetError.
Regards
Thushara.

User avatar
PeterO
Posts: 6095
Joined: Sun Jul 22, 2012 4:14 pm

Re: Opengl es2.0 glreadpixels filling all zeros

Wed May 06, 2015 10:21 am

It would seem that PVR has wrapped all the opengl calls to produce this error message : "PVR:(Error): glReadPixels: Failed to get strided data".

You really need to find a forum dedicated to your TI hardware and ask your questions there.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

thusharajayan
Posts: 17
Joined: Tue May 05, 2015 5:21 am

Re: Opengl es2.0 glreadpixels filling all zeros

Wed May 06, 2015 11:43 am

Thanks .I will try that.
I need a clarification regarding the format and type we specify in glReadPixels.
My understanding about that is we can specify what format and type we need to read the values from display buffers. It need not be same as what we have written into it. please correct me if I am wrong
Regards
Thushara.

User avatar
PeterO
Posts: 6095
Joined: Sun Jul 22, 2012 4:14 pm

Re: Opengl es2.0 glreadpixels filling all zeros

Wed May 06, 2015 11:52 am

thusharajayan wrote:Thanks .I will try that.
I need a clarification regarding the format and type we specify in glReadPixels.
My understanding about that is we can specify what format and type we need to read the values from display buffers. It need not be same as what we have written into it. please correct me if I am wrong
Regards
Thushara.
The formats supported by your TI soc hardware may not be the same as the RASPBERRY PI soc supports. Here on the RASPBERRY PI forums we cannot help you with these issues you have with your TI hardware. You need to ask these questions on a TI specific forum.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
Paeryn
Posts: 3531
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Opengl es2.0 glreadpixels filling all zeros

Wed May 06, 2015 1:32 pm

thusharajayan wrote:Thanks .I will try that.
I need a clarification regarding the format and type we specify in glReadPixels.
My understanding about that is we can specify what format and type we need to read the values from display buffers. It need not be same as what we have written into it. please correct me if I am wrong
Regards
Thushara.
GL_RGBA and GL_UNSIGNED_BYTE should be available but if it doesn't work then you need to query what to use with glGetIntegerv() for GL_IMPLEMENTATION_COLOR_READ_TYPE and GL_IMPLEMENTATION_COLOR_READ_FORMAT.
She who travels light — forgot something.
Please note that my name doesn't start with the @ character so can people please stop writing it as if it does!

thusharajayan
Posts: 17
Joined: Tue May 05, 2015 5:21 am

Re: Opengl es2.0 glreadpixels filling all zeros

Thu May 07, 2015 7:24 am

Hi,
Ive posted in TI forum as well, but I have not got any response yet.
I wanted to know if I am doing any generic mistakes with respect to usage of my glReadPixels.

As per your suggestion I have queried the format and type. I am getting GL_UNSIGNED_BYTE as a response to GL_IMPLEMENTATION_COLOR_READ_TYPE. But the return value when I queried for GL_IMPLEMENTATION_COLOR_READ_FORMAT is giving me some value which is invalid ,It is none of the following values: GL_RGBA, GL_RGB, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_LUMINANCE, GL_DEPTH_COMPONENT.
These values are in the pixel formats listed in GLUT header file.


What could be the reason for this kind of behaviour?

Regards
Thushara.

User avatar
Paeryn
Posts: 3531
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Opengl es2.0 glreadpixels filling all zeros

Thu May 07, 2015 10:06 am

thusharajayan wrote:Hi,
Ive posted in TI forum as well, but I have not got any response yet.
I wanted to know if I am doing any generic mistakes with respect to usage of my glReadPixels.

As per your suggestion I have queried the format and type. I am getting GL_UNSIGNED_BYTE as a response to GL_IMPLEMENTATION_COLOR_READ_TYPE. But the return value when I queried for GL_IMPLEMENTATION_COLOR_READ_FORMAT is giving me some value which is invalid ,It is none of the following values: GL_RGBA, GL_RGB, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_LUMINANCE, GL_DEPTH_COMPONENT.
These values are in the pixel formats listed in GLUT header file.


What could be the reason for this kind of behaviour?

Regards
Thushara.
It may be a PVR defined format rather than standard gles, it'd have an _EXT at the end like GL_BGRA_EXT.
Does glReadPixels not accept the value returned? I find that strange as that's its only use. What is the numerical value?
She who travels light — forgot something.
Please note that my name doesn't start with the @ character so can people please stop writing it as if it does!

thusharajayan
Posts: 17
Joined: Tue May 05, 2015 5:21 am

Re: Opengl es2.0 glreadpixels filling all zeros

Thu May 07, 2015 10:15 am

Hi I am getting 0x80e1 for GL_IMPLEMENTATION_COLOR_READ_FORMAT.
eglGet Error is not returning any errors,So I don't know how to verify is glReadPixels accepts this format or not.

Regards
Thushara.

thusharajayan
Posts: 17
Joined: Tue May 05, 2015 5:21 am

Re: Opengl es2.0 glreadpixels filling all zeros

Thu May 07, 2015 11:33 am

Hi
I have checked the value for 0x 80e1 I was getting as GL_IMPLEMENTATION_COLOR_READ_FORMAT.
It corresponds to GL_BGRA_EXT. It is defined in gl2ext.h.

Regards
Thushara.

User avatar
Paeryn
Posts: 3531
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Opengl es2.0 glreadpixels filling all zeros

Thu May 07, 2015 12:46 pm

glReadPixels will accept it, it only accepts 2 pairs, either RGBA & Unsigned Byte or the pair returned by the IMPLEMENTATION_COLOR_READ_TYPE & _FORMAT.

Is it working for you now?
She who travels light — forgot something.
Please note that my name doesn't start with the @ character so can people please stop writing it as if it does!

thusharajayan
Posts: 17
Joined: Tue May 05, 2015 5:21 am

Re: Opengl es2.0 glreadpixels filling all zeros

Thu May 07, 2015 12:48 pm

No...even with GL_BGRA_EXT, I am getting all zeros.
I am getting : PVR:(Error): glReadPixels: Failed to get strided data [1046, /pixelop.c]
with those 2 pairs.

Regards
Thushara.

User avatar
Paeryn
Posts: 3531
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Opengl es2.0 glreadpixels filling all zeros

Thu May 07, 2015 1:33 pm

In that case it sounds like you've got a broken driver. The only other thing I can think that could cause problems is if the memory you've allocated to data isn't big enough to hold the buffer and the mmu is causing the errors.
I'll try some stuff out later on one of my omaps, but it has a much older gpu than yours. You really need to get in touch with your board's manufacturer, TI, or ImgTec.
She who travels light — forgot something.
Please note that my name doesn't start with the @ character so can people please stop writing it as if it does!

thusharajayan
Posts: 17
Joined: Tue May 05, 2015 5:21 am

Re: Opengl es2.0 glreadpixels filling all zeros

Thu May 07, 2015 1:42 pm

Hi

I don't think this could be due to insufficient memory as I have tried allocating more than the queried size.
Meanwhile I am trying to get in touch with TI.
Thanks for the support
Regards
Thushara.

Return to “OpenGLES”