Skip to main content
gamedev.net
🔒 Locked

loading pgm

Started by Yashin Jun 6, 2006 at 2:17 PM 2 replies 1.7k views
Original Post
Yashin
Yashin
Hi everyone. How can i load a pgm image onto opengl. Its preferable that i keep the data loaded into a matrix so that i cn access individual pixels for image processing.. any help??
extralongpants
extralongpants
You should generally avoid thinking about the problem as "loading a pgm image into OpenGL". It is more beneficial to think about it along the lines of "loading pgm image data into memory, then creating an OpenGL texture using that data" (You don't really load image files directly into OpenGL).

Googling for tutorials on loading pgm data is probably more effective than trying to ask some one here. If anyone has a response, it's probably just going to be a link to a tutorial somewhere or a 3rd party library.

As far as your data format, it's easiest to keep color data in one 1-dimensional array of unsigned bytes, and to keep track of the image's width, height, and number of channels as well. Offsets into that data representing pixels can be caculated using pixel co-ordinates and the image's width, height, and channels with some simple math.

Hope that helps.
Solias
Solias
PGM (and PPM and PBM) files are very easy to load. They are basicly just raw image data without any bells and whistles. The ASCII version is just space delimited text numbers representing each pixel with a simple header. There is also a binary version where the pixels are standard 1 or 2 byte binary unsigned integer values.

It's been a while since I had to use them for anything, but the first hit on google looks like a decent reference. If you have done any file I/O before, writting a PGM loader should be easy. As the previous poster suggested, store the image data in a 1d array and calculate the offset into the array with: offset = (width * y) + x. You can also pass this array directly in to opengl in your glTexImage2D call.

It looks like there is also a library at the link above that might work for loading the files for you.
Yashin
Yashin
Thanks a lot for the explantions. I'll try to look for some references on the web

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.