GLGETTEXIMAGE(3G)
๐ GLGETTEXIMAGE (3G) โ or, "bestie, give me that texture back"
Hey hi hello ๐ซถ you're looking at the 3G manual page, which means we're deep in OpenGL land. This is glGetTexImage โ the function that reaches into the GPU and yoinks a texture image back out into your own memory. It's giving "I made this, actually give it back" energy. Let's go โจ
๐ธ NAME ๐ธ
glGetTexImage โ return a texture image ๐
โญ C SPECIFICATION โญ
void glGetTexImage( GLenum target,
GLint level,
GLenum format,
GLenum type,
GLvoid *pixels )
No cap, that's the whole signature. Copy it exactly, don't get cute with it ๐
๐ฆ PARAMETERS ๐ฆ
targetโ tells the function which texture you're grabbing. Accepted values areGL_TEXTURE_1D,GL_TEXTURE_2D, andGL_TEXTURE_3D. Like, pick your dimension, bestie ๐levelโ the level-of-detail number of the image you want. Level0is the base image level, and level n is the *n*th mipmap reduction image. So like, level 0 is the main character and the rest are the ever-smaller understudies ๐formatโ specifies a pixel format for the returned data ๐ The supported formats areGL_RED,GL_GREEN,GL_BLUE,GL_ALPHA,GL_RGB,GL_BGR,GL_RGBA,GL_BGRA,GL_LUMINANCE, andGL_LUMINANCE_ALPHA.typeโ specifies a pixel type for the returned data โจ The supported types areGL_UNSIGNED_BYTE,GL_BYTE,GL_UNSIGNED_SHORT,GL_SHORT,GL_UNSIGNED_INT,GL_INT,GL_FLOAT,GL_UNSIGNED_BYTE_3_3_2,GL_UNSIGNED_BYTE_2_3_3_REV,GL_UNSIGNED_SHORT_5_6_5,GL_UNSIGNED_SHORT_5_6_5_REV,GL_UNSIGNED_SHORT_4_4_4_4,GL_UNSIGNED_SHORT_4_4_4_4_REV,GL_UNSIGNED_SHORT_5_5_5_1,GL_UNSIGNED_SHORT_1_5_5_5_REV,GL_UNSIGNED_INT_8_8_8_8,GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2, andGL_UNSIGNED_INT_2_10_10_10_REV. Yes that's a lot of them. Yes you should still read them all. Periodt ๐pixelsโ returns the texture image ๐ Should be a pointer to an array of the type specified bytype. That's your destination, your little receiving basket ๐งบ
๐ฅ DESCRIPTION ๐ฅ
So glGetTexImage returns a texture image into pixels. target specifies whether the desired texture image is the one specified by glTexImage1D (GL_TEXTURE_1D), glTexImage2D (GL_TEXTURE_2D), or glTexImage3D (GL_TEXTURE_3D). level specifies the level-of-detail number of the desired image. format and type specify the and type of the desired image array โ and yes, that sentence reads a lil cursed in the original too, we're keeping it real ๐ โ see the reference pages glTexImage1D and glDrawPixels for a description of the acceptable values for the format and type parameters, respectively.
Okay so to actually understand how glGetTexImage works, picture the selected internal four-component texture image as an RGBA color buffer that's the size of the image ๐ผ๏ธ Once you do that, the semantics of glGetTexImage are identical to those of glReadPixels, with one exception: no pixel transfer operations are performed, when called with the same format and type, with x and y set to 0, width set to the width of the texture image (including border if one was specified), and height set to 1 for 1D images, or to the height of the texture image (including border if one was specified) for 2D images. Literally identical energy, just no pixel transfers โจ
And since the internal texture image is an RGBA image, the pixel formats GL_COLOR_INDEX, GL_STENCIL_INDEX, and GL_DEPTH_COMPONENT are not accepted, and pixel type GL_BITMAP is not accepted. Not invited to the party, sorry babes ๐
Now โ if the selected texture image doesn't have four components, the following mappings get applied. Write these down, they're on the quiz ๐
- Single-component textures are treated as RGBA buffers with red set to the single-component value, green set to
0, blue set to0, and alpha set to1. - Two-component textures are treated as RGBA buffers with red set to the value of component zero, alpha set to the value of component one, and green and blue set to
0. - Three-component textures are treated as RGBA buffers with red set to component zero, green set to component one, blue set to component two, and alpha set to
1.
Slay, the math is mathing ๐
To figure out the required size of pixels, use glGetTexLevelParameter to determine the dimensions of the internal texture image, then scale the required number of pixels by the storage required for each pixel, based on format and type ๐งฎ And be sure to take the pixel storage parameters into account, especially GL_PACK_ALIGNMENT โ this is the classic "why is my image skewed" bug, iykyk ๐ญ
๐ NOTES ๐
- If an error is generated, no change is made to the contents of
pixels. Your buffer stays exactly as it was ๐ - When the
GL_ARB_multitextureextension is supported,glGetTexImagereturns the texture image for the active texture unit ๐ - The types
GL_UNSIGNED_BYTE_3_3_2,GL_UNSIGNED_BYTE_2_3_3_REV,GL_UNSIGNED_SHORT_5_6_5,GL_UNSIGNED_SHORT_5_6_5_REV,GL_UNSIGNED_SHORT_4_4_4_4,GL_UNSIGNED_SHORT_4_4_4_4_REV,GL_UNSIGNED_SHORT_5_5_5_1,GL_UNSIGNED_SHORT_1_5_5_5_REV,GL_UNSIGNED_INT_8_8_8_8,GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,GL_UNSIGNED_INT_2_10_10_10_REV, and the formatsGL_BGRandGL_BGRAare available only if the GL version is 1.2 or greater. Gatekeeping, honestly ๐ช
๐ ERRORS ๐
GL_INVALID_ENUMis generated iftarget,format, ortypeis not an accepted value. Wrong word, wrong vibe check ๐ซGL_INVALID_VALUEis generated iflevelis less than0. Negative levels are not a thing, bestie ๐GL_INVALID_VALUEmay be generated iflevelis greater than log2*max*, where max is the returned value ofGL_MAX_TEXTURE_SIZE. "May" โ so like, don't push it ๐ธGL_INVALID_OPERATIONis generated ifglGetTexImageis executed between the execution ofglBeginand the corresponding execution ofglEnd. Do not do the thing inside the other thing ๐คGL_INVALID_OPERATIONis returned iftypeis one ofGL_UNSIGNED_BYTE_3_3_2,GL_UNSIGNED_BYTE_2_3_3_REV,GL_UNSIGNED_SHORT_5_6_5, orGL_UNSIGNED_SHORT_5_6_5_REVandformatis notGL_RGB.GL_INVALID_OPERATIONis returned iftypeis one ofGL_UNSIGNED_SHORT_4_4_4_4,GL_UNSIGNED_SHORT_4_4_4_4_REV,GL_UNSIGNED_SHORT_5_5_5_1,GL_UNSIGNED_SHORT_1_5_5_5_REV,GL_UNSIGNED_INT_8_8_8_8,GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2, orGL_UNSIGNED_INT_2_10_10_10_REV, andformatis neitherGL_RGBAorGL_BGRA.
Okay real talk: those last two are the pairing rules and they are strict. Mismatchedtype/formatcombos are an instantGL_INVALID_OPERATION, no negotiation, no vibes ๐ซถ
๐ง ASSOCIATED GETS ๐ง
glGetTexLevelParameterwith argumentGL_TEXTURE_WIDTHglGetTexLevelParameterwith argumentGL_TEXTURE_HEIGHTglGetTexLevelParameterwith argumentGL_TEXTURE_BORDERglGetTexLevelParameterwith argumentGL_TEXTURE_INTERNALFORMATglGetwith argumentsGL_PACK_ALIGNMENTand others
These are the little info-gathering besties that tell you what you're working with ๐
๐ SEE ALSO ๐
glActiveTextureARB(3G), glDrawPixels(3G), glReadPixels(3G), glTexEnv(3G), glTexGen(3G), glTexImage1D(3G), glTexImage2D(3G), glTexImage3D(3G), glTexSubImage1D(3G), glTexSubImage2D(3G), glTexSubImage3D(3G), glTexParameter(3G)
The whole friend group, honestly ๐ฏโโ๏ธ
And that's the whole page, bestie โ you ate that ๐
โจ This one goes out from GLGETTEXIMAGE(3G), filed under the 3G manual, so go forth and grab those textures. ๐ฆ๐
๐ฆ where this page comes from
- opensuse-leap 16.0: Mesa-libGL-devel 24.1.7-160000.3.1 ยท MIT
- opensuse-leap 16.0: Mesa-libGL-devel 24.3.3-160000.3.1 ยท MIT
- opensuse-leap 16.0: Mesa-libGL-devel 24.3.3-160000.3.1 ยท MIT
- opensuse-leap 16.0: Mesa-libGL-devel 24.3.3-160000.3.1 ยท MIT
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms