views:

107

answers:

2

Hi,

reading the docs i see that the glGetTexImage2d() function has a 'type' parameter. The docs say that the type parameter "specifies the data type of the pixel data" and gives some examples of types such as GL_INT, GL_BYTE, etc.

but what does it mean precisely when the image format is GL_RGBA and GL_INT ? is it an int for each channel? or an int for the whole color? and if it's an int for th whole color, then isn't that really the same as GL_BYTE ? since there's 4 bytes in an int which makes each channel a byte each

Thanks in advance,

+2  A: 

The type parameter specifies the effective type of the data inside the buffer you're sending to OpenGL.

The aim here is that OpenGL is going to walk in your buffer, and want to know how much elements are present ( width * height * internalformat ) and their size & interpretation (type).

For instance, if you are to provide an array of unsigned ints containing red/green/blue/alpha channels (in this order), you'll need to specify:

  • target: GL_TEXTURE_2D
  • level: 0 (except if you use mipmaps)
  • internalformat: 4 because you have red, green, blue and alpha
  • width: 640
  • height: 480
  • border: 0
  • internal format: GL_RGBA to tell opengl the order of our channels, and what they mean
  • type: GL_UNSIGNED_INT will let opengl know the type of elements inside our array
  • pixels: a pointer to your array
Aurélien Vallée
so when i specify GL_UNSIGNED_INT then each and every color component (r, g, b, a ) is an int (i.e 32 bits) or just the color as a 'whole' is 32 bits?
banister
Yep, when specifying GL_UNSIGNED_INT each element (channel) is an unsigned integer.
Aurélien Vallée
+2  A: 

It's an int per channel. RGBA means each pixel has R, G, B and A ints (if you set it to int) in the data-array you're giving it. RBGA (if it exists, not sure of that) would also mean four ints, but ordered differently. RGB would mean just three (no alpha channel).

roe