DevIL_manual (1265195), страница 5
Текст из файла (страница 5)
If the image already hasmipmaps, the previous mipmaps are erased, and new mipmaps are generated. Otherwise,iluBuildMipmaps generates mipmaps for the image.The mipmaps built are always powers of 2. If the original image does not have power-of-2dimensions, iluBuildMipmaps resizes the original image via iluScale to have power-of-2dimensions.9.1.2 Mipmap AccessAccess mipmaps through the iluActiveMipmap function:ILboolean ilActiveMipmap(ILuint MipNum);iluActiveMipmap sets the current image to the MipNum mipmap level of the currentimage. If there are no mipmaps present, then iluActiveMipmap returns IL_FALSE, else itreturns IL_TRUE. The base image is mipmap level 0, so specify 0 for MipNum to return tothe base image.
The only other method for setting the current image to the base image isto call ilBindImage again.9.2 AnimationsAnimations are similar to mipmaps, but instead of being smaller successive images, theimages are the same size but have different data.
The successive animation chains in DevILcan be used to create animations in your programs. File formats that natively supportanimations are .gif and .mng. You can also create your own sub-images as animations.9.2.1 Animation Chain CreationTo be added...9.2.2 Animation Chain AccessAccess animations through the iluActiveImage function:ILboolean ilActiveImage(ILuint ImageNum);Chapter 9: Sub-Images20iluActiveImage sets the current image to the ImageNum animation frame of the currentimage. If there are no animation frames present, then iluActiveImage returns IL_FALSE,else it returns IL_TRUE.
The base image is animation frame 0, so specify 0 for ImageNumto return to the base image. The only other method for setting the current image to thebase image is to call ilBindImage again.iluActiveImage is functionally equivalent to iluActiveMipmap, except that it dealswith animations and not mipmaps.9.3 LayersDevIL does not have a full layer implementation yet.9.4 Sub-Image MixingAn image can have both mipmaps and animations at the same time.
Every image inan animation chain can have its own set of mipmaps, though it is not necessary by anymeans. If you “activate” an animation image in the base image’s animation chain, theactive image becomes the new “base” image. Therefore, if you call iluActiveMipmap afteriluActiveImage, a mipmap from the selected image in the animation chain is chosen.Chapter 10: DXTC/S3TC Notes2110 DXTC/S3TC Notes10.1 DDS Loading/SavingDevIL supports loading and saving of Microsoft .dds files.
DDS files can either be compressed or uncompressed. If they are compressed, DDS files use DirectX Texture Compression (DXTC). DXTC is also known as S3TC, since Microsoft licensed the compressiontechnology from S3.10.1.1 Keeping DXTC DataWhen loading, DevIL uncompresses the DXTC. If you call ilEnable with theIL KEEP DXTC DATA parameter, DevIL will keep an uncompressed copy of the DXTCdata along with the image.
Functions that deal with DXTC data can use this data withouthaving to recompress the uncompressed data, making these functions operate faster. Theonly drawback is the use of more memory.10.1.2 Controlling SavingDevIL’s DXTC support consists of three different compression formats: DXT1, DXT3 andDXT5. DXT2 and DXT4 use premultiplied alpha, which not even OpenGL supports. DevILloads DXT2 and DXT4 textures but immediately converts them to formats that do not usepremultiplied alpha. To set what format to save DDS files in, use this line:ilSetInteger(IL_DXTC_FORMAT, Format);Format can be IL DXT1, IL DXT3 or IL DXT5.10.2 Retrieving DXTC DataTo retrieve a copy of the DXTC data, use ilGetDXTCData. To determine how large Buffershould be, first call ilGetDXTCData with the Buffer parameter as NULL.
This function willthen return the number of bytes that are required to completely store the DXTC data. Callit a second time to actually retrieve the data.ILuint ilGetDXTCData(ILvoid *Buffer, ILuint BufferSize,ILenum DXTCFormat);If the DXTC data does not exist in the format that you request, DevIL will automaticallycompress the data. If ilGetDXTCData returns 0, then the data could not be compressed.To see if a certain format of DXTC data already exists for the currently bound image, callilGetInteger with the IL_DXTC_DATA_FORMAT parameter.10.3 OpenGL/Direct3D DXTC SupportILUT allows you to directly send the DXTC data to OpenGL or Direct3D.
Several modesin ILUT directly control this behavior.10.3.1 OpenGL S3TC SupportOpenGL can use S3TC (DXTC) textures via extensions. If a computer does not supportthe S3TC texture extension, DevIL will just send the data normally through glTexImage2D,as always. Please keep in mind that DDS files store their data in a top-down format, so ifChapter 10: DXTC/S3TC Notes22you enable the OpenGL S3TC support, make certain to set the origins of all images in theupper left:ilEnable(IL_ORIGIN_SET);ilSetInteger(IL_ORIGIN_MODE, IL_ORIGIN_UPPER_LEFT);To enable the OpenGL S3TC support, use the ilutEnable function with the ILUT_GL_USE_S3TC parameter:ilutEnable(ILUT_GL_USE_S3TC);Setting this parameter means that ILUT will only use DXTC data from images that arealready compressed with DXTC (e.g.
DDS files). To force ILUT to compress any image itsends to OpenGL, use ilutEnable again:ilutEnable(ILUT_GL_GEN_S3TC);This can adversely affect your performance while loading textures, though, so use it withcaution, especially if you are running a performance-critical application.10.3.2 Direct3D DXTC SupportILUT’s Direct3D (D3D) support works exactly like the OpenGL support, except you usethe ILUT_D3D_USE_DXTC and ILUT_D3D_GEN_DXTC defines instead of ILUT_GL_USE_S3TC andILUT_GL_GEN_S3TC, respectively.Appendix A: Common DevIL #defines23Appendix A Common DevIL #definesHere goes lists of DevIL #defines used in functions that manipulate image data. As youcan see, they are self-explanatory.A.1 format-related #definesIL_COLOUR_INDEXIL_RGBIL_RGBAIL_BGRIL_BGRAIL_LUMINANCEA.2 type-related #definesIL_BYTEIL_UNSIGNED_BYTEIL_SHORTIL_UNSIGNED_SHORTIL_INTIL_UNSIGNED_INTIL_FLOATIL_DOUBLEA.3 Language-related #definesIL_ENGLISHIL_ARABICIL_DUTCHIL_GERMANIL_JAPANESEIL_SPANISHAppendix B: Common DevIL Error Codes24Appendix B Common DevIL Error CodesErrors sometimes occur within DevIL.
To get the error code of the last error that occurred,call ilGetError with no parameters. To get a human-readable string of an error code, calliluErrorString with the error code. A table of error codes follows:Error code #defineIL_NO_ERRORIL_INVALID_ENUMIL_OUT_OF_MEMORYIL_FORMAT_NOT_SUPPORTEDIL_INTERNAL_ERRORIL_INVALID_VALUEIL_ILLEGAL_OPERATIONIL_ILLEGAL_FILE_VALUEIL_INVALID_FILE_HEADERIL_INVALID_PARAMIL_COULD_NOT_OPEN_FILEIL_INVALID_EXTENSIONIL_FILE_ALREADY_EXISTSIL_OUT_FORMAT_SAMEIL_STACK_OVERFLOWIL_STACK_UNDERFLOWIL_INVALID_CONVERSIONIL_BAD_DIMENSIONSIL_FILE_READ_ERRORIL_LIB_JPEG_ERRORIL_LIB_PNG_ERRORIL_LIB_TIFF_ERRORIL_LIB_MNG_ERRORIL_LIB_JP2_ERRORIL_UNKNOWN_ERRORHexvalue0x0000x5010x5020x5030x5040x5050x5060x5070x5080x5090x50A0x50B0x50C0x50D0x50E0x50F0x5100x5110x5120x5E20x5E30x5E40x5E50x5E60x5FFDecimalvalue0128112821283128412851286128712881289129012911292129312941295129612971298150615071508150915101535Appendix C: Supported File Formats25Appendix C Supported File FormatsDevIL supports loading and saving of a large number of image formats.
Table lists theformats DevIL supports sorted according to #define.Format nameWindows bitmapC-style headerDr. Halo Cut FileZSoft Multi-PCXDirectDraw surfaceDOOM walls/flatsExtension.bmp.h.cut.dcx.dds.lmpIL #defineIL_BMPIL_CHEDIL_CUTIL_DCXIL_DDSIL_DOOM,IL_DOOM_FLATIL_GIFIL_ICOLoading?yesnoyesyesyesyesGraphics Interchange Format .gifyesRadianceHighDynamic .hdryesRangeIcons.ico, .curIL_ICOyesMacintosh Icons.icnsIL_ICNSyesJpeg Network Graphics.jngIL_JNGyesJpeg 2000.jp2IL_JP2yesJpeg.jpg, .jpe, .jpegIL_JPGyesInterlaced Bitmap.lbmIL_LBMyesHomeworld File.lifIL_LIFyesHalf-Life Model.mdlIL_MDLyesMng Animation.mngIL_MNGyesPhotoCD.pcdIL_PCDyesZSoft PCX.pcxIL_PCXyesPIC.picIL_PICyesPIX.pixIL_PIXyesPortable Network Graphics.pngIL_PNGyesPnm.pbm, .pgm, .ppm, .pnm IL_PPMyesAdobe PhotoShop.psdIL_PSDyesPaintShop Pro.pspIL_PSPyesPixar.pxrIL_PXRyesRaw data*IL_RAWyesSilicon Graphics.sgi, .bw, .rgb, .rgbaIL_SGIyesTarga.tgaIL_TGAyesTIFF.tif, .tiffIL_TIFyesQuake2 Texture.walIL_WALyesX Pixel Map.xpmIL_XPMyesException: IL_JPG (IJL) type is not supported by ilLoadF nor by ilSaveF.
IL_JPG(libjpeg) is supported by both.Saving?yesyesnonoyesnonoyesnonononoyesnononononoyesnonoyesyesyesnonoyesyesyesyesnoyesAppendix D: Sample DevIL program26Appendix D Sample DevIL programIf you are not used to this approach, you may be grateful for a short program demonstratinghow to actually use DevIL:#include<IL/il.h>#include<stdlib.h>// because of malloc() etc.int main(){ILunt handle, w, h;// First we initialize the library. Never forget that...ilInit();// We want all images to be loaded in a consistent mannerilEnable(IL_ORIGIN_SET);// In the next section, we load one imageilGenImages(1, & handle);ilBindImage(handle);ilLoadImage("our_image_file.jpg");// Let’s spy on it a little bitw = ilGetInteger(IL_IMAGE_WIDTH);// getting image widthh = ilGetInteger(IL_IMAGE_HEIGHT);// and heightprintf("Our image resolution: %dx%d\n", w, h);// how much memory will we need?int memory_needed = w * h * 3 * sizeof(unsigned char);// We multiply by 3 here because we want 3 components per pixelvoid * data = malloc(memory_needed);// finally get the image datailCopyPixels(0, 0, 0, w, h, 1, IL_RGB, IL_UNSIGNED_BYTE, data);// now we don’t need the loaded image - the data is already oursilDeleteImages(1, & handle);// We want to process the image, right?process image(data, w, h);// And maybe we want to save that all...// So we have to define a new image..ilGenImages(1, & handle);ilBindImage(handle);// and stuff it with our precious data!ilTexImage(w, h, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, data);// and dump them to the disc...ilSaveImage("our_result.png");// Finally, clean the mess!ilDeleteImages(1, & handle);free(data);return 0;}IndexIndexindex entry, another .
. . . . . . . . . . . . . . . . . . . . . . . . . . . 127.