OpenGL glGetTexImage2d type parameter?

て烟熏妆下的殇ゞ 提交于 2019-12-12 17:02:12

问题


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


回答1:


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).




回答2:


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


来源:https://stackoverflow.com/questions/1543212/opengl-glgetteximage2d-type-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!