View Full Version : Handling Image
02-22-2001, 11:13 PM
Is it possible to import an image (.bmp or similar), draw it on the screen and readValueOfPixel(x,y) and setNewPixelValue(x,y)
How do I import an image?
How do I get access to each pixel in the image?
This is possible but this is not hardware accelerated and therefore slow.
To import the image, you have to write a function that reads the BMP file get the pixel data out of it and store it into a buffer in RAM. The problem is that BMP are stored in BGR format (for 24bpp BMPs) whereas OpenGL uses RGB format. Therefore, you have to either use the BGR extension (bof!) or simply swap the R an G value for every pixel (not very difficult so why bother about the extension).
Then you use glDrawPixels to paste your image into the color buffer. You can use glReadPixels to read the pixels (by groups or one by one), but since you already have the pixel data stored in a buffer in RAM, it's faster to read from the buffer. You can change any pixel by using glDrawPixels again.
All this is very slow.
I think I have examples of the use of glDrawPixels, glReadPixels, somewhere ... I can try and look for them if you want.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.