DevIL_manual (1265195), страница 2
Текст из файла (страница 2)
The bug appears tooccur when you use a #pragma to link a .lib file and link it via another method. The headerfiles il.h, ilu.h and ilut.h automatically link the .lib files in via a #pragma for convenience.To prevent this bug, check for and remove these:• devil.lib, devil-d.lib, ilu.lib, ilu-d.lib, ilut.lib and ilut-d.lib in your project settings(Project Settings menu).• devil.lib, devil-d.lib, ilu.lib, ilu-d.lib, ilut.lib and ilut-d.lib in your project’s workspace.Some people link libraries into their project this way, which really should be discouraged, due to the hardcoded paths.2.1.3 MultithreadingDevIL takes advantage of the multithreaded standard LIBC DLLs.
To use file streams withDevIL, you must change the project settings of your project. If you do not perform thesesteps, your program will crash whenever you attempt to use a DevIL file stream.Generally, DevIL is not thread safe. You should make sure that threads in your application do not use DevIL at the same time.1. Navigate to the Project menu and choose Settings.2.
Click the C/C++ tab.3. Change the Category drop-down menu to read Code Generation.4. Change the Use run-time library drop-down menu to Multithreaded DLL if the SettingsFor menu says Win32 Release. Change the Use run-time library drop-down menu toDebug Multithreaded DLL if the Settings For menu says Win32 Debug.Chapter 2: Library setup45.
Choose OK.2.2 DJGPP SetupSetting up DevIL in DJGPP requires the following steps:1. Unzip DevIL in an empty directory. If using WinZip, check the “Use folder names”box before unzipping. Use the -d command line option if using pkunzip.2. Create a new subdirectory called il’ in your DJGPP include directory.3. Copy the files to their respective places:• To use the precompiled libraries, copy libil.a, libilu.a and libilut.a fromImageLib\lib\djgpp to your DJGPP lib directory. Then copy il.h, ilu.h and ilut.hfrom your ImageLib\lib\il directory to your DJGPP include\il directory.• To compile the library yourself, change directories to ImageLib\Makefiles\Djgpp.This folder contains only a makefile for DJGPP.
Simply type make’, and the makefile will compile DevIL and copy the files to their respective locations.To compile with DevIL in DJGPP, add ‘-lil’ to your command line. To also use ILUand ILUT, use ‘-lilu’ and ‘-lilut’, respectively.2.3 General GCC-based (Linux, Cygwin, Max OS X, etc.)SetupSetting up DevIL in this environment requires the following steps:1.2.3.4.‘’Unzip DevIL in an empty directory, by typing gzip d gzipname followed by tarxvf tarname, where ‘gzipname’ and ‘tarname’ are ‘DevIL-x.x.x.tar.gz’ and‘DevIL-x.x.x.tar’.Unzip should automatically use the directory structure present in the DevIL zip file.To use the precompiled libraries, copy ‘libIL.so’, ‘libILU.so’ and ‘libILUT.so’ to aplace specified in your library path, or use the full path to the libraries when compiling.To compile the library yourself: Type ./configure, you get a long text.
Then, typemake followed by make install.Chapter 3: Basic usage53 Basic usageYou must initialize DevIL, or it will most certainly crash. You need to initialize each library(IL, ILU, and ILUT) separately. You do not need to initialize libraries you are not using, butkeep in mind that the higher level libraries are dependent on the lower ones. For example,ILUT is dependent on ILU and IL, so you have to initialize IL and ILU as well.3.1 Initializing DevIL3.1.1 IL InitializationSimply call the ilInit function with no parameters:// Initialize ILilInit();3.1.2 ILU InitializationCall the iluInit function with no parameters:// Initialize ILUiluInit();3.1.3 ILUT InitializationILUT initialization is slightly more complex than IL and ILU initialization.
The functionyou will use is ilutRenderer. You must call ilutRenderer before you use any ILUTfunctions. This function initializes ILUT support for the API you desire to use by a singleparameter:• ILUT_OPENGL – Initializes ILUT’s OpenGL support.• ILUT_ALLEGRO – Initializes ILUT’s Allegro support.• ILUT_WIN32 – Initializes ILUT’s Windows GDI and DirectX 8 support.An example of using ilutRenderer follows:// Initialize ILUT with OpenGL support.ilutRenderer(ILUT_OPENGL);3.2 Image Name HandlingImage names are DevIL’s way of keeping track of images it is currently containing. Someother image libraries return structs, but they generally seem more cluttered than DevIL’simage name handling.ILvoid ilGenImages(ILsizei Num, ILuint *Images);ILvoid ilBindImage(ILuint Image);ILvoid ilDeleteImages(ILsizei Num, ILuint *Images);3.2.1 Generating Image NamesUse ilGenImages to generate a set of image names.
ilGenImages accepts an array ofILuint to receive the generated image names. There are no guarantees about the order ofthe generated image names or any other predictable behaviour like this. If ilDeleteImagesChapter 3: Basic usage6is called on an image name, ilGenImages will return that value afterward, until all deletedimage names are used. This conserves memory and is generally quick. The only guaranteeis that each member of the Images parameter (up to Num number of them) will have a new,unique value.3.2.2 Binding Image NamesilBindImage binds the current image to the image described by the image name in Image.DevIL reserves the number zero for the default base image.
If you pass a value for Image thatwas not generated by ilGenImages, ilBindImage automatically creates an image specifiedby the image name passed. An image must always be bound before you call any functionsthat operate on images and their data.When DevIL creates a new image, the image has the default properties of with a bitdepth of 8. DevIL creates a new image when you call ilBindImage with an image namethat has not been generated by ilGenImages or when you call ilGenImages specifically.3.2.3 Deleting Image NamesilDeleteImages is the exact opposite of ilGenImages and even accepts the exact same parameters.
ilDeleteImages deletes image names to free memory for subsequent operations.You should always call ilDeleteImages on images that are not in use anymore. Whenyou delete an image, DevIL actually deletes all data and anything associate with it, so thatilGenImages can possibly use the image name later.3.3 File handling – loading imagesDevIL’s main purpose is to load images. DevIL’s loading is designed to be extremely easybut very powerful. Appendix B lists the image types DevIL is capable of loading.DevIL contains four loading functions to support different loading styles and loadingfrom several different image sources.ILbooleanILbooleanILbooleanILbooleanilLoadImage(const char *FileName);ilLoad(ILenum Type, const char *FileName);ilLoadF(ILenum Type, ILHANDLE File);ilLoadL(ILenum Type, ILvoid *Lump, ILuint Size);3.3.1 Loading from Files – ilLoadImageilLoadImage is the main DevIL loading function.
All you do is pass ilLoadImage thefilename of the image you wish to load. ilLoadImage takes care of the rest. ilLoadImageallows users to transparently load several different image formats uniformly. DevIL’s mostpowerful function is ilLoadImage because of this feature.Before loading the image, ilLoadImage must first determine the image format of thefile. ilLoadImage performs the following steps:1. Compares the filename’s extension to any registered file handlers, allowing the registered file handlers to take precedence over the default DevIL file handlers. If theextension matches a registered file handler, ilLoadImage passes control to the file handler and returns. For more information on registering, refer to the section entitled“Registration”.Chapter 3: Basic usage72. Compares the filename’s extension to the extensions natively supported by DevIL.
Ifthe extension matches a loading function’s extension, ilLoadImage passes control tothe file handler and returns.3. Examines the file for a header and tries to match it with a known type of image header.If a valid image header is found, ilLoadImage passes control to the appropriate filehander and returns.4. Returns IL_FALSE.3.3.2 Loading from Files – ilLoadDevIL’s other file loading function is ilLoad. ilLoad is similar to ilLoadImage in manyrespects but different in other ways.
ilLoad accepts two parameters: the type of image andthe filename of the image.ilLoad’s type parameter is what differentiates it from ilLoadImage. Type can be anyof the values listed in table B-2 in appendix B or the value IL_TYPE_UNKNOWN. If Typeis a value from table B-1, ilLoad attempts to load the file as the specified type of imageformat. Only use this if you know what type of images you will be loading and want tobypass DevIL’s checks.If IL_TYPE_UNKNOWN is specified for Type, ilLoad behaves exactly like ilLoadImage.Refer to the previous section for detailed behaviour of these two functions.3.3.3 Loading from File Streams – ilLoadFDevIL’s file stream loading function is ilLoadF. ilLoadF is exactly equivalent to ilLoad,but instead of accepting a const char pointer, ilLoadF accepts an ILHANDLE.
DevILdefines ILHANDLE as a void pointer via a typedef. Under normal circumstances, File will bea FILE struct pointer defined in stdio.h.Refer to the section entitled “Registration“ for instructions on how to use your own filehandling functions and file handles.3.3.4 Loading from Memory Lumps – ilLoadLDevIL’s file handling is abstracted to allow loading images from memory called “lumps”.ilLoadL handles loading from lumps. You must specify a valid type as the first parameterand the lump as the second parameter.The third parameter that ilLoadL accepts is the total size of the lump. DevIL uses thisvalue to perform bounds checking on the input data.