🔒 Locked
Linux Compatible Bitmap Loader
Advertisement
Original Post
Take a look at SDL_image. I'm not sure if it will convert a color key to transparency, but it will give you a pointer to the uncompressed image data, and you can make a color transparent yourself by just using a for loop over the entire image data and setting alpha to 0 for that color.
Quote:
Original post by nagromo
Take a look at SDL_image. I'm not sure if it will convert a color key to transparency, but it will give you a pointer to the uncompressed image data, and you can make a color transparent yourself by just using a for loop over the entire image data and setting alpha to 0 for that color.
yeah I was just having a look at SDL, but I'm confused, can you bind the image you loaded with SDL onto an opengl polygon? or are you only able to output the image to the screen.
You can use an SDL_Surfaces with glTexImage2D just pass the pixels member as the last parameter:
eg:
You may have to fiddle with the format flags depending on the type of images you load though.
eg:
SDL_Surface* temp = IMG_Load( "somefile.bmp" );glTexImage2D( GL_TEXTURE_2D, 0, 3, temp->w, temp->h, 0, GL_BGR, GL_UNSIGNED_BYTE, temp->pixels );SDL_FreeSurface( temp );You may have to fiddle with the format flags depending on the type of images you load though.
Quote:
Original post by Phoresis Quote:
Original post by nagromo
Take a look at SDL_image. I'm not sure if it will convert a color key to transparency, but it will give you a pointer to the uncompressed image data, and you can make a color transparent yourself by just using a for loop over the entire image data and setting alpha to 0 for that color.
yeah I was just having a look at SDL, but I'm confused, can you bind the image you loaded with SDL onto an opengl polygon? or are you only able to output the image to the screen.
Yes.
SDL will load the image into memory. Using some of SDL's surface manipulation facilities you can turn the image into a format acceptable by opengl. Then you ca give opengl access to the raw image data. What you do then is up to you.
If you are interested in cross-platform opengl development I highly recommend SDL as a library for window creation and input, if you are not using it already.
Ok, I've got textures working, but for some things they are loading really blurred and I can't figure out why. Also transparency isn't working at all. Here is my code:
void loadBitmap(char *filename, int id, bool transparency){ glPixelStorei(GL_UNPACK_ALIGNMENT,4); glBindTexture(GL_TEXTURE_2D,texture_id[id]); //Load Bitmap SDL_Surface* bmpFile = SDL_LoadBMP(filename); if (transparency && bmpFile) { SDL_SetColorKey(bmpFile, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB(bmpFile->format, 0,255,0)); } glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D,3,bmpFile->w,bmpFile->h,GL_BGR_EXT,GL_UNSIGNED_BYTE,bmpFile->pixels); //Free surface after using it SDL_FreeSurface(bmpFile);}
Quote:
Original post by Phoresis
I need to create a Bitmap texture loader that is not windows dependant and I also need to be able to pick a colour to make transparent, but I have no idea where to start, and google has failed me.
Anyone know any good tutorials or sample code for accomplishing this?
I have my own BMP loader/writer. I hope it helps you: imageBmp.zip.
(it has been tested on a Linux system.)
I uses glDrawPixels() in the above code, but you can convert easily to glTexImage2D(). For example;
Image::Bmp bmp;bmp.read("somefile.bmp");int width = bmp.getWidth();int height = bmp.getHeight();GLvoid* pixels = (GLvoid*)bmp.getDataRGB(); // data with RGB orderGLint format;switch(bmp.getBitCount()){ case 8: format = GL_LUMINANCE; break; case 24: format = GL_RGB; break; case 32: format = GL_RGBA; break;}...glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, pixels);Quote:
Original post by songho Quote:
Original post by Phoresis
I need to create a Bitmap texture loader that is not windows dependant and I also need to be able to pick a colour to make transparent, but I have no idea where to start, and google has failed me.
Anyone know any good tutorials or sample code for accomplishing this?
I have my own BMP loader/writer. I hope it helps you: imageBmp.zip.
(it has been tested on a Linux system.)
I uses glDrawPixels() in the above code, but you can convert easily to glTexImage2D(). For example;
*** Source Snippet Removed ***
awesome, does this allow transparency?
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement