Sign in to follow this  
dunnodt

how to get the rgb value of a pixel?

Recommended Posts

hi ppl, i have an image used that is mapped as texture on a quad. right now, i want to divide the image into 4 equal size quads and get the sum value of every pixel in each quad. how can i do that? does anyone knows how to get the value from the pixels? cheers, dunnodt

Share this post


Link to post
Share on other sites
What you're trying to do is some image processing on a bitmap, so it's got nothing to do with openGL. In windows, the (fast) function to read and write pixel data from/to a bitmap is scanline. You'll find plenty of doc and examples on the net.

I'm not sure what you mean with "summing pixel values".

Share this post


Link to post
Share on other sites
hey

Firstly, how do you go about loading textures into opengl? As I think you are asking how to read the pixels back after already loading into opengl, which makes me think you use some library that automatically loads them into opengl.

It might be worth making your own lib to load an image, then you can split it up before loading into opengl ;). Well there are probably libs where you can do this anyhows, hehe.

Hmm, I'm not sure how to directly read back the texture data from opengl, but I think you can read from the framebuffer / color buffer or whatever. So firstly ya would have to render ya original image on a quad. Then ya could either generate/create 4 new blank opengl textures, and then copy each section from the color buffer with glCopyTexSubImage2D() to each of them, or you could just do the same but use glReadPixels() instead, which reads to system memory.

Anyhows I hope this helps :).

cyas

Share this post


Link to post
Share on other sites
If you really want to use OpenGL for this (for performance issues maybe?) you can load the texture, set up a framebuffer that renders to a texture that is 2*2 pixels in size, use a shader that reads the texture at every pixel and then outputs the color of them together on the 2*2 framebuffer. But it would still be so much easier to do it on the CPU.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this