Search code examples
opengltextures

How to set the Internal format and format for the glTexImage function


I am receiving pixel data in BGRA format.

In order to show the image i need to set this

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1920, 1080, 0, GL_BGRA, GL_UNSIGNED_BYTE, 0);

Initially i was trying

 glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA, 1920, 1080, 0, GL_BGRA, GL_UNSIGNED_BYTE, 0);

my understanding was that the second parameter is the format of the texel data provided to the function and the first is how to store it internally.

Are these formats linked to each other ?


Solution

  • GL_BGRA is not a valid internal format, see glTexImage2D. The format and type parameter specify the format of the source data. The internalformat parameter specifies the format of the target texture image.
    When glTexImage2D is called, then the 2 dimensional texture image is specified and the source image converted to the internalformat of the target.