How Get RGB values from a image in memory?
OPENGL
Hello::
I have a image in memory:
"depthimage = (unsigned char *)malloc(600*600*sizeof(GL_FLOAT)); "
How can retrieve the RGB values from each pixel?... (to compare values)???
HELP
Alert
Hello::

I have a image in memory:
"depthimage = (unsigned char *)malloc(600*600*sizeof(GL_FLOAT)); "
How can retrieve the RGB values from each pixel?... (to compare values)???
HELP
Alert
Provided that you've actually loaded the texture, I see two problem ahead. First of all, GL_FLOAT is most likely not what you have in a texture. You probably have the pixels as groups of bytes. If so, you should malloc (bits_per_pixel * 600*600*sizeof (char)); Now, how many is depending on the format of the image in memory. Where did you get this image from? Does it have alpha? If it does, bits_per_pixel above should be 4, else it should be 3. Anyway, if you assume that the image is in RGB format (which isn't always the case, mind you), then the first byte is the red value, the next is the green value and the next is the blue value. Then, the next pixel's three values and so on.
Now, please provide som more info on what you're doing - where does the image come from? Have you rendered to texture? Loaded from a file, and if so, what kind of file?
Now, please provide som more info on what you're doing - where does the image come from? Have you rendered to texture? Loaded from a file, and if so, what kind of file?
I´m trying developer an opengl program to detect collisions by a image of z-buffer values..
Code:
unsigned char *depthimage;
depthimage = (unsigned char *)malloc(600*600*sizeof(GL_FLOAT));
glReadPixels(0,0,600,600,GL_DEPTH_COMPONENT,GL_FLOAT,depthimage );
So...
how can access to the values of each pixel in this image ...to do a collision test!!!!
Alert
Code:
unsigned char *depthimage;
depthimage = (unsigned char *)malloc(600*600*sizeof(GL_FLOAT));
glReadPixels(0,0,600,600,GL_DEPTH_COMPONENT,GL_FLOAT,depthimage );
So...
how can access to the values of each pixel in this image ...to do a collision test!!!!
Alert
Not retrieve the RGB values from each pixel but the depht vaues for each pixel!!!
Ah, that's easy. Assume that your coordinates are x and y, you do:
float *depthValuePtr = (float *)(depthImage + (y * 800) + x);
Your value is now pointed to by depthValuePtr.
float *depthValuePtr = (float *)(depthImage + (y * 800) + x);
Your value is now pointed to by depthValuePtr.
its supposed to be whatever your image's width is.
another thing: dont use "unsigned char*". If you dont know what an array's type is, use void*. But, since in this case you use GL_FLOAT, make it a GL_FLOAT*
another thing: dont use "unsigned char*". If you dont know what an array's type is, use void*. But, since in this case you use GL_FLOAT, make it a GL_FLOAT*
Sorry I continue without understanding....
I have a image (600*600) in memory...
I want retrieve the Z-buffer value for each pixel.....
I don´t now I I use the up code?....
Sorry.. please help again
Alert
I have a image (600*600) in memory...
I want retrieve the Z-buffer value for each pixel.....
I don´t now I I use the up code?....
Sorry.. please help again
Alert
Oh, sorry - your image was 600 pixels wide, so it should 600 * y + x then.
It's a little late to poke in here, but if you're using glReadPixels to do a collision test you're going to have some serious performance issues. You're probably better off doing collisions manually by tracking rects or something.
Anyway, this reminds me of a TRON game I wrote with friend in highschool, for the original classic mac ( with 496 kb of ram... ) where we didn't have enough memory to model collision detection so we read back pixel values from the screen buffer. Those were the days
Anyway, this reminds me of a TRON game I wrote with friend in highschool, for the original classic mac ( with 496 kb of ram... ) where we didn't have enough memory to model collision detection so we read back pixel values from the screen buffer. Those were the days
Shoot Things actually uses readback for collision detection, because it was the easiest way to do arbitrary concave object intersection. Check the source if you want to see how.
Readback is slow, but if you are careful it is not too bad. Runs at 60fps on anything newer than a Rage 128...
Readback is slow, but if you are careful it is not too bad. Runs at 60fps on anything newer than a Rage 128...
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| passing values from vertex to fragment shader | Sumaleth | 6 | 8,637 |
Feb 18, 2011 01:54 AM Last Post: Holmes |
|
| Changing Pixel Values using CG | LIPH700 | 1 | 3,756 |
Nov 25, 2010 03:17 PM Last Post: SethWillits |
|
| Reading texture colors values | Leroy | 6 | 4,116 |
Jul 24, 2007 10:06 PM Last Post: Leroy |
|
| "Inconsistent set of values to create NSBitmapImageRep" Help! | Joseph Duchesne | 2 | 4,985 |
Sep 30, 2005 05:32 PM Last Post: Joseph Duchesne |
|
| Passing values to SDL_LoadBMP strangeness | Lunatic | 0 | 2,271 |
Sep 7, 2005 08:49 PM Last Post: Lunatic |
|

