OpenGL Texture Loading Query

Started by
4 comments, last by 21st Century Moose 10 years, 8 months ago

Okay so I'll get right into it.

I load a texture's data into a char* and each pixel is 4 bytes, what would I be passing to the glTexImage2D would I be passing it GL_RGBA and GL_UNSIGNED_INT_8_8_8_8 or GL_UNSIGNED_BYTE, What would I use to load the texture?

Thank you for any help

Advertisement

GL_RGBA with GL_UNSIGNED_BYTE will work. It means 8 bits per component, where the components are in order red, followed by green, followed by blue, followed by alpha (opacity).

AFAIK: GL_RGBA with GL_UNSIGNED_INT_8_8_8_8 may work. It means that there is a 32 bit word packed with 8 bits each for red, followed by green, followed by blue, followed by alpha. However, the problem is the endianess of the platform in use. It will work if your platform uses big endianess. If, on the other hand, your platform uses little endianess then you have to use GL_RGBA with GL_UNSIGNED_INT_8_8_8_8_REV instead. (May be I'm mixed up little and big endianess here; maybe its the other way around).

Okay so I'll get right into it.

I load a texture's data into a char* and each pixel is 4 bytes, what would I be passing to the glTexImage2D would I be passing it GL_RGBA and GL_UNSIGNED_INT_8_8_8_8 or GL_UNSIGNED_BYTE, What would I use to load the texture?

Thank you for any help

You should pass both GL_RGBA and GL_UNSIGNED_BYTE. GL_RGBA for internal format, GL_RGBA or GL_BGRA_EXT (for Windows) for data format, and GL_UNSIGNED_BYTE for data type.

Thank you, although you two say both will work?

Thank you, although you two say both will work?

Err, not exactly. I say:

* GL_RGBA with GL_UNSIGNED_BYTE will work (this is the way I recommend to use)

* GL_RGBA with GL_UNSIGNED_INT_8_8_8_8 or else GL_RGBA with GL_UNSIGNED_INT_8_8_8_8_REV will work

Please download the OpenGL Specification from Khronos and look at the top of page 181. There the bit patterns of GL_UNSIGNED_INT_8_8_8_8 and GL_UNSIGNED_INT_8_8_8_8_REV are shown. Notice that with GL_RGBA the 1st component is the R.

Just noting here that the GL spec defines absolutely nothing about endianness, but does define a GL_UNPACK_SWAP_BYTES parameter to glPixelStore, which seems a much better way of dealing with it (if it is a problem for you) than changing the parameters to every glTex(Sub)Image call you make. Endianness is certainly not an excuse to declare a moratorium on the 8_8_8_8 formats.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement