void CDevILCodec::DecodeFromFile(const nstring & filename, CImage *image,
		CImageFormats::NovaPixelFormats format)
{
	ILuint image_id;
	// Generate the main image name to use.
	ilGenImages(1, &image_id);

	// Bind this image name.
	ilBindImage(image_id);

	if(!ilLoadImage(filename.c_str()))
	{
		ILenum Error = 0;
		if((Error = ilGetError()) != NULL)
		{
			nstring str("CDevILCodec::DecodeFromFile(): Can not load image file - ");
			str.append(iluErrorString(Error));
			throw NOVA_EXP(str.c_str(), BAD_OPERATION);
		}
	}

	image->GetImageSource().mHeight = ilGetInteger(IL_IMAGE_HEIGHT);
	image->GetImageSource().mWidth = ilGetInteger(IL_IMAGE_WIDTH);
	image->GetImageSource().mDepth = ilGetInteger(IL_IMAGE_DEPTH);

	//if (ilGetInteger(IL_IMAGE_ORIGIN) == IL_ORIGIN_LOWER_LEFT)
	//	iluFlipImage();

//	this->size = ilGetInteger(IL_IMAGE_SIZE_OF_DATA);
	if(format == CImageFormats::NF_DEFAULT)
	{
		CDevILFormats inf;
		inf.SetFormat(ilGetInteger(IL_IMAGE_FORMAT));
		format = inf.GetExFormat();
	}

	CDevILFormats informat;
	informat.SetExFormat(format);
	image->GetImageSource().mPixelFormat = format;

	size_t _size = image->GetWidth() * image->GetHeight() * image->GetDepth() * ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);
	image->GetBits().FreeBuffer();
	image->GetBits().AllocBuffer(_size);

	ilCopyPixels(0, 0, 0, image->GetWidth(), image->GetHeight(), 
		image->GetDepth(), informat.GetFormat(), IL_UNSIGNED_BYTE, image->GetBits().GetBegin());

	ilDeleteImages(1, &image_id);

	ILenum Error = 0;
	if((Error = ilGetError()) != NULL)
	{
		nstring str("CDevILCodec::DecodeFromFile(): Can not load image file ");
		str.append(filename);
		str.append(", reason: ");
		str.append(iluErrorString(Error));
		throw NOVA_EXP(str.c_str(), BAD_OPERATION);
	}
}
示例#2
0
	void ClearDevILErrors()
	{
		ILenum error = ilGetError();
		while (error != IL_NO_ERROR)
		{
			error = ilGetError();
		}
	}
示例#3
0
// Function load a image, turn it into a texture, and return the texture ID as a GLuint for use
GLuint ModelObject::loadImageTex(const char* theFileName) {
    ILuint      imageID;                        // Create an image ID as a ULuint
    ILboolean   success;                        // Create a flag to keep track of success/failure
    ILenum      error;				// Create a flag to keep track of the IL error state
    ilGenImages(1, &imageID);                   // Generate the image ID
    ilBindImage(imageID); 			// Bind the image
    success = ilLoadImage(theFileName);         // Load the image file
    // If we managed to load the image, then we can start to do things with it...
    if (success) {
        // If the image is flipped (i.e. upside-down and mirrored, flip it the right way up!)
        ILinfo ImageInfo;
        iluGetImageInfo(&ImageInfo);
        if (ImageInfo.Origin == IL_ORIGIN_UPPER_LEFT) {
            iluFlipImage();
        }
        // Convert the image into a suitable format to work with
        // NOTE: If your image contains alpha channel you can replace IL_RGB with IL_RGBA
        success = ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
        // Quit out if we failed the conversion
        if (!success) {
            error = ilGetError();
            std::cout << "Image conversion failed - IL reports error: " << error << " - " << iluErrorString(error) << std::endl;
            exit(-1);
        }
        // Generate a new texture
        glGenTextures(1, &textureID);
        // Bind the texture to a name
        glBindTexture(GL_TEXTURE_2D, textureID);
        // Set texture clamping method
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
        // Set texture interpolation method to use linear interpolation (no MIPMAPS)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        // Specify the texture specification
        glTexImage2D(GL_TEXTURE_2D, 				// Type of texture
                     0,				// Pyramid level (for mip-mapping) - 0 is the top level
                     ilGetInteger(IL_IMAGE_BPP),	// Image colour depth
                     ilGetInteger(IL_IMAGE_WIDTH),	// Image width
                     ilGetInteger(IL_IMAGE_HEIGHT),	// Image height
                     0,				// Border width in pixels (can either be 1 or 0)
                     ilGetInteger(IL_IMAGE_FORMAT),	// Image format (i.e. RGB, RGBA, BGR etc.)
                     GL_UNSIGNED_BYTE,		// Image data type
                     ilGetData());			// The actual image data itself
        //glGenerateMipmap(GL_TEXTURE_2D); // Note: This requires OpenGL 3.0 or higher
    } else { // If we failed to open the image file in the first place...
        error = ilGetError();
        std::cout << "Image load failed - IL reports error: " << error << " - " << iluErrorString(error) << std::endl;
        exit(-1);
    }

    ilDeleteImages(1, &imageID); // Because we have already copied image data into texture data we can release memory used by image.
    std::cout << "Texture creation successful." << std::endl;
    return textureID; // Return the GLuint to the texture so you can use it!
}
示例#4
0
	void ImageData::create(int width, int height, void * data)
	{
		Lock lock(devilMutex); //automatically lock and unlock
		ILuint image;

		//create the image
		ilGenImages(1, &image);

		//bind it
		ilBindImage(image);

		while(ilGetError() != IL_NO_ERROR);
		
		//create and populate the image
		bool success = (ilTexImage(width, height, 1, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data) == IL_TRUE);

		ILenum err = ilGetError();
		while(ilGetError() != IL_NO_ERROR);

		if (!success)
		{
			ilDeleteImages(1, &image);

			if (err != IL_NO_ERROR)
			{
				switch (err)
				{
					case IL_ILLEGAL_OPERATION:
						throw love::Exception("Illegal operation");
					case IL_INVALID_PARAM:
						throw love::Exception("Invalid parameters");
					case IL_OUT_OF_MEMORY:
						throw love::Exception("Out of memory");
					default:
						throw love::Exception("Unknown error (%d)", (int) err);
				}
			}

			throw love::Exception("Could not decode image data.");
		}

		try
		{
			this->data = new unsigned char[width*height*bpp];
		}
		catch (std::bad_alloc)
		{
			ilDeleteImages(1, &image);
			throw love::Exception("Out of memory");
		}

		memcpy(this->data, ilGetData(), width*height*bpp);

		ilDeleteImages(1, &image);
	}
示例#5
0
文件: ILUTest.cpp 项目: AMDmi3/DevIL
void ILUTest::tearDown()
{
  const ILenum lResult = ilGetError();

  while (ilGetError() != IL_NO_ERROR) {;}

  ilResetMemory();
  CPPUNIT_ASSERT(ilGetError() == IL_NO_ERROR);

  CPPUNIT_ASSERT_MESSAGE("Received Error from ilGetError", lResult == IL_NO_ERROR);
}
示例#6
0
	void HandleDevILErrors(const String& errorPrefix="")
	{
		ILenum error = ilGetError();
		if (error != IL_NO_ERROR)
		{
			sysLog.Log("DevIL errors loading: " + errorPrefix);
			do 
			{
				sysLog.Log(iluErrorString(error));
			} while ((error = ilGetError()));
		}
	}
示例#7
0
void HandleDevILErrors ()
{
	ILenum error = ilGetError ();
	
	if (error != IL_NO_ERROR) {
		do {
			printf ("\n\n%s\n", iluErrorString (error));	
		} while ((error = ilGetError ()));

		exit (1);
	}
}
示例#8
0
static void handleDevilErrors(const char *fname){
    char wd[PATH_MAX];
    
    ILenum error = ilGetError ();
    if (error != IL_NO_ERROR) {
        getcwd(wd,PATH_MAX);
        printf("Devil errors, CWD: %s\n",wd);
        do {
            printf ("- %s\n", iluErrorString (error));	
        } while ((error = ilGetError ()));
        printf("cannot load image: %s\n",fname);
    }
}
bool CSprite::LoadTexture(char* filename)
{
	Engine()->PushContext();

	// TODO: Move this into a separate class

	if ( !glIsEnabled( GL_TEXTURE_RECTANGLE_NV ) ) 
	{
		m_iTexture = ilutGLLoadImage( filename );

		if (ilGetError() != IL_NO_ERROR)
			return false;

		m_iWidth = ilGetInteger( IL_IMAGE_WIDTH );
		m_iHeight = ilGetInteger( IL_IMAGE_HEIGHT );

	}
	else
	{
		ILuint texid;

		ilGenImages(1, &texid);
		ilBindImage(texid);
		ilLoadImage( filename );

		ILenum Error = ilGetError();

		if ( Error != IL_NO_ERROR )
		{
			sqstd_printcallstack( Sqrat::DefaultVM::Get() );
			std::stringstream st; st << "DevIL Error: " << iluErrorString(Error) << std::endl;
			Engine()->Debug( st.str() );
			return false;
		}

		m_iWidth = ilGetInteger( IL_IMAGE_WIDTH );
		m_iHeight = ilGetInteger( IL_IMAGE_HEIGHT );

		ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
		glGenTextures(1, &m_iTexture);
		glBindTexture(GL_TEXTURE_RECTANGLE_NV, m_iTexture);
		glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, ilGetInteger(IL_IMAGE_BPP), m_iWidth,
		 m_iHeight, 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE,
		 ilGetData());
	}

	//Engine()->PopContext();
	return true;
}
示例#10
0
	Texture TextureHandler::getTexture(const string &path, const string &def, GLenum format)
	{
		if(hasTexture(path))
			return existingTextures[path];

		Texture ret(path);
		ILuint imageID;
		ILboolean success;
		ILenum error;
		ilGenImages(1, &imageID);
		ilBindImage(imageID);
		success = ilLoadImage((const ILstring)path.c_str());

		if(!success)
		{
			error = ilGetError();
			std::cout << "Image load failed " + path + " - IL reports error: " << error << " - " << iluErrorString(error) << std::endl;
			success = ilLoadImage((const ILstring)def.c_str());
			if(!success)
			{
				error = ilGetError();
				std::cout << "Image load failed " + def + " - IL reports error: " << error << " - " << iluErrorString(error) << std::endl;
				exit(-1);
			}
		}

		ILinfo ImageInfo;
		iluGetImageInfo(&ImageInfo);
		if(ImageInfo.Origin == IL_ORIGIN_UPPER_LEFT)
			iluFlipImage();

		GLenum type;
		success = convertAndGetType(format, type);

		if(!success)
		{
			error = ilGetError();
			cout << "Image conversion failed - IL reports error: " << error << " - " << iluErrorString(error) << endl;
			exit(-1);
		}
		ret.generate();
		ret.bind();
		ret.texImage(0, format, vec3(ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0), ilGetInteger(IL_IMAGE_FORMAT), type, ilGetData());

		ilDeleteImages(1, &imageID);

		existingTextures[path] = ret;
		return ret;
	}
示例#11
0
float* getImage(const wchar_t* fileName, int* height, int* width, int* imgFormat)
{
	ilInit();
	ILuint img;
	ilGenImages(1, &img);
	ilBindImage(1);
	ilLoadImage(fileName);
	ILenum error;
	error = ilGetError();

	*height = ilGetInteger(IL_IMAGE_HEIGHT);
	*width = ilGetInteger(IL_IMAGE_WIDTH);
	*imgFormat = ilGetInteger(IL_IMAGE_FORMAT);

	ILubyte* imgData = ilGetData();

	float* texImg = new float[*height * *width * 3];
	for(int i = 0; i < *height * *width * 3; i++)
	{
		texImg[i] = imgData[i] / 255.0f;
	}
	
	ilDeleteImages(1, &img);
	std::cout << "Textures loaded!" << std::endl;

	return texImg;
}
示例#12
0
// Image saver...
bit DevilSave(cstrconst filename,nat32 width,nat32 height,nat32 format,nat32 type,void * data,bit overwrite)
{
 unsigned int handle;
 ilGenImages(1,(unsigned int *)&handle); 
 ilBindImage(handle);
 ilEnable(0x0600);
 ilOriginFunc(0x0601);

 if (overwrite) ilEnable(DEVIL_FILE_SQUISH);
           else ilDisable(DEVIL_FILE_SQUISH);
  
 int num;
 switch (format)
 {
  case DEVIL_FORM_RGB: num = 3; break;
  case DEVIL_FORM_RGBA: num = 4; break;
  default: num =  1; break;
 }
 ilTexImage(width,height,1,num,format,type,data);

 ilSaveImage(filename);
 if (ilGetError())
 {
  ilDeleteImages(1,(unsigned int *)&handle);
  return false;
 }
 else
 { 
  ilDeleteImages(1,(unsigned int *)&handle);
  return true;
 }
}
示例#13
0
int Sprite::LoadImage(char *filename)
{
	// IL image ID
	ILuint ImgId = 0;

	// Generate the main image name to use
	ilGenImages(1, &ImgId);
	// Bind this image name
	ilBindImage(ImgId);
	// Loads the image specified by File into the ImgId image
	if (!ilLoadImage(filename))
	{
		ILenum err = ilGetError();
		printf("An error occured while loading %s: %d (%s)\n", filename, err, iluErrorString(err));
		return 0;
	}
	
	// Get image width and height
	width = (int) ilGetInteger(IL_IMAGE_WIDTH);
	height = (int) ilGetInteger(IL_IMAGE_HEIGHT);
	bpp = (int) ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);

	// Enable texturing
	glEnable(GL_TEXTURE_2D);

	// Goes through all steps of sending the image to OpenGL
	TexName = ilutGLBindTexImage();

	// We're done with our image, so we go ahead and delete it
	ilDeleteImages(1, &ImgId);

	isDefined = true;

	return 1;
}
示例#14
0
bool nTextureManager::saveTexture(nTexture *tex, string name) {
    if(!glIsTexture(tex->tex)) {
        return false;
    }
    mutex->lock();
    unsigned char *dat = new unsigned char[3 * (unsigned int)(tex->size.x * tex->size.y)];
    glBindTexture(GL_TEXTURE_2D, tex->tex);
    glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, dat);
    ILuint img;
    ilGenImages(1, &img);
    ilBindImage(img);
    iluScale(tex->size.x, tex->size.y, 1);
    ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
    bool t = ilTexImage(tex->size.x, tex->size.y, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, dat);
    ILuint error = ilGetError();
    GLuint glError = glGetError();
    if(error || !t || glError) {
        nGine::instance()->getLogger()->addDebugLog("Error while saving file : " + nLogger::numToString((int)error) + "/" + nLogger::numToString((int)glError));
        mutex->unlock();
        return false;
    }
    bool a = ilSaveImage((nGine::instance()->appPath() + name).c_str());
    mutex->unlock();
    return a;
}
示例#15
0
文件: texture.cpp 项目: leezl/cse680
void Texture::checkErrors() {
    ILenum Error;
    std::cout<<"Checking Errors..."<<std::endl;
	while ((Error = ilGetError()) != IL_NO_ERROR) { 
	    printf("%d: %s/n", Error, iluErrorString(Error)); 
	} 
}
示例#16
0
void CDevILCodec::CodeToFile(const nstring & filename, const CImage &image)
{
	ILuint imageid;
	CDevILFormats informat;
	informat.SetExFormat(image.GetPixelFormat());
	// Generate the main image name to use.
	ilGenImages(1, &imageid);

	// Bind this image name.
	ilBindImage(imageid);

	ilTexImage(image.GetWidth(), image.GetHeight(), image.GetDepth(), informat.GetInternalChannels(),
		informat.GetFormat(), IL_UNSIGNED_BYTE, image.GetBitsPtr());

	ilSaveImage(filename.c_str());

	ilDeleteImages(1, &imageid);

	ILenum Error = 0;
	if((Error = ilGetError()) != NULL)
	{
		nstring str("CDevILCodec::CodeToFile: ");
		str.append(iluErrorString(Error));
		throw NOVA_EXP(str.c_str(), BAD_OPERATION);
	}
}
示例#17
0
文件: Texture2D.cpp 项目: Kaaml/Vxy
bool Texture2D::LoadWithFile( const std::string &ImageName )
{
	//wczytanie obrazka
	ILuint image;
	ilGenImages( 1, &image );
	ilBindImage( image );
	ilLoadImage( ImageName.c_str() );
	ILenum Error = ilGetError();
	if( Error != IL_NO_ERROR )
	{
		std::cerr << "ERROR: Wczytanie tekstury: "<< "nie powiodlo sie, plik: " << ImageName << " nie zostal wczytany" << std::endl;
		return false;
	}
	int width, height, depth;
	ILenum type, format;
	width = ilGetInteger(IL_IMAGE_WIDTH);
	height = ilGetInteger(IL_IMAGE_HEIGHT);
	depth = ilGetInteger( IL_IMAGE_DEPTH );
	type = ilGetInteger( IL_IMAGE_TYPE ); 
	format = ilGetInteger( IL_IMAGE_FORMAT );
	ILubyte *pixmap = ilGetData();
	glBindTexture( GL_TEXTURE_2D, m_BufferHandle );
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, format, type, pixmap );
	UnBind();
	ilDeleteImage( image );
	return true;
}
示例#18
0
文件: texture.cpp 项目: esgott/gpgpu
void Texture2D::loadFromFile(std::string fileName) {
    ilInit();
    ILuint devilError = ilGetError();
    if (IL_NO_ERROR != devilError) {
        std::cout << iluErrorString(devilError) << std::endl;
    }

    ILuint imageHandle;
    ilGenImages(1, &imageHandle);
    ilBindImage(imageHandle);
    ilLoadImage(fileName.c_str());
    if (IL_NO_ERROR != devilError) {
        std::cout << iluErrorString(devilError) << std::endl;
    }

    width = (unsigned int) ilGetInteger(IL_IMAGE_WIDTH);
    height = (unsigned int) ilGetInteger(IL_IMAGE_HEIGHT);
    bpp = (unsigned int) ilGetInteger(IL_IMAGE_BITS_PER_PIXEL);

    ILuint dataSize = ilGetInteger(IL_IMAGE_SIZE_OF_DATA);

    float* buffer = new float[width * height * 4];
    ilCopyPixels(0, 0, 0, width, height, 1, IL_RGBA, IL_FLOAT, buffer);

    initialize(width, height, bpp);
    setData(buffer);

    ilDeleteImages(1, &imageHandle);
}
示例#19
0
bool TextureControl::selectImage(ILuint hImage) {
	ilBindImage(hImage);
	if(ilGetError() != IL_NO_ERROR) {
		return false;
	}
	return true;
}
示例#20
0
fill_input_buffer (j_decompress_ptr cinfo)
{
	iread_ptr src = (iread_ptr) cinfo->src;
	ILint nbytes;

	nbytes = iread(src->buffer, 1, INPUT_BUF_SIZE);

	if (nbytes <= 0) {
		if (src->start_of_file) {  // Treat empty input file as fatal error
			//ERREXIT(cinfo, JERR_INPUT_EMPTY);
			jpgErrorOccured = IL_TRUE;
		}
		//WARNMS(cinfo, JWRN_JPEG_EOF);
		// Insert a fake EOI marker
		src->buffer[0] = (JOCTET) 0xFF;
		src->buffer[1] = (JOCTET) JPEG_EOI;
		nbytes = 2;
		return IL_FALSE;
	}
	if (nbytes < INPUT_BUF_SIZE) {
		ilGetError();  // Gets rid of the IL_FILE_READ_ERROR.
	}

	src->pub.next_input_byte = src->buffer;
	src->pub.bytes_in_buffer = nbytes;
	src->start_of_file = IL_FALSE;

	return IL_TRUE;
}
示例#21
0
void Model::loadImage(Image& image, const char* filepath)
{
    std::cout << "Trying to load image at filepath: " << filepath << std::endl;
    
	ILuint imageName; // The image name to return.
    ilGenImages(1, &imageName); // Grab a new image name.
    
	ilBindImage(imageName);
    
	if (!ilLoadImage(filepath)) {
		ILenum Error;
		while ((Error = ilGetError()) != IL_NO_ERROR) {
			std::cout << Error << " " << iluErrorString(Error) << std::endl;
		}
		ilDeleteImages(1, &imageName); // Delete the image name.
	}
    
	image.path = filepath;
	image.width = ilGetInteger(IL_IMAGE_WIDTH); // getting image width
	image.height = ilGetInteger(IL_IMAGE_HEIGHT); // and height
	image.components = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);
	if(image.components < 3) image.components = 3;
	int memory_needed = image.width * image.height * image.components;
	image.data.resize(memory_needed); //Allocate memory
    
	// finally get the image data, and delete the il-image.
	unsigned int type = IL_RGB;
	if(image.components == 4)
		type = IL_RGBA;
	ilCopyPixels(0, 0, 0, image.width, image.height, 1, type, IL_UNSIGNED_BYTE, &image.data[0]);
	ilDeleteImages(1, &imageName);
}
示例#22
0
    //---------------------------------------------------------------------
    void ILImageCodec::codeToFile(MemoryDataStreamPtr& input, 
        const String& outFileName, Codec::CodecDataPtr& pData) const
    {

        ILuint ImageName;

        ilGenImages( 1, &ImageName );
        ilBindImage( ImageName );

		ImageData* pImgData = static_cast< ImageData * >( pData.getPointer() );
		PixelBox src(pImgData->width, pImgData->height, pImgData->depth, pImgData->format, input->getPtr());

		// Convert image from OGRE to current IL image
		ILUtil::fromOgre(src);

        iluFlipImage();

        // Implicitly pick DevIL codec
        ilSaveImage(const_cast< char * >( outFileName.c_str() ) );
	
        // Check if everything was ok
        ILenum PossibleError = ilGetError() ;
        if( PossibleError != IL_NO_ERROR ) {
           ilDeleteImages(1, &ImageName);
           OGRE_EXCEPT( Exception::ERR_NOT_IMPLEMENTED,
                "IL Error, could not save file: " + outFileName,
                iluErrorString(PossibleError) ) ;
        }

        ilDeleteImages(1, &ImageName);

    }
示例#23
0
void ImageManager::ReportDevILErrors()
{
    ILenum Error;
    while ((Error = ilGetError()) != IL_NO_ERROR)
    {
       // printf("DevIL Error %d: %s\n", Error, iluErrorString(Error));
    }
}
示例#24
0
文件: image.c 项目: ryd/info-beamer
int image_load(lua_State *L, const char *path, const char *name) {
    ILuint imageID;
    ilGenImages(1, &imageID);
    ilBindImage(imageID);
 
    if (!ilLoadImage(path)) {
        ilDeleteImages(1, &imageID);
        return luaL_error(L, "loading %s failed: %s",
            path, iluErrorString(ilGetError()));
    }
 
    ILinfo ImageInfo;
    iluGetImageInfo(&ImageInfo);

    if (ImageInfo.Origin == IL_ORIGIN_UPPER_LEFT)
        iluFlipImage();
 
    if (!ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE)) {
        ilDeleteImages(1, &imageID);
        return luaL_error(L, "converting %s failed: %s",
            path, iluErrorString(ilGetError()));
    }

    int width = ilGetInteger(IL_IMAGE_WIDTH);
    int height = ilGetInteger(IL_IMAGE_HEIGHT);

    GLuint tex;
    glGenTextures(1, &tex);
    glBindTexture(GL_TEXTURE_2D, tex);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

    glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), width, height, 0,
                 ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());
    glGenerateMipmap(GL_TEXTURE_2D);
 
    ilDeleteImages(1, &imageID);
 
    image_t *image = push_image(L);
    image->tex = tex;
    image->fbo = 0;
    image->width = width;
    image->height = height;
    return 1;
}
示例#25
0
GLuint CGLTexture::LoadGL(string f) {
    glBmap=0;
    filename=f;
	ILuint imageID;
	ILboolean success;
	ILenum error;
	ilGenImages(1, &imageID);
	ilBindImage(imageID);
	success = ilLoadImage(filename.c_str());
	if (success) {
		ILinfo ImageInfo;
		iluGetImageInfo(&ImageInfo);
		if (ImageInfo.Origin == IL_ORIGIN_UPPER_LEFT) iluFlipImage();
		success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
		if (!success){
			error = ilGetError();
			pLog->_Add("  CGLTexture::LoadGL() Image conversion failed - IL reports error: %d %s",error,iluErrorString(error));
			return 0;
        }
        width=ilGetInteger(IL_IMAGE_WIDTH);
        height=ilGetInteger(IL_IMAGE_HEIGHT);
        format=ilGetInteger(IL_IMAGE_FORMAT);
        bpp=ilGetInteger(IL_IMAGE_BPP)*8;
        glEnable(GL_TEXTURE_2D);
		glGenTextures(1, &glBmap);
		glBindTexture(GL_TEXTURE_2D, glBmap);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		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,
                        ilGetInteger(IL_IMAGE_BPP),
                        ilGetInteger(IL_IMAGE_WIDTH),
                        ilGetInteger(IL_IMAGE_HEIGHT),	 0,
                        ilGetInteger(IL_IMAGE_FORMAT),
                        GL_UNSIGNED_BYTE,
                        ilGetData());
 	}
  	else {
		error = ilGetError();
		pLog->_Add("  CGLTexture::LoadGL() Image load failed - IL reports error: %d %s",error,iluErrorString(error));
		return 0;
  	}
 	ilDeleteImages(1, &imageID);
    return glBmap;
}
示例#26
0
文件: il_wdp.c 项目: 123woodman/minko
ERR iReadWS_File(struct WMPStream* pWS, void* pv, size_t cb)
{
	// For some reason, the WDP images load just fine, but it tries to read too much,
	//  so IL_FILE_READ_ERROR is set.  So we get rid of the error.
	if (iread(pv, 1, (ILuint)cb) != cb)
		ilGetError();
    return WMP_errSuccess;
}
示例#27
0
bool initGL()
{
    // clock_gettime(CLOCK_MONOTONIC, &ts); // Works on FreeBSD
    clock_gettime(CLOCK_REALTIME, &ts); // Works on Linux
    start_time = ts.tv_sec;

    //Initialize GLEW
    GLenum glewError = glewInit();
    if( glewError != GLEW_OK )
    {
        printf( "Error initializing GLEW! %s\n", glewGetErrorString( glewError ) );
        return false;
    }

    //Make sure OpenGL 2.1 is supported
    if( !GLEW_VERSION_2_1 )
    {
        printf( "OpenGL 2.1 not supported!\n" );
        return false;
    }

    //Set the viewport
    glViewport( 0.f, 0.f, SCREEN_WIDTH, SCREEN_HEIGHT );

    //Initialize clear color
    glClearColor( 0.f, 0.f, 0.f, 1.f );

    //Enable texturing
    glEnable( GL_TEXTURE_2D );

    //Set blending
    glEnable( GL_BLEND );
    glDisable( GL_DEPTH_TEST );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

    //Check for error
    GLenum error = glGetError();
    if( error != GL_NO_ERROR )
    {
        printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) );
        return false;
    }

    //Initialize DevIL and DevILU
    ilInit();
    iluInit();
    ilClearColour( 255, 255, 255, 000 );

    //Check for error
    ILenum ilError = ilGetError();
    if( ilError != IL_NO_ERROR )
    {
        printf( "Error initializing DevIL! %s\n", iluErrorString( ilError ) );
        return false;
    }

    return true;
}
示例#28
0
文件: test.c 项目: AMDmi3/DevIL
int main(int argc, char **argv)
{
	ILuint	ImgId;
	ILenum	Error;
	char	*Data;
	long	Size;

	// We use the filename specified in the first argument of the command-line.
	if (argc < 3) {
		printf("Please specify a .rar file and file inside to open.\n");
		return 1;
	}

	// Check if the shared lib's version matches the executable's version.
	if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION ||
		iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION) {
		printf("DevIL version is different...exiting!\n");
		return 2;
	}

	// Initialize DevIL.
	ilInit();
	// Generate the main image name to use.
	ilGenImages(1, &ImgId);
	// Bind this image name.
	ilBindImage(ImgId);

	if (!urarlib_get(&Data, &Size, argv[2], argv[1], "none")) {
		printf("Error loading .rar file.\n");
		return 3;
	} 

	// Loads the image specified by File into the image named by ImgId.
	ilLoadL(IL_TGA, Data, Size);

	// Display the image's dimensions to the end user.
	printf("Width: %d  Height: %d  Depth: %d  Bpp: %d\n", ilGetInteger(IL_IMAGE_WIDTH),
		ilGetInteger(IL_IMAGE_HEIGHT), ilGetInteger(IL_IMAGE_DEPTH), ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL));

	// Enable this to let us overwrite the destination file if it already exists.
	ilEnable(IL_FILE_OVERWRITE);

	// If argv[2] is present, we save to this filename, else we save to test.tga.
	if (argc > 2)
		ilSaveImage(argv[3]);
	else
		ilSaveImage("test.tga");

	// We're done with the image, so let's delete it.
	ilDeleteImages(1, &ImgId);

	// Simple Error detection loop that displays the Error to the user in a human-readable form.
	while ((Error = ilGetError())) {
		printf("Error: %s\n", iluErrorString(Error));
	}

	return 0;
}
示例#29
0
文件: ilur.c 项目: 123woodman/minko
int do_stuff(const Params * parameters)
{
	if (parameters->Flags & FLAG_HELP || ((parameters->Flags | FLAG_LOAD |  FLAG_SAVE) != parameters->Flags) )
	{/* We wanted HELP or we did not get SAVE or LOAD */
		print_help(); /* tell the loser what to do, then :-) */
		return 0;
	}
	int verbose = parameters->Flags & FLAG_VERBOSE;

	int image_handle;
	int w, h;
	ILboolean result;

	/* Quite obvious stuff, just load an image */
	ilGenImages(1, & image_handle);
	ilBindImage(image_handle);
	result = ilLoadImage(parameters->Load_filename);
	if (result == IL_FALSE)
	{
		int error = ilGetError();
		fprintf(stderr, "Error: Something went wrong when loading file '%s' (%s)\n", parameters->Load_filename, iluErrorString(error));
		return error;
	}
	/* If we get image's dimensions, people will believe that we have actually loaded something :-) */
	w = ilGetInteger(IL_IMAGE_WIDTH);
	h = ilGetInteger(IL_IMAGE_HEIGHT);
	if (verbose)
		printf("Loaded '%s', size %dx%d\n", parameters->Load_filename, w, h);
	/* Now let's do our stuff!!! */
	int i;
	for (i = 0; i < parameters->Calls_count; i++)
		perform_operation(parameters->Calls_strings[i], verbose);
	/* our stuff has been done... */

	result = ilSaveImage(parameters->Save_filename);
	if (result == IL_FALSE)
	{
		int error = ilGetError();
		fprintf(stderr, "Error: Something went wrong when saving file '%s' (%s)\n", parameters->Save_filename, iluErrorString(error));
		ilDeleteImages(1, & image_handle);
		return error;
	}
	ilDeleteImages(1, & image_handle);
	return 0;
}
示例#30
0
//! Set all states to their defaults.
ILvoid ilDefaultStates()
{
	ilStates[ilCurrentPos].ilOriginSet = IL_FALSE;
	ilStates[ilCurrentPos].ilOriginMode = IL_ORIGIN_LOWER_LEFT;
	ilStates[ilCurrentPos].ilFormatSet = IL_FALSE;
	ilStates[ilCurrentPos].ilFormatMode = IL_BGRA;
	ilStates[ilCurrentPos].ilTypeSet = IL_FALSE;
	ilStates[ilCurrentPos].ilTypeMode = IL_UNSIGNED_BYTE;
	ilStates[ilCurrentPos].ilOverWriteFiles = IL_FALSE;
	ilStates[ilCurrentPos].ilAutoConvPal = IL_FALSE;
	ilStates[ilCurrentPos].ilDefaultOnFail = IL_FALSE;
	ilStates[ilCurrentPos].ilUseKeyColour = IL_FALSE;
	ilStates[ilCurrentPos].ilCompression = IL_COMPRESS_ZLIB;
	ilStates[ilCurrentPos].ilInterlace = IL_FALSE;

	ilStates[ilCurrentPos].ilTgaCreateStamp = IL_FALSE;
	ilStates[ilCurrentPos].ilJpgQuality = 99;
	ilStates[ilCurrentPos].ilPngInterlace = IL_FALSE;
	ilStates[ilCurrentPos].ilTgaRle = IL_FALSE;
	ilStates[ilCurrentPos].ilBmpRle = IL_FALSE;
	ilStates[ilCurrentPos].ilSgiRle = IL_FALSE;
	ilStates[ilCurrentPos].ilJpgFormat = IL_JFIF;
	ilStates[ilCurrentPos].ilDxtcFormat = IL_DXT1;
	ilStates[ilCurrentPos].ilPcdPicNum = 2;
	ilStates[ilCurrentPos].ilPngAlphaIndex = -1;

	ilStates[ilCurrentPos].ilTgaId = NULL;
	ilStates[ilCurrentPos].ilTgaAuthName = NULL;
	ilStates[ilCurrentPos].ilTgaAuthComment = NULL;
	ilStates[ilCurrentPos].ilPngAuthName = NULL;
	ilStates[ilCurrentPos].ilPngTitle = NULL;
	ilStates[ilCurrentPos].ilPngDescription = NULL;

	//2003-09-01: added tiff strings
	ilStates[ilCurrentPos].ilTifDescription = NULL;
	ilStates[ilCurrentPos].ilTifHostComputer = NULL;
	ilStates[ilCurrentPos].ilTifDocumentName = NULL;
	ilStates[ilCurrentPos].ilTifAuthName = NULL;
	ilStates[ilCurrentPos].ilCHeader = NULL;

	ilStates[ilCurrentPos].ilQuantMode = IL_WU_QUANT;
	ilStates[ilCurrentPos].ilNeuSample = 15;
	ilStates[ilCurrentPos].ilQuantMaxIndexs = 256;

	ilStates[ilCurrentPos].ilKeepDxtcData = IL_FALSE;




	ilHints.MemVsSpeedHint = IL_FASTEST;
	ilHints.CompressHint = IL_USE_COMPRESSION;

	while (ilGetError() != IL_NO_ERROR);

	return;
}