Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


OpenGL Texture Loading Query


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Joshhua5   Members   -  Reputation: 1061

Like
0Likes
Like

Posted 05 August 2013 - 11:58 PM

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



Sponsor:

#2 haegarr   Crossbones+   -  Reputation: 6042

Like
0Likes
Like

Posted 06 August 2013 - 12:40 AM

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, 06 August 2013 - 12:45 AM.


#3 Aks9   Members   -  Reputation: 1088

Like
0Likes
Like

Posted 06 August 2013 - 12:42 AM

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.



#4 Joshhua5   Members   -  Reputation: 1061

Like
0Likes
Like

Posted 06 August 2013 - 01:04 AM

Thank you, although you two say both will work?



#5 haegarr   Crossbones+   -  Reputation: 6042

Like
0Likes
Like

Posted 06 August 2013 - 01:44 AM

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.



#6 mhagain   Crossbones+   -  Reputation: 9839

Like
1Likes
Like

Posted 06 August 2013 - 12:37 PM

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS