bool JTexture::loadTextureFromFileWithColorKey(std::string path, GLubyte r, GLubyte g, GLubyte b, GLubyte a)
{
	if(!loadPixelsFromFile(path))
	{
		return false;
	}

	GLuint size = mTextureWidth * mTextureHeight;

	//loop through all pixels
	for (int i = 0; i < size; ++i)
	{
		//each GLuint is an array of 4 GLubytes
		GLubyte* colors = (GLubyte*)&mPixels[i];

		if (colors[0] == r && colors[1] == g && colors[2] == b && ( 0 == a || colors[3] == a))
		{
			colors[0] = 255;
			colors[1] = 255;
			colors[2] = 255;
			colors[3] = 000;
		}
	}

	return loadTextureFromPixels32();
}
Exemple #2
0
bool DrawAbstract::loadImages(){

    //Generate and set current image ID
    ILuint *imgID = new ILuint[videoduration];
    ilGenImages( videoduration, imgID );

    mTextureIDs = new GLuint[videoduration];
    glGenTextures( videoduration, mTextureIDs );

    for(int i = 0; i < videoduration; i++){
    	ilBindImage( imgID[i] );

        //Load image
        char *path;
        generateImagePath(&path,i+1);//array from 0, images on hdd from 1
        std::cout << "Path:" << path << std::endl;
        ILboolean success = ilLoadImage( path );
        //delete path;
        std::cout << "bla" << success <<  std::endl;

        //Image loaded successfully
        if( success == IL_TRUE )
        {
            success = ilConvertImage( IL_RGBA, IL_UNSIGNED_BYTE );
            if( success == IL_TRUE )
            {
                //Create texture from file pixels
                loadTextureFromPixels32( (GLuint*)ilGetData(), (GLuint)ilGetInteger( IL_IMAGE_WIDTH ), (GLuint)ilGetInteger( IL_IMAGE_HEIGHT ),i);
            }
        }

     }

    return true;
}
bool JTexture::loadTextureFromFile(std::string path)
{
	bool textureLoaded = false;

	//generate & set current image ID
	ILuint imgID = 0;
	ilGenImages(1, &imgID);
	ilBindImage(imgID);

	//load image
	ILboolean success = ilLoadImage(path.c_str());

	if (success == IL_TRUE)
	{
		success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);

		if(success == IL_TRUE)
        {
            //Create texture from file pixels
            textureLoaded = loadTextureFromPixels32((GLuint*)ilGetData(), (GLuint)ilGetInteger(IL_IMAGE_WIDTH), (GLuint)ilGetInteger(IL_IMAGE_HEIGHT));
        }
	}
	
	if(!textureLoaded)
			printf("Unable to load %s\n", path.c_str());

	return textureLoaded;
}
bool LTexture::loadTextureFromFile32( std::string path )
{
    //Texture loading success
    bool textureLoaded = false;

    //Generate and set current image ID
    ILuint imgID = 0;
    ilGenImages( 1, &imgID );
    ilBindImage( imgID );

    //Load image
    ILboolean success = ilLoadImage( path.c_str() );

    //Image loaded successfully
    if( success == IL_TRUE )
    {
        //Convert image to RGBA
        success = ilConvertImage( IL_RGBA, IL_UNSIGNED_BYTE );
        if( success == IL_TRUE )
        {
            //Initialize dimensions
            GLuint imgWidth = (GLuint)ilGetInteger( IL_IMAGE_WIDTH );
            GLuint imgHeight = (GLuint)ilGetInteger( IL_IMAGE_HEIGHT );

            //Calculate required texture dimensions
            GLuint texWidth = powerOfTwo( imgWidth );
            GLuint texHeight = powerOfTwo( imgHeight );

            //Texture is the wrong size
            if( imgWidth != texWidth || imgHeight != texHeight )
            {
                //Place image at upper left
                iluImageParameter( ILU_PLACEMENT, ILU_UPPER_LEFT );

                //Resize image
                iluEnlargeCanvas( (int)texWidth, (int)texHeight, 1 );
            }

            //Create texture from file pixels
            textureLoaded = loadTextureFromPixels32( (GLuint*)ilGetData(), imgWidth, imgHeight, texWidth, texHeight );
        }

        //Delete file from memory
        ilDeleteImages( 1, &imgID );

        //Set pixel format
        mPixelFormat = GL_RGBA;
    }

    //Report error
    if( !textureLoaded )
    {
        printf( "Unable to load %s\n", path.c_str() );
    }

    return textureLoaded;
}
bool LTexture::loadTextureFromFileWithColorKey32( std::string path, GLubyte r, GLubyte g, GLubyte b, GLubyte a )
{
    //Load pixels
    if( !loadPixelsFromFile32( path ) )
    {
        return false;
    }

    //Go through pixels
    GLuint size = mTextureWidth * mTextureHeight;
    for( int i = 0; i < size; ++i )
    {
        //Get pixel colors
        GLubyte* colors = (GLubyte*)mPixels32;

        //Color matches
        if( colors[ 0 ] == r && colors[ 1 ] == g && colors[ 2 ] == b && ( 0 == a || colors[ 3 ] == a ) )
        {
            //Make transparent
            colors[ 0 ] = 255;
            colors[ 1 ] = 255;
            colors[ 2 ] = 255;
            colors[ 3 ] = 000;
        }
    }

    //Create texture
    if( !loadTextureFromPixels32() )
    {
        return false;
    }

    //Set pixel format
    mPixelFormat = GL_RGBA;

    return true;
}
Exemple #6
0
bool Texture::loadTextureFromFile( std::string path )
{
    //Texture loading success
    bool textureLoaded = false;

    //Generate and set current image ID
    ILuint imgID = 0;
    ilGenImages( 1, &imgID );
    ilBindImage( imgID );

    //Load image
	ILboolean success = ilLoadImage( path.c_str() );

	//Image loaded successfully
	if( success == IL_TRUE ){
	//Convert image to RGBA
	success = ilConvertImage( IL_RGBA, IL_UNSIGNED_BYTE );

		if( success == IL_TRUE )
		{
			//Create texture from file pixels
			textureLoaded = loadTextureFromPixels32( (GLuint*)ilGetData(), (GLuint)ilGetInteger( IL_IMAGE_WIDTH ), (GLuint)ilGetInteger( IL_IMAGE_HEIGHT ) );
		}

		//Delete file from memory
		ilDeleteImages( 1, &imgID );
	}

	//Report error
	if( !textureLoaded )
	{
		mTextureID = 0;
	}

	return textureLoaded;
}
Exemple #7
0
bool DrawAbstract::loadImage(std::string path){

    //Generate and set current image ID
    ILuint imgID;
    ilGenImages( 1, &imgID );
    ilBindImage( imgID );

    //Load image
    char path_tmp[1024];
    strcpy(path_tmp,path.c_str());
    ILboolean success = ilLoadImage( path_tmp );

    //Image loaded successfully
    if( success == IL_TRUE )
    {
        success = ilConvertImage( IL_RGBA, IL_UNSIGNED_BYTE );
        if( success == IL_TRUE )
        {
            //Create texture from file pixels
            loadTextureFromPixels32( (GLuint*)ilGetData(), (GLuint)ilGetInteger( IL_IMAGE_WIDTH ), (GLuint)ilGetInteger( IL_IMAGE_HEIGHT ) );
        }
    }
	return true;
}
Exemple #8
0
Texture::Texture( GLuint* pixels, GLuint width, GLuint height )
{
	loadTextureFromPixels32(pixels, width, height);
}