problem in my color keying code

Started by
13 comments, last by Khaos Dragon 19 years, 10 months ago
I didn''t know it also builds the texture, never used GLUT.
Advertisement
quote:Original post by Raduprv
I didn't know it also builds the texture, never used GLUT.


It's not GLUT, it's GLU, the opengl utility library.

And changing the alpha test parameter from 0.0 to 0.1 had no effect as well.



[edited by - Khaos Dragon on June 3, 2004 11:32:47 AM]
i have the same question.after googling the web for quite a long time ,finally i got this.
http://www.lighthouse3d.com/opengl/billboarding/index.php3?billInt
game!only game! :)
the code may give you some help on how to terminate your q.
first time posting in this site.
game!only game! :)
Yes I found some tutorials beforehand which performed color keying but only by using the glaux library. I wanted to do it just using SDL since I would like to do all my auxilary image processing with one library if possible.

But alas I found out the problem, and it was a fairly stupid one at that, I feel quite like an idiot.

It turns out there wasn''t much of a problem with my code, except instead of using glLinear in my texture attributes I have to use glNearest.

For anyone who wants to do color keying with open gl and sdl, here is my source code for the function which does it. Right now
it color keys black out, if you want a different color just adjust the values in the line if( r == 0 && g == 0 && b == 0 )

void CreateTexture( unsigned int* intPtr, char* filename, bool color_key){    int channels;	unsigned char * newData;	SDL_Surface *pBitmap[1];    pBitmap[0] = IMG_Load( filename );           if(pBitmap[0] == NULL)                                        return;    	glGenTextures(1, intPtr );    glBindTexture(GL_TEXTURE_2D, *intPtr );    int width  = pBitmap[0] -> w;    int height = pBitmap[0] -> h;    unsigned char * data = (unsigned char *) (pBitmap[0] -> pixels);       if( !color_key)	{		channels = 3;		newData = new unsigned char[width*height*3];	}	else	{		channels = 4;		newData = new unsigned char[width*height*4];	}    int BytesPerPixel = pBitmap[0] -> format -> BytesPerPixel ;     for( int i = 0 ; i < (height / 2) ; ++i )        for( int j = 0 ; j < width * BytesPerPixel; j += BytesPerPixel )            for(int k = 0; k < BytesPerPixel; ++k)			{				unsigned char  temp = data[ (i * width * BytesPerPixel) + j + k];				data[ (i * width * BytesPerPixel) + j + k]    =  data[ ( (height - i - 1) * width * BytesPerPixel ) + j + k];				data[ ( (height - i - 1) * width * BytesPerPixel ) + j + k]    = temp;			}    for(i = 0; i < (width * height); ++i)    {        unsigned char r,g,b;                                                       Uint32 pixel_value = 0;                                            for(int j = BytesPerPixel - 1 ; j >=0; --j)                        {            pixel_value = pixel_value << 8;                                    pixel_value = pixel_value | data[ (i * BytesPerPixel) + j ];         }                                                                         SDL_GetRGB(pixel_value, pBitmap[0] -> format, (Uint8 *)&r, (Uint8 *)&g, (Uint8 *)&b);            		newData[(i * channels) + 0] = r;                newData[(i * channels) + 1] = g;                  newData[(i * channels) + 2] = b;    		if( color_key )			if( r == 0 && g == 0 && b == 0 )				newData[(i * channels) + 3] = 0;			else				newData[(i * channels) + 3] = 255;        pixel_value = 0;                                               }    	if( color_key )	{		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST);        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST);		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, pBitmap[0]->w, pBitmap[0]->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, newData);	}	else	{		gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap[0]->w, pBitmap[0]->h, GL_RGB, GL_UNSIGNED_BYTE, newData);		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);    		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);	}    delete [] newData;    SDL_FreeSurface(pBitmap[0]);                       } 

This topic is closed to new replies.

Advertisement