PDA

View Full Version : Use BMP, PCX, TGA, JPEG for textures



Bahamut_france
03-12-2001, 05:21 AM
Hi.
I search free librairies or free classes who permit to import textures in OpenGL applications. Now I'm using RGB format but it is hard to find software for making drawings in RGB format.
So if you now a program (free always) who convert BMP, PCX, or TGA files in RGB format. Exist 3Dexploration but it do only the conversion in the contrary sens.

Thanks for help. http://www.opengl.org/discussion_boards/ubb/smile.gif

Keymaster
03-29-2001, 10:12 AM
void setup_texture(char *filename, GLuint texobj, GLenum minFilter, GLenum maxFilter, int xs)
/////////////////////////////////////////////////////////////////////////////////////////////
// Load texture from tga-file..(32 bit.. )
{
glBindTexture(GL_TEXTURE_2D, texobj);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, maxFilter);

FILE *f = fopen( filename, "rb" );

if (!f)
{
MessageBox (0, filename, "File Open Error", 0);
assert( f );
}
fseek( f, 18, SEEK_SET );

unsigned char *buf = (unsigned char*)malloc( xs * xs * 4 );
assert(buf);
fread( buf, xs * xs * 4, 1, f );

// alpha-wert setzen...
for ( int i = 0; i < xs*xs; i++ )
buf[i*4+3]=128;

fclose( f );

glTexImage2D( GL_TEXTURE_2D, 0, 4, xs, xs, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, buf );

free(buf);
}

jwatte
03-29-2001, 10:41 AM
OpenIL is one of many available image loading libraries that are freely available.

davepermen
03-29-2001, 10:50 AM
hm openIL is stupid.. they forgot a nice little function:

IMG* myimg = loadIMG( "mypic.xyz" ); //xyz representing the fileformat

i dont want that they handle it like textures so that you cant access them directly.. thats just stupid.. i dont need any more functions than THIS ONE!

(hm.. i just have problems to get the gimp functions to work.. then you can download it on my server)

zed
03-29-2001, 01:22 PM
>>IMG* myimg = loadIMG( "mypic.xyz" ); //xyz representing the fileformat
i dont want that they handle it like textures so that you cant access them directly.. thats just stupid.. i dont need any more functions than THIS ONE!<<

check the docs its possible to have access to the images data directly so u can do the gl texture creation yourself. or with openil so all you need is one line to simply load + bind a texture. ive done both so its possible.