loading an image

Started by
15 comments, last by apocalexiz 20 years, 9 months ago
ya i know that open gl knows nothing...but i have to provide information to open gl so that the image data will be used in the way that i want to see

bye
Advertisement
Targa is usually stored bottom-to-top, just like OpenGL wants it (t == 0 is bottom; t == 1 is top). OpenGL needs 4-byte-aligned data for optimal performance. Targa stores data in BGRA order, which is optimal to upload as-is.

file = fopen( "my_stupid_image.tga", "rb" );unsigned short header[ 9 ];fread( header, 2, 9, file );assert( (header[ 8 ] & 0x3f) == 32 );unsigned int width = header[ 6 ];unsigned int height = header[ 7 ];assert( !(width & (width-1)) );assert( !(height & (height-1)) );unsigned int * data = new unsigned int[ width*height ];fread( data, 4, width*height, file );fclose( file );// I forget the exact order of the argumentsglTexImage2D( 0, GL_RGBA8, width, height, GL_BGRA8, GL_UNSIGNED_CHAR, data );delete[] data; 

The GL_BGRA8 should be plain GL_BGRA because the size is given by the GL_UNSIGNED_BYTE argument. The first argument should be GL_RGBA8, as indicated, to tell GL what components matter and what size to use per component.
anonymouse
**********

this is the "very old" tga file format, isnt it? my documentation says something different about the header

how do i the 4 byte alignment? is this just a linker setting? or is there something that i have to put into my sourcecode (i would prefer the second method)

bye
I've never heard about the 4 byte alignment before, but it should just happen automatically for you since your textures need to be powers of two in width and height (you know that right?).

Also, you may have to swap the red and blue channels of your texture around to get the colours to come out right, but that's of course work to be done AFTER you get anything at all being sent to OpenGL.

Why you shouldn't use iostream.h - ever! | A Good free online C++ book

[edited by - siaspete on July 6, 2003 5:54:50 PM]
sisapete
********
i guess the 4byte alignment is for faster accessing memory (the thing with the adresses) on intel machines...but u waste 1 byte per pixel

and yes i know that the texture need to be a power of 2

anonymous
*********

ah...sorry i overread the short int... headersize is 18 bytes...and yes tga files (32bit) will be stored in bgra format


thx for help

bye

quote:Original post by apocalexiz
sisapete
********
i guess the 4byte alignment is for faster accessing memory (the thing with the adresses) on intel machines...but u waste 1 byte per pixel


Ah, this is not true. I wrote a TGA loader a while ago, and 24-bit images are stored tightly packed.

Why you shouldn''t use iostream.h - ever! | A Good free online C++ book

This topic is closed to new replies.

Advertisement