Jump to content
  • Advertisement
Sign in to follow this  
Yashin

OpenGL loading pgm

This topic is 4401 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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??

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!