PDA

View Full Version : Copy Color data



Addoula
08-04-2009, 06:08 AM
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

Roest
08-04-2009, 06:24 AM
You could render to a fbo.

kowal
08-04-2009, 08:33 AM
glReadPixels (slow)
glCopyTexImage
and as Roest said render to fbo (IMHO best)

Addoula
08-05-2009, 01:42 AM
do you mean VBO?
If so please explain how.

Addoula
08-05-2009, 01:48 AM
btw i'm a real beginner. SO if you could show me an example.

awhig
08-05-2009, 03:02 AM
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:

[CODE]
Color = texture2D(<sampler2D> , <coord>)

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

OR

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

//you can use GL_BACK , GL_FRONT buffers also.
[CODE]

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

Addoula
08-07-2009, 02:48 AM
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?

Addoula
08-11-2009, 06:18 AM
i meant FBO