Jump to content
  • Advertisement
Sign in to follow this  
DingOunan

[DevIL]about write pixels to a file

This topic is 3985 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

I want to make a screenshot use DevIL,but I failed. I have tried this things: 1.initialize the IL,generate the image,and bind the image.this is called just after I created the surface(use SDL_SetVideoMode),before any render calls.It is called only onece. <code> ilInit() ilGenImages(1,& image); ilBindImage(image); </code> 2.allocate the memory for reading <code> void* pixels=malloc(sizeof(unsigned int)*width*height); </code> 3.read the pixels from the buffer.and write to the file. <code> glReadPixels(0,height,width,height,GL_RGBA,GL_UNSIGNED_BYTE,pixels); ilSetData(pixels); //line #1 ilSave(IL_PNG,filename); </code> at line #1,I tried ilLoadL,ilCopyPixels,ilSetPixels,but I still can't make it work.Then I think DevIL may not know the image format,so it can't write the image.So,I use ilSetInteger: <code> ilSetInteger(IL_FORMAT_MODE,IL_RGBA); ilSetInteger(IL_TYPE_MODE,IL_UNSIGNED_BYTE); ilSetInteger(IL_IMAGE_BITS_PER_PIXEL,32); </code> I still can not make it. I know there is a function ilutGLScreen to make a screenshot.But when I link the program,many unsolved symbol...,(Linux 2.6 Fedora Core 6,DevIL 1.6.8 RC2,GCC 4.1) (gcc -oScreenShot -O3 `sdl-config --cflags --libs` -lGL -lGLU -lIL -lILU -lILUT ScreenShot.c) Is there somethink like "devil-config"? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
SOLVED!!!!!

use ilTexImage to allocate the memory for the image!

ilGenImages(1,&image);
ilBindImage(image);
//!!!!!!!!!!!!
//attention:the forth parameter is called bytes per pixel,not bits per pixel
ilTexImage(width,height,1,4,IL_RGBA,IL_UNSIGNED_BYTE,pixels);
ilSetData(pixels);
ilSave(IL_PNG,filename);

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!