开发者

GLUT Creating a binary / RAW image file

I have question about creating a binary / raw image file.

I've made an image in photoshop and now I want to load that in a C program. I followed this tutorial http://www.nullterminator.net/gltexture.html but I don't know 开发者_高级运维how to convert my own image to a .RAW file.

Can anyone help me out with this question?


Download ImageMagick, it is a command-line utility that can convert images into all kind of ways. And it supports many platforms. So you could save your file in Photoshop to for example a PNG file, then run the following command to convert it to raw grayscale 8 bit:

convert MyImage.png -depth 8 gray:MyRawImage.raw


Try Save As and selecting RAW from the format drop-down. Humorously, it is listed under "P" for Photoshop RAW.

I don't know if it is the right kind of RAW which GLUT requires...


This worked for me, with that tutorial code:

  1. Open your image in GIMP
  2. Go to Layer/Transparency/Remove Alpha Channel. If it's already removed the option will be greyed out, which is fine. If you have multiple layers, do this for all of them. (You MUST remove the alpha channel or else GIMP will write RGBA instead of RGB, and you'll just see a repeating lattice pattern instead of your image.)
  3. File/Save As... and at the very bottom of the save popup, there's an option "Select File Type (By Extension)" with a (+). Expand it.
  4. Select Raw image data
  5. At the top of the save popup, manually give your file a .raw extension and save. Click OK to accept the default options.

Then you should be able to save it, move it to your program's directory, and read it in with the code from that tutorial.

Also, to save yourself another headache source, I suggest adding an error message if the file isn't found, like replace the line

if ( file == NULL ) return 0;

with

if ( file == NULL ){
    printf("texture file not found.");
    return 0;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜