Jump to content
  • Advertisement
Sign in to follow this  
JoshuaWaring

OpenGL OpenGL Texture Loading Query

This topic is 1932 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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).

Edited by haegarr

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!