Пример #1
0
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);
}
Пример #2
0
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);
	}
}
Пример #3
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);
}
Пример #4
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);
	}
}
Пример #5
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;
}
Пример #6
0
void Texture::checkErrors() {
    ILenum Error;
    std::cout<<"Checking Errors..."<<std::endl;
	while ((Error = ilGetError()) != IL_NO_ERROR) { 
	    printf("%d: %s/n", Error, iluErrorString(Error)); 
	} 
}
Пример #7
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);

    }
Пример #8
0
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;
}
Пример #9
0
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;
}
Пример #10
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;
}
Пример #11
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);
}
Пример #12
0
//
// ILERROR
//
void ilError::Check(void (*Callback)(const char*))
{
	static ILenum Error;

	while ((Error = ilGetError()) != IL_NO_ERROR) {
		Callback(iluErrorString(Error));
	}

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

    //Make sure OpenGL 3.0 is supported
    if( !GLEW_VERSION_3_0 )
    {
        printf( "OpenGL 3.0 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 ) );
        printf( "Error initializing OpenGL!\n"); 
        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;
}
Пример #14
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!
}
Пример #15
0
// return true on error
bool ILCheck(const char* file, int line, const char* call)
{
    ILuint err = ilGetError();
    if (err != IL_NO_ERROR) {
#ifdef FAIL_ON_ERROR
        sbFail(
#else
        gLog.err(
#endif
            "DevIL error: \"%s\" at file %s, line %d\n>> %s\n", iluErrorString(err), file, line, call);
    }
Пример #16
0
void HandleDevILErrors ()
{
	ILenum error = ilGetError ();
	
	if (error != IL_NO_ERROR) {
		do {
			printf ("\n\n%s\n", iluErrorString (error));	
		} while ((error = ilGetError ()));

		exit (1);
	}
}
Пример #17
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()));
		}
	}
Пример #18
0
bool readImage(char *filename, int frameNumber, vpx_image_t **pRGBImage, vpx_image_t **pYV12Image, int flip)
{
	// Load image.
	//
	char path[512];
	sprintf(path, filename, frameNumber);

	ILuint imageHandle;
	ilGenImages(1, &imageHandle);
	ilBindImage(imageHandle);

	ILboolean ok = ilLoadImage(path);

	if (ok)
	{
		if (ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE))
		{
			unsigned int w = ilGetInteger(IL_IMAGE_WIDTH);
			unsigned int h = ilGetInteger(IL_IMAGE_HEIGHT);

			if (*pRGBImage == NULL)
			{
				*pRGBImage = vpx_img_alloc(NULL, VPX_IMG_FMT_RGB24, w, h, 1);
			}

			if (*pYV12Image == NULL)
			{
				*pYV12Image = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, w, h, 1);
			}

			memcpy((*pRGBImage)->img_data, ilGetData(), w * h * 3);

			rgb24toyv12(*pRGBImage, *pYV12Image);

			if (flip)
			{
				vpx_img_flip(*pYV12Image);
			}

			ilDeleteImages(1, &imageHandle);

			return true;
		}
	}
	else
	{
		ILenum ilError = ilGetError();
		fprintf(stderr, "Can't load [%s], [%x %s]\n.", path, ilError, iluErrorString(ilError));
	}

	return false;
}
Пример #19
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);
    }
}
Пример #20
0
void readTextures(scene_data* scene, const boost::property_tree::ptree& pt)
{
	boost::property_tree::ptree::const_iterator iter = pt.begin();
	for (; iter != pt.end(); ++iter)
	{
		std::string name = iter->first;
		std::string filename = iter->second.get_value<std::string>();
		GLuint image = ilutGLLoadImage((wchar_t*)filename.c_str());
		ILenum error = ilGetError();
		printf("%s\n", iluErrorString(error));
		scene->textures[name] = image;
	}
}
Пример #21
0
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;
}
Пример #22
0
	Image::Image(string filename)
	{
		Image::init();

		ilGenImages(1, &_image);

		ilBindImage(_image);
		ilLoadImage(filename.c_str());

		ILenum Error;
		while ((Error = ilGetError()) != IL_NO_ERROR) {
			std::cerr << iluErrorString(Error) << std::endl;
		}
	}
Пример #23
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;
	}
bool initGL()
{
    //Set the viewport
    glViewport( 0.f, 0.f, SCREEN_WIDTH, SCREEN_HEIGHT );

    //Initialize Projection Matrix
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glOrtho( 0.0, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0, 1.0, -1.0 );

    //Initialize Modelview Matrix
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    //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 ) );
        printf( "Error initializing OpenGL!\n"); 
        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;
}
Пример #25
0
bool initIL() {
	//Initialize DevIL and DevILU

	bool success = true;

	ilInit();
	iluInit();
	ilClearColour( 255, 255, 255, 000 );

	ILenum ilError = ilGetError();

	if ( ilError != IL_NO_ERROR ) {
		printf("Error initializing DevIL:\n\t%s\n", iluErrorString( ilError ) );
		success = false;
	}

	return success;
}
Пример #26
0
INT_PTR APIENTRY AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
	{
	    case WM_INITDIALOG:
		{
			int i;
			ILenum ilError;
			TCHAR VersionNum[256];

			wsprintf(VersionNum, L"Num:  %d", ilGetInteger(IL_VERSION_NUM));

			SetDlgItemText(hDlg, IDC_ABOUT_VENDOR, ilGetString(IL_VENDOR));
			SetDlgItemText(hDlg, IDC_ABOUT_VER_STRING, ilGetString(IL_VERSION_NUM));
			SetDlgItemText(hDlg, IDC_ABOUT_VER_NUM, VersionNum);

			for (i = 0; i < 6; i++) {
				ilError = ilGetError();
				if (ilError == IL_NO_ERROR)
					break;
				SetDlgItemText(hDlg, IDC_ERROR1+i, iluErrorString(ilError));
			}

			return (TRUE);
		}
		break;

	    case WM_COMMAND:      
		{
			if (LOWORD(wParam) == IDOK)
				EndDialog(hDlg, TRUE);
			if (LOWORD(wParam) == IDCANCEL)
				EndDialog(hDlg, FALSE);
	    }
		break;

		case WM_CLOSE:
			EndDialog(hDlg, TRUE);
			break;
	}

	return FALSE;
}
Пример #27
0
bool initGL(void) {
	GLenum glewError = glewInit();
	if (glewError != GLEW_OK) {
		fprintf(stderr, "Error initializing GLEW!\n%s\n", glewGetErrorString(glewError));
		return false;
	}

	if (!GLEW_VERSION_3_1) {
		fprintf(stderr, "OpenGL 3.1 not supported!\n");
		return false;
	}

	glViewport(0.0f, 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT);

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glEnable(GL_TEXTURE_2D);

	glEnable(GL_BLEND);
	glDisable(GL_DEPTH_TEST);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

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

	ilInit();
	iluInit();
	ilClearColor(255, 255, 255, 000);

	ILenum ilError = ilGetError();
	if (ilError != IL_NO_ERROR) {
		fprintf(stderr, "Unable to initialize DevIL!\n%s\n", iluErrorString(ilError));
		return false;
	}

	if (!LFont::initFreetype()) {
		fprintf(stderr, "Unable to initialize Truetype!\n");
	}

	return true;
}
Пример #28
0
unsigned int devil_loadImage(const std::string &fileName) {
	unsigned int imageName = 0;
	ilGenImages(1, &imageName);
	ilBindImage(imageName);
	
	ilLoadImage(fileName);
	
	ILenum error = ilGetError();
	
	if (error != IL_NO_ERROR) {
		std::cerr << "DevIL error: " << iluErrorString(error) << std::endl;
		return 0;
	} else {
		if (ilGetInteger(IL_ORIGIN_MODE) == IL_ORIGIN_LOWER_LEFT &&
		    getFileExtension(fileName) != ".tif") {
			iluFlipImage();
		}
		
		return imageName;
	}
}
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 );
}
Пример #30
0
	/**
	  * Loads an image into memory from file
	  */
	static void loadImage(std::string filename, texture& tex) {
		ILuint ImageName;

		ilGenImages(1, &ImageName); // Grab a new image name.
		ilBindImage(ImageName); 
		
		if (!ilLoadImage(filename.c_str())) {
			ILenum e;
			std::stringstream error;
			while ((e = ilGetError()) != IL_NO_ERROR) {
				error << e << ": " << iluErrorString(e) << std::endl;
			}
			ilDeleteImages(1, &ImageName); // Delete the image name. 
			throw std::runtime_error(error.str());
		}

		tex.width = ilGetInteger(IL_IMAGE_WIDTH); // getting image width
		tex.height = ilGetInteger(IL_IMAGE_HEIGHT); // and height
		tex.data.resize(tex.width*tex.height*3);
		
		ilCopyPixels(0, 0, 0, tex.width, tex.height, 1, IL_RGB, IL_FLOAT, tex.data.data());
		ilDeleteImages(1, &ImageName); // Delete the image name. 
	}