2

I have a bitmap image that is currently represented as a byte array (could be YCrCb or RGB). Is there a function build in to OpenGL that will allow me to looks at individual pixels from this byte array?

I know that there is the function glReadPixels but I don't need to be reading from the frame buffer if I've already got the data.

If not, is there an alternative way to do this in C++?

1
  • Have a look at Cimg. Commented Sep 4, 2011 at 23:28

1 Answer 1

5

OpenGL is a drawing API, not some kind of all purpose graphics library – The 'L' in OpenGL means should be read as Layer, not library.

That being said: If you know the dimensions of the byte array, and the data layout, then it is trivial to fetch individual pixels.

pixel_at(x,y) = data_byte_array[row_stride * y + pixel_stride * x]

in a tightly packed format

pixel_stride = bytes_per_pixel
row_stride = width * pixel_stride
Sign up to request clarification or add additional context in comments.

2 Comments

"The 'L' in OpenGL means Layer, not library." Not according to the OpenGL Specification. On page 1, the section appropriately titled, "What is the OpenGL Graphics System?", the very first line is "OpenGL (for "Open Graphics Library")". The rest of your statement is correct though.
@Nicol Bolas: I'm fully aware that officially the L means library. But today one should read it as Layer and I hope someday this change will be made official.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.