示例#1
0
文件: test.cpp 项目: wg-lesta/ResIL
void test_ilLoad(wchar_t* sourceFN, wchar_t* targetFN)
{
	testHeap();
	ilInit();
	testHeap();
	ILuint handle = ilGenImage();
	testHeap();
	ilBindImage(handle);
	testHeap();
	//printf("Loading " PathCharMod "\n", sourceFN);
	ilResetRead();
	ILenum sourceType = ilDetermineType(sourceFN);
	if (!ilLoad(sourceType, sourceFN)) {
		printf("test_ilLoad: Failed to load %S\n", sourceFN);
		++errors;
		return;
	}
	testHeap();
	//ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
	//ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_BYTE);
	//iluScale(150, 150, 1);
	testHeap();
	DeleteFile(targetFN);
	//printf("Saving " PathCharMod "\n", targetFN);
	if (!ilSaveImage(targetFN)) {
		printf("test_ilLoad: Failed to save " PathCharMod "\n", targetFN);
		++errors;
	}
	testHeap();
	ilDeleteImage(handle);
}
bool CGuildMarkUploader::__Load(const char* c_szFileName, UINT* peError)
{
	ILuint uImg;
	ilGenImages(1, &uImg);
	ilBindImage(uImg);
	ilEnable(IL_ORIGIN_SET);
	ilOriginFunc(IL_ORIGIN_UPPER_LEFT);

	if (!ilLoad(IL_TYPE_UNKNOWN, (const ILstring)c_szFileName))	
	{
		*peError=ERROR_LOAD;
		return false;
	}

	if (ilGetInteger(IL_IMAGE_WIDTH)!=SGuildMark::WIDTH)	
	{
		*peError=ERROR_WIDTH;
		return false;
	}

	if (ilGetInteger(IL_IMAGE_HEIGHT)!=SGuildMark::HEIGHT)
	{
		*peError=ERROR_HEIGHT;
		return false;
	}

	ilConvertImage(IL_BGRA, IL_BYTE);

	ilCopyPixels(0, 0, 0, SGuildMark::WIDTH, SGuildMark::HEIGHT, 1, IL_BGRA, IL_BYTE, (ILvoid*)m_kMark.m_apxBuf);

	ilDeleteImages(1, &uImg);
	return true;
}
示例#3
0
bool CGuildMarkImage::Load(const char * c_szFileName) 
{
	Destroy();
	Create();	

	ilBindImage(m_uImg);
	ilEnable(IL_ORIGIN_SET);
	ilOriginFunc(IL_ORIGIN_UPPER_LEFT);

	if (!ilLoad(IL_TYPE_UNKNOWN, (const ILstring) c_szFileName))
	{
		sys_err("GuildMarkImage: %s cannot open file.", c_szFileName);
		return false;
	}

	if (ilGetInteger(IL_IMAGE_WIDTH) != WIDTH)	
	{
		sys_err("GuildMarkImage: %s width must be %u", c_szFileName, WIDTH);
		return false;
	}

	if (ilGetInteger(IL_IMAGE_HEIGHT) != HEIGHT)
	{
		sys_err("GuildMarkImage: %s height must be %u", c_szFileName, HEIGHT);
		return false;
	}

	ilConvertImage(IL_BGRA, IL_UNSIGNED_BYTE);

	BuildAllBlocks();
	return true;
}
示例#4
0
//-----------------------------------------------------------------------------
//Функция загрузки изображения текстуры
void Load_Tex_Image()
{
    int width, height, bpp;

    ilLoad(IL_BMP, reinterpret_cast<const ILstring>(TEX_IMAGE_NAME));
    int err = ilGetError();                          // Считывание кода ошибки
    if (err != IL_NO_ERROR)
    {
        const char* strError = iluErrorString(err);  // Считываем строку ошибки
        std::cout << "Error load texture image: " << strError << std::endl;
        exit(EXIT_FAILURE);
    }
    else
    {
        std::cout << "Load texture image completed!" << std::endl;
        width  = ilGetInteger(IL_IMAGE_WIDTH);
        height = ilGetInteger(IL_IMAGE_HEIGHT);
        bpp    = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);
        std::cout << "width:  "<< width << std::endl << "height: "
                  << height << std::endl << "bpp:    " << bpp << std::endl;
    }

    unsigned char* data = ilGetData();
    unsigned int type;

    switch (bpp) {
    case 1:
      type  = GL_RGB8;
      break;
    case 3:
      type = GL_RGB;
      break;
    case 4:
      type = GL_RGBA;
      break;
    }
    glGenTextures(3, &texture[0]);
        //1-я текстура
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0,
    GL_RGB, GL_UNSIGNED_BYTE, data);
        //2-я текстура
    glBindTexture(GL_TEXTURE_2D, texture[1]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0,
    GL_RGB, GL_UNSIGNED_BYTE, data);
        //3-я текстура
    glBindTexture(GL_TEXTURE_2D, texture[2]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_NEAREST);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0,
    GL_RGB, GL_UNSIGNED_BYTE, data);
}
bool CGuildMarkUploader::__LoadSymbol(const char* c_szFileName, UINT* peError)
{
	//	For Check Image
	ILuint uImg;
	ilGenImages(1, &uImg);
	ilBindImage(uImg);
	ilEnable(IL_ORIGIN_SET);
	ilOriginFunc(IL_ORIGIN_UPPER_LEFT);
	if (!ilLoad(IL_TYPE_UNKNOWN, (const ILstring)c_szFileName))
	{
		*peError=ERROR_LOAD;
		return false;
	}
	if (ilGetInteger(IL_IMAGE_WIDTH) != 64)
	{
		*peError=ERROR_WIDTH;
		return false;
	}
	if (ilGetInteger(IL_IMAGE_HEIGHT) != 128)
	{
		*peError=ERROR_HEIGHT;
		return false;
	}
	ilDeleteImages(1, &uImg);
	ilShutDown();

	/////

	FILE * file = fopen(c_szFileName, "rb");
	if (!file)
	{
		*peError=ERROR_LOAD;
	}

	fseek(file, 0, SEEK_END);
	m_dwSymbolBufSize = ftell(file);
	fseek(file, 0, SEEK_SET);

	m_pbySymbolBuf = new BYTE [m_dwSymbolBufSize];
	fread(m_pbySymbolBuf, m_dwSymbolBufSize, 1, file);

	fclose(file);

	/////

	m_dwSymbolCRC32 = GetFileCRC32(c_szFileName);
	return true;
}
void CTexture :: LoadTexture ( ILenum FileType, char *filename, TextureImage *texture )
{	
	ilLoad ( FileType, ( LPCWSTR ) filename );
 	
	int err=ilGetError ( );
	if ( err != IL_NO_ERROR )
	{
		const wchar_t* strError = iluErrorString(err);
		MessageBox ( NULL, (LPCWSTR)strError, L"Ошибка при загрузке!", MB_OK );
		exit ( 1 );
	} 
	
	texture->width = ilGetInteger(IL_IMAGE_WIDTH);			// Ширина
	texture->height = ilGetInteger(IL_IMAGE_HEIGHT);		// Высота
	texture->bpp = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);	// Байт на пиксель
 
	// Загружаем данные в нашу текстуру
	texture->imageData = ilGetData();
 
	ilEnable(IL_CONV_PAL);
 
	// Тип данных изображения
	unsigned int type = ilGetInteger(IL_IMAGE_FORMAT);
 
	// Генерируем текстуру
	glGenTextures(1, &texture->texID);
 
	// Привязываем данные текстуры к ID
	glBindTexture(GL_TEXTURE_2D,texture->texID);
 
	// биндим мип-мапы
	gluBuild2DMipmaps(GL_TEXTURE_2D, texture->bpp, texture->width,
		texture->height, type, GL_UNSIGNED_BYTE, texture->imageData);
 
	// Устанавливаем качество текстур
	glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
}
GameImage* GameResourceManager::loadImgData(DUserClient*,string filename) {
	ILuint image_id=0;
	ilGenImages(1,&image_id);
	ilBindImage(image_id);

	ILenum type=ilDetermineType(filename.c_str());
	if(!ilLoad(type,filename.c_str())) {
		printf("Failed to load image %s\n",filename.c_str());
		ilDeleteImage(image_id);
		return 0;
	}

	int w=ilGetInteger(IL_IMAGE_WIDTH);
	int h=ilGetInteger(IL_IMAGE_HEIGHT);
	int d=ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);

	if(d!=1 && d!=2 && d!=3 && d!=4) {
		printf("Unupported image depth %d, image %s\n",d,filename.c_str());
		ilDeleteImage(image_id);
		return 0;
	}

	if(d==2) d=1;

	char *data=new char[w*h*d];

	ILenum formats[]={0,IL_LUMINANCE,IL_LUMINANCE,IL_RGB,IL_RGBA};
	ilCopyPixels(0,0,0,w,h,1,formats[d],IL_UNSIGNED_BYTE,data);

	ilDeleteImage(image_id);

	GameImage* img=new GameImage();
	img->data=data;
	img->width=w;
	img->height=h;
	img->depth=d;
	return img;
}
示例#8
0
文件: main.cpp 项目: astrellon/GPP
void init()
{
	// Initialize the DevIL framework.
	ilInit();

	// Initialize OpenGL
	glInit();

	// Give the scene a starting number of spheres.
	changeSphereCount(INITIAL_SPHERE_COUNT);
	
	// Create an image ID for our font texture.
	ILubyte fontId = ilGenImage();
	ilBindImage(fontId);

	if(!ilLoad(IL_PNG, "data/font.png"))
	{
		MessageBox(NULL, "Unable to load font texture.\nThere will be no interface.", "Could not load font.", MB_OK);
	}
	else
	{
		// Tell all existing TextFields the image ID to use.
		txtNumSpheres.setFontId(fontId);
		txtRenderFrames.setFontId(fontId);
		txtPhysicsFrames.setFontId(fontId);
		txtNumThreads.setFontId(fontId);

		txtInstructions.setFontId(fontId);
		txtInstructions.setColour(0xFFFFAA);
		txtInstructions.setText("Press +/- to add or remove spheres. 1 - 9 to set sphere size.");

		txtInstructions2.setFontId(fontId);
		txtInstructions2.setColour(0xFFFFAA);
		txtInstructions2.setText("Use the arrow keys and page up/down to control the sphere.");
	}

	int iCPUVals[4];
	cpuid(1, iCPUVals);

	bool sse4Support = false;
	if(iCPUVals[2] & (1 << 19))
	{
		sse4Support = true;
	}

#ifdef _SSE4
	if(!sse4Support && _SSE4)
	{
		txtInstructions.setColour(0xFF0000);
		txtInstructions.setText("Your computer does not support SSE4, please use a different version of this program.");
		displayError = true;

		numPhysicsThreads = 1;
	}
	else
#endif
	{
		// Setup performance checking, used to determine time difference
		// between physics thread runs.
		QueryPerformanceFrequency( &frequency );
		freq = (double)frequency.QuadPart / 1000.0;
		LARGE_INTEGER firstTime;
		QueryPerformanceCounter(&firstTime);

	#if _USE_MT
		// Get the number of physics threads to use from boost.
		numPhysicsThreads = boost::thread::hardware_concurrency();
	#else
		// Set that we're only using one thread, mostly for the purpose that
		// the physics function uses the number of threads for striding.
		numPhysicsThreads = 1;
	#endif

		updateTimes = new LARGE_INTEGER[numPhysicsThreads];
		physicsFrames = new int[numPhysicsThreads];

		for(int i = 0; i < numPhysicsThreads; i++)
		{
			updateTimes[i] = firstTime;
			physicsFrames[i] = 0;
	#if _USE_MT
			threads.create_thread(boost::bind(physicsThread, i));
	#endif
		}

		char buff[32];

		sprintf(buff, "Num threads: %d", numPhysicsThreads);
		txtNumThreads.setText(buff);
	}
}
示例#9
0
ILboolean ilImage::Load(char *FileName, ILenum Type)
{
	this->iGenBind();
	return ilLoad(Type, FileName);
}
示例#10
0
ILboolean ilImage::Load(ILconst_string FileName, ILenum Type)
{
	this->iGenBind();
	return ilLoad(Type, FileName);
}
示例#11
0
文件: il_io.c 项目: jitrc/p3d
ILboolean ILAPIENTRY ilLoad(ILenum Type, const ILstring FileName) {
#ifndef _UNICODE
	if (FileName == NULL || strlen(FileName) < 1) {
#else
	char AnsiName[512];
	if (FileName == NULL || wcslen(FileName) < 1) {
#endif//_UNICODE
		ilSetError(IL_INVALID_PARAM);
		return IL_FALSE;
	}

	switch (Type)
	{
		case IL_TYPE_UNKNOWN:
			return ilLoadImage(FileName);

		#ifndef IL_NO_TGA
		case IL_TGA:
			return ilLoadTarga(FileName);
		#endif

		#ifndef IL_NO_JPG
		case IL_JPG:
			return ilLoadJpeg(FileName);
		#endif

		#ifndef IL_NO_DDS
		case IL_DDS:
			return ilLoadDds(FileName);
		#endif

		#ifndef IL_NO_PNG
		case IL_PNG:
			return ilLoadPng(FileName);
		#endif

		#ifndef IL_NO_BMP
		case IL_BMP:
			return ilLoadBmp(FileName);
		#endif

		#ifndef IL_NO_GIF
		case IL_GIF:
			return ilLoadGif(FileName);
		#endif

		#ifndef IL_NO_HDR
		case IL_HDR:
			return ilLoadHdr(FileName);
		#endif

		#ifndef IL_NO_CUT
		case IL_CUT:
			return ilLoadCut(FileName);
		#endif

		#ifndef IL_NO_DOOM
		case IL_DOOM:
			return ilLoadDoom(FileName);
		case IL_DOOM_FLAT:
			return ilLoadDoomFlat(FileName);
		#endif

		#ifndef IL_NO_ICO
		case IL_ICO:
			return ilLoadIcon(FileName);
		#endif

		#ifndef IL_NO_LIF
		case IL_LIF:
			return ilLoadLif(FileName);
		#endif

		#ifndef IL_NO_MDL
		case IL_MDL:
			return ilLoadMdl(FileName);
		#endif

		#ifndef IL_NO_MNG
		case IL_MNG:
			return ilLoadMng(FileName);
		#endif

		#ifndef IL_NO_PCD
		case IL_PCD:
			return IL_FALSE;//ilLoadPcd(FileName);
		#endif

		#ifndef IL_NO_PCX
		case IL_PCX:
			return ilLoadPcx(FileName);
		#endif

		#ifndef IL_NO_PIC
		case IL_PIC:
			return ilLoadPic(FileName);
		#endif

		#ifndef IL_NO_PIX
		case IL_PIX:
			return ilLoadPix(FileName);
		#endif

		#ifndef IL_NO_PNM
		case IL_PNM:
			return ilLoadPnm(FileName);
		#endif

		#ifndef IL_NO_PSD
		case IL_PSD:
			return ilLoadPsd(FileName);
		#endif

		#ifndef IL_NO_PSP
		case IL_PSP:
			return ilLoadPsp(FileName);
		#endif

		#ifndef IL_NO_PXR
		case IL_PXR:
			return ilLoadPxr(FileName);
		#endif

		#ifndef IL_NO_RAW
		case IL_RAW:
			return ilLoadRaw(FileName);
		#endif

		#ifndef IL_NO_SGI
		case IL_SGI:
			return ilLoadSgi(FileName);
		#endif

		#ifndef IL_NO_TIF
		case IL_TIF:
			#ifndef _UNICODE
				return ilLoadTiff(FileName);
			#else
				wcstombs(AnsiName, FileName, 512);
				//WideCharToMultiByte(CP_ACP, 0, FileName, -1, AnsiName, 512, NULL, NULL);
				return ilLoadTiff(AnsiName);
			#endif//_UNICODE
		#endif

		#ifndef IL_NO_WAL
		case IL_WAL:
			return ilLoadWal(FileName);
		#endif

		#ifndef IL_NO_XPM
		case IL_XPM:
			return ilLoadXpm(FileName);
		#endif
	}

	ilSetError(IL_INVALID_ENUM);
	return IL_FALSE;
}


ILboolean ILAPIENTRY ilLoadF(ILenum Type, ILHANDLE File)
{
	if (File == NULL) {
		ilSetError(IL_INVALID_PARAM);
		return IL_FALSE;
	}

	if (Type == IL_TYPE_UNKNOWN)
		Type = ilDetermineTypeF(File);
	
	switch (Type)
	{
		case IL_TYPE_UNKNOWN:
			return IL_FALSE;

		#ifndef IL_NO_TGA
		case IL_TGA:
			return ilLoadTargaF(File);
		#endif

		#ifndef IL_NO_JPG
			#ifndef IL_USE_IJL
			case IL_JPG:
				return ilLoadJpegF(File);
			#endif
		#endif

		#ifndef IL_NO_DDS
		case IL_DDS:
			return ilLoadDdsF(File);
		#endif

		#ifndef IL_NO_PNG
		case IL_PNG:
			return ilLoadPngF(File);
		#endif

		#ifndef IL_NO_BMP
		case IL_BMP:
			return ilLoadBmpF(File);
		#endif

		#ifndef IL_NO_GIF
		case IL_GIF:
			return ilLoadGifF(File);
		#endif

		#ifndef IL_NO_HDR
		case IL_HDR:
			return ilLoadHdrF(File);
		#endif

		#ifndef IL_NO_CUT
		case IL_CUT:
			return ilLoadCutF(File);
		#endif

		#ifndef IL_NO_DOOM
		case IL_DOOM:
			return ilLoadDoomF(File);
		case IL_DOOM_FLAT:
			return ilLoadDoomFlatF(File);
		#endif

		#ifndef IL_NO_ICO
		case IL_ICO:
			return ilLoadIconF(File);
		#endif

		#ifndef IL_NO_LIF
		case IL_LIF:
			return ilLoadLifF(File);
		#endif

		#ifndef IL_NO_MDL
		case IL_MDL:
			return ilLoadMdlF(File);
		#endif

		#ifndef IL_NO_MNG
		case IL_MNG:
			return ilLoadMngF(File);
		#endif

		#ifndef IL_NO_PCD
		case IL_PCD:
			return IL_FALSE;//return ilLoadPcdF(File);
		#endif

		#ifndef IL_NO_PCX
		case IL_PCX:
			return ilLoadPcxF(File);
		#endif

		#ifndef IL_NO_PIC
		case IL_PIC:
			return ilLoadPicF(File);
		#endif

		#ifndef IL_NO_PIX
		case IL_PIX:
			return ilLoadPixF(File);
		#endif

		#ifndef IL_NO_PNM
		case IL_PNM:
			return ilLoadPnmF(File);
		#endif

		#ifndef IL_NO_PSD
		case IL_PSD:
			return ilLoadPsdF(File);
		#endif

		#ifndef IL_NO_PSP
		case IL_PSP:
			return ilLoadPspF(File);
		#endif

		#ifndef IL_NO_PXR
		case IL_PXR:
			return ilLoadPxrF(File);
		#endif

		#ifndef IL_NO_RAW
		case IL_RAW:
			return ilLoadRawF(File);
		#endif

		#ifndef IL_NO_SGI
		case IL_SGI:
			return ilLoadSgiF(File);
		#endif

		#ifndef IL_NO_TIF
		case IL_TIF:
			return ilLoadTiffF(File);
		#endif

		#ifndef IL_NO_WAL
		case IL_WAL:
			return ilLoadWalF(File);
		#endif

		#ifndef IL_NO_XPM
		case IL_XPM:
			return ilLoadXpmF(File);
		#endif
	}

	ilSetError(IL_INVALID_ENUM);
	return IL_FALSE;
}


ILboolean ILAPIENTRY ilLoadL(ILenum Type, const ILvoid *Lump, ILuint Size) {
	if (Lump == NULL || Size == 0) {
		ilSetError(IL_INVALID_PARAM);
		return IL_FALSE;
	}

	if (Type == IL_TYPE_UNKNOWN)
		Type = ilDetermineTypeL(Lump, Size);
	
	switch (Type)
	{
		case IL_TYPE_UNKNOWN:
			return IL_FALSE;

		#ifndef IL_NO_TGA
		case IL_TGA:
			return ilLoadTargaL(Lump, Size);
		#endif

		#ifndef IL_NO_JPG
		case IL_JPG:
			return ilLoadJpegL(Lump, Size);
		#endif

		#ifndef IL_NO_DDS
		case IL_DDS:
			return ilLoadDdsL(Lump, Size);
		#endif

		#ifndef IL_NO_PNG
		case IL_PNG:
			return ilLoadPngL(Lump, Size);
		#endif

		#ifndef IL_NO_BMP
		case IL_BMP:
			return ilLoadBmpL(Lump, Size);
		#endif

		#ifndef IL_NO_GIF
		case IL_GIF:
			return ilLoadGifL(Lump, Size);
		#endif

		#ifndef IL_NO_HDR
		case IL_HDR:
			return ilLoadHdrL(Lump, Size);
		#endif

		#ifndef IL_NO_CUT
		case IL_CUT:
			return ilLoadCutL(Lump, Size);
		#endif

		#ifndef IL_NO_DOOM
		case IL_DOOM:
			return ilLoadDoomL(Lump, Size);
		case IL_DOOM_FLAT:
			return ilLoadDoomFlatL(Lump, Size);
		#endif

		#ifndef IL_NO_ICO
		case IL_ICO:
			return ilLoadIconL(Lump, Size);
		#endif

		#ifndef IL_NO_LIF
		case IL_LIF:
			return ilLoadLifL(Lump, Size);
		#endif

		#ifndef IL_NO_MDL
		case IL_MDL:
			return ilLoadMdlL(Lump, Size);
		#endif

		#ifndef IL_NO_MNG
		case IL_MNG:
			return ilLoadMngL(Lump, Size);
		#endif

		#ifndef IL_NO_PCD
		case IL_PCD:
			return IL_FALSE;//return ilLoadPcdL(Lump, Size);
		#endif

		#ifndef IL_NO_PCX
		case IL_PCX:
			return ilLoadPcxL(Lump, Size);
		#endif

		#ifndef IL_NO_PIC
		case IL_PIC:
			return ilLoadPicL(Lump, Size);
		#endif

		#ifndef IL_NO_PIX
		case IL_PIX:
			return ilLoadPixL(Lump, Size);
		#endif

		#ifndef IL_NO_PNM
		case IL_PNM:
			return ilLoadPnmL(Lump, Size);
		#endif

		#ifndef IL_NO_PSD
		case IL_PSD:
			return ilLoadPsdL(Lump, Size);
		#endif

		#ifndef IL_NO_PSP
		case IL_PSP:
			return ilLoadPspL(Lump, Size);
		#endif

		#ifndef IL_NO_PXR
		case IL_PXR:
			return ilLoadPxrL(Lump, Size);
		#endif

		#ifndef IL_NO_RAW
		case IL_RAW:
			return ilLoadRawL(Lump, Size);
		#endif

		#ifndef IL_NO_SGI
		case IL_SGI:
			return ilLoadSgiL(Lump, Size);
		#endif

		#ifndef IL_NO_TIF
		case IL_TIF:
			return ilLoadTiffL(Lump, Size);
		#endif

		#ifndef IL_NO_WAL
		case IL_WAL:
			return ilLoadWalL(Lump, Size);
		#endif

		#ifndef IL_NO_XPM
		case IL_XPM:
			return ilLoadXpmL(Lump, Size);
		#endif
	}

	ilSetError(IL_INVALID_ENUM);
	return IL_FALSE;
}


//! Attempts to load an image with various different methods before failing - very generic.
ILboolean ILAPIENTRY ilLoadImage(const ILstring FileName)
{
	ILstring	Ext = iGetExtension(FileName);
	ILenum		Type;

	if (iCurImage == NULL) {
		ilSetError(IL_ILLEGAL_OPERATION);
		return IL_FALSE;
	}

#ifndef _UNICODE
	if (FileName == NULL || strlen(FileName) < 1) {
#else
	if (FileName == NULL || wcslen(FileName) < 1) {
#endif//_UNICODE
		ilSetError(IL_INVALID_PARAM);
		return IL_FALSE;
	}

	// Try registered procedures first (so users can override default lib functions).
	if (Ext) {
		if (iRegisterLoad(FileName))
			return IL_TRUE;

		#ifndef IL_NO_TGA
		if (!iStrCmp(Ext, IL_TEXT("tga")) || !iStrCmp(Ext, IL_TEXT("vda")) ||
			!iStrCmp(Ext, IL_TEXT("icb")) || !iStrCmp(Ext, IL_TEXT("vst"))) {
			return ilLoadTarga(FileName);
		}
		#endif

		#ifndef IL_NO_JPG
		if (!iStrCmp(Ext, IL_TEXT("jpg")) || !iStrCmp(Ext, IL_TEXT("jpe")) ||
			!iStrCmp(Ext, IL_TEXT("jpeg"))) {
			return ilLoadJpeg(FileName);
		}
		#endif

		#ifndef IL_NO_DDS
		if (!iStrCmp(Ext, IL_TEXT("dds"))) {
			return ilLoadDds(FileName);
		}
		#endif

		#ifndef IL_NO_PNG
		if (!iStrCmp(Ext, IL_TEXT("png"))) {
			return ilLoadPng(FileName);
		}
		#endif

		#ifndef IL_NO_BMP
		if (!iStrCmp(Ext, IL_TEXT("bmp")) || !iStrCmp(Ext, IL_TEXT("dib"))) {
			return ilLoadBmp(FileName);
		}
		#endif

		#ifndef IL_NO_GIF
		if (!iStrCmp(Ext, IL_TEXT("gif"))) {
			return ilLoadGif(FileName);
		}
		#endif

		#ifndef IL_NO_HDR
		if (!iStrCmp(Ext, IL_TEXT("hdr"))) {
			return ilLoadHdr(FileName);
		}
		#endif

		#ifndef IL_NO_CUT
		if (!iStrCmp(Ext, IL_TEXT("cut"))) {
			return ilLoadCut(FileName);
		}
		#endif

		#ifndef IL_NO_DCX
		if (!iStrCmp(Ext, IL_TEXT("dcx"))) {
			return ilLoadDcx(FileName);
		}
		#endif

		#ifndef IL_NO_ICO
		if (!iStrCmp(Ext, IL_TEXT("ico")) || !iStrCmp(Ext, IL_TEXT("cur"))) {
			return ilLoadIcon(FileName);
		}
		#endif

		#ifndef IL_NO_LIF
		if (!iStrCmp(Ext, IL_TEXT("lif"))) {
			return ilLoadLif(FileName);
		}
		#endif

		#ifndef IL_NO_MDL
		if (!iStrCmp(Ext, IL_TEXT("mdl"))) {
			return ilLoadMdl(FileName);
		}
		#endif

		#ifndef IL_NO_MNG
		if (!iStrCmp(Ext, IL_TEXT("mng")) || !iStrCmp(Ext, IL_TEXT("jng"))) {
			return ilLoadMng(FileName);
		}
		#endif

		#ifndef IL_NO_PCD
		if (!iStrCmp(Ext, IL_TEXT("pcd"))) {
			return IL_FALSE;//return ilLoadPcd(FileName);
		}
		#endif

		#ifndef IL_NO_PCX
		if (!iStrCmp(Ext, IL_TEXT("pcx"))) {
			return ilLoadPcx(FileName);
		}
		#endif

		#ifndef IL_NO_PIC
		if (!iStrCmp(Ext, IL_TEXT("pic"))) {
			return ilLoadPic(FileName);
		}
		#endif

		#ifndef IL_NO_PIX
		if (!iStrCmp(Ext, IL_TEXT("pix"))) {
			return ilLoadPix(FileName);
		}
		#endif

		#ifndef IL_NO_PNM
		if (!iStrCmp(Ext, IL_TEXT("pbm"))) {
			return ilLoadPnm(FileName);
		}
		if (!iStrCmp(Ext, IL_TEXT("pgm"))) {
			return ilLoadPnm(FileName);
		}
		if (!iStrCmp(Ext, IL_TEXT("pnm"))) {
			return ilLoadPnm(FileName);
		}
		if (!iStrCmp(Ext, IL_TEXT("ppm"))) {
			return ilLoadPnm(FileName);
		}
		#endif

		#ifndef IL_NO_PSD
		if (!iStrCmp(Ext, IL_TEXT("psd")) || !iStrCmp(Ext, IL_TEXT("pdd"))) {
			return ilLoadPsd(FileName);
		}
		#endif

		#ifndef IL_NO_PSP
		if (!iStrCmp(Ext, IL_TEXT("psp"))) {
			return ilLoadPsp(FileName);
		}
		#endif

		#ifndef IL_NO_PXR
		if (!iStrCmp(Ext, IL_TEXT("pxr"))) {
			return ilLoadPxr(FileName);
		}
		#endif

		#ifndef IL_NO_SGI
		if (!iStrCmp(Ext, IL_TEXT("sgi")) || !iStrCmp(Ext, IL_TEXT("bw")) ||
			!iStrCmp(Ext, IL_TEXT("rgb")) || !iStrCmp(Ext, IL_TEXT("rgba"))) {
			return ilLoadSgi(FileName);
		}
		#endif

		#ifndef IL_NO_TIF
		if (!iStrCmp(Ext, IL_TEXT("tif")) || !iStrCmp(Ext, IL_TEXT("tiff"))) {
			return ilLoadTiff(FileName);
		}
		#endif

		#ifndef IL_NO_WAL
		if (!iStrCmp(Ext, IL_TEXT("wal"))) {
			return ilLoadWal(FileName);
		}
		#endif

		#ifndef IL_NO_XPM
		if (!iStrCmp(Ext, IL_TEXT("xpm"))) {
			return ilLoadXpm(FileName);
		}
		#endif
	}

	// As a last-ditch effort, try to identify the image
	Type = ilDetermineType(FileName);
	if (Type == IL_TYPE_UNKNOWN)
		return IL_FALSE;
	return ilLoad(Type, FileName);
}


ILboolean ILAPIENTRY ilSave(ILenum Type, ILstring FileName)
{
	switch (Type)
	{
		case IL_TYPE_UNKNOWN:
			return ilSaveImage(FileName);

		#ifndef IL_NO_BMP
		case IL_BMP:
			return ilSaveBmp(FileName);
		#endif

		#ifndef IL_NO_CHEAD
		case IL_CHEAD:
			return ilSaveCHeader(FileName, "IL_IMAGE");
		#endif

		#ifndef IL_NO_JPG
		case IL_JPG:
			return ilSaveJpeg(FileName);
		#endif

		#ifndef IL_NO_PCX
		case IL_PCX:
			return ilSavePcx(FileName);
		#endif

		#ifndef IL_NO_PNG
		case IL_PNG:
			return ilSavePng(FileName);
		#endif

		#ifndef IL_NO_PNM
		case IL_PNM:
			return ilSavePnm(FileName);
		#endif

		#ifndef IL_NO_PSD
		case IL_PSD:
			return ilSavePsd(FileName);
		#endif

		#ifndef IL_NO_RAW
		case IL_RAW:
			return ilSaveRaw(FileName);
		#endif

		#ifndef IL_NO_SGI
		case IL_SGI:
			return ilSaveSgi(FileName);
		#endif

		#ifndef IL_NO_TGA
		case IL_TGA:
			return ilSaveTarga(FileName);
		#endif

		#ifndef IL_NO_TIF
		case IL_TIF:
			return ilSaveTiff(FileName);
		#endif

		case IL_JASC_PAL:
			return ilSaveJascPal(FileName);
	}

	ilSetError(IL_INVALID_ENUM);
	return IL_FALSE;
}


ILuint ILAPIENTRY ilSaveF(ILenum Type, ILHANDLE File)
{
	ILboolean Ret;

	if (File == NULL) {
		ilSetError(IL_INVALID_PARAM);
		return 0;
	}

	switch (Type)
	{
		#ifndef IL_NO_BMP
		case IL_BMP:
			Ret = ilSaveBmpF(File);
			break;
		#endif

		#ifndef IL_NO_JPG
			#ifndef IL_USE_IJL
			case IL_JPG:
				Ret = ilSaveJpegF(File);
				break;
			#endif
		#endif

		#ifndef IL_NO_PNM
		case IL_PNM:
			Ret = ilSavePnmF(File);
			break;
		#endif

		#ifndef IL_NO_PNG
		case IL_PNG:
			Ret = ilSavePngF(File);
			break;	
		#endif

		#ifndef IL_NO_PSD
		case IL_PSD:
			Ret = ilSavePsdF(File);
			break;
		#endif

		#ifndef IL_NO_RAW
		case IL_RAW:
			Ret = ilSaveRawF(File);
			break;
		#endif

		#ifndef IL_NO_SGI
		case IL_SGI:
			Ret = ilSaveSgiF(File);
			break;
		#endif

		#ifndef IL_NO_TGA
		case IL_TGA:
			Ret = ilSaveTargaF(File);
			break;
		#endif

		/*#ifndef IL_NO_TIF
		case IL_TIF:
			Ret = ilSaveTiffF(File);
			break;
		#endif*/

		default:
			ilSetError(IL_INVALID_ENUM);
			return 0;
	}

	if (Ret == IL_FALSE)
		return 0;

	return itell();
}
示例#12
0
Texture TextureLoader::loadTexture(const aiScene* scene, unsigned int index)
{
	ILboolean success;

	Texture texture;

	std::string filename;
	int texIndex = 0;
	aiString path;	// filename

	aiReturn texFound = scene->mMaterials[index]->GetTexture(aiTextureType_DIFFUSE, texIndex, &path);
	if(texFound == AI_SUCCESS)
	{
		filename = path.data;
		filename = filename.substr(filename.find_last_of("/\\") +1);

		//save filename for texture
		texture.setFilename(filename);

		printf("Filename is: %s\n", filename.c_str());
	}

	int numTextures = 1;

	/* create and fill DevIL texture id */
	ILuint* imageId = new ILuint[numTextures];
	ilGenImages(numTextures, &imageId[0]);

	/* create and fill GL texture id */
	GLuint* textureId = new GLuint[numTextures];
	glGenTextures(numTextures, &textureId[0]); /* Texture name generation */

	//save generated textureId for texture
	texture.setTextureId(textureId[0]);

	//Binding of DevIL image name
	ilBindImage(imageId[0]);
	ilEnable(IL_ORIGIN_SET);
	ilOriginFunc(IL_ORIGIN_LOWER_LEFT);

	std::string fullPath = std::string("Resources/3dModels/" + filename);

	printf("Texture path is: %s\n", fullPath.c_str());

	success = ilLoad(IL_TYPE_UNKNOWN, fullPath.c_str());

	if (success)
	{
		// Convert image to RGBA
		ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);

		// Create and load textures to OpenGL
		glBindTexture(GL_TEXTURE_2D, textureId[0]);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ilGetInteger(IL_IMAGE_WIDTH),
				ilGetInteger(IL_IMAGE_HEIGHT), 0, GL_RGBA, GL_UNSIGNED_BYTE,
				ilGetData());

		/* Unbind texture state after loading. */
		glBindTexture(GL_TEXTURE_2D, 0);
	}
	else
	{
		printf("Couldn't load Image: %u, error code: %x\n", textureId[0], ilGetError());
	}

	// Because we have already copied image data into texture data
	// we can release memory used by image.
	ilDeleteImages(numTextures, imageId);

	//Cleanup
	delete[] imageId;
	delete[] textureId;

	int code;
	if( (code = glGetError()) != GL_NO_ERROR )
	{
		printf("OGL ERROR: %x\n", code);
	}

	if( (code = ilGetError()) != IL_NO_ERROR )
	{
		printf("IL ERROR: %x\n", code);
	}

	printf("Successfully loaded texture at %s with handle ID: %u\n", fullPath.c_str(), texture.getTextureId());

	//return the texture Object;
	return texture;
}