reading image file into an array

Most of us can read in a texture image file and map it onto a polygon/shape.
But I want to know how can I read nay image file into an array. So Im able to have access to any (x,y) position and its rgb values.


Either you write the code yourself. For that you need to know the file format. You can find doc on Or you use an API to do that. I recommend DevIL. This API has been discussed recently on this board.

[This message has been edited by Morglum (edited 01-06-2003).]

I’m not sure I understand the question.If you can use the image as an opengl texture then you upload it using an glTexture*D call.The last arg to this call is a pointer(an array) to the pixels.Accessing specific RGB values of pixels denpends on the format of the image but it should be easy to do.

once you have the data into the array, the formula for plotting coordinates is:

array[x + (y*w)]

x is the x coordinate you want to modify
y is the y coordinate
w is the width of the texture in pixels

this approach works best when you use a struct for holding rgb triples or quads, or else you have to use an offset for the data…or just store the data in unsigned ints