Copy Color data

Hey, i’ve just started using opengl and i was wondering if there is a way to copy the color buffer content to an array of colors.
I’m using a grayscale image, so I don’t need to copy the 3 RGB values for each pixel, instead i just need one.
Thank you

You could render to a fbo.

glReadPixels (slow)
and as Roest said render to fbo (IMHO best)

do you mean VBO?
If so please explain how.

btw i’m a real beginner. SO if you could show me an example.

He is talking about FBO. VBO is different from FBO. FBO is used for writing to texture.

Once you attach a texture to COLOR_ATTACHMENT, then inside fragment shader add:

Color = texture2D(<sampler2D> , <coord>)

glColor = Color; //Sends color info to all buffers


//gl_FragData[n] = Color; //sends data to specified aux buffer

//you can use GL_BACK , GL_FRONT buffers also.

To attach and use texture at FBO, refer to tutorial on FBO (google search) . Official document would be technical and uninteresting at first.

Thx Awhig for the explanation, but there’s something that’s still not clear to me.
In my project, i have to take an image and calculate 2 gradients Gx and Gy (sobel edge detection). Then, i must use these 2 color gradients to calculate G and Theta which are defined as followed:
G=sqrt(Gx^2 + Gy^2)
Theta= invtan(Gy/Gx)

so i thought about rendereing two VBO, one for Gx and the other for Gy, but how could i use the resulting buffers to calculate G and Theta?

One more thing, is there a way to access a random pixel’s color?

i meant FBO