I have executed the following command in order to store a texture (PNG) file in a C++ header file: xxd -i Texture.png Texture.h
.
How would I go about loading this texture into OpenGL?
glEnable(GL_TEXTURE_2D);
GLuint textureId;
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
I realise that the function glTexImage2D
should be used but am very unsure about which parameters to choose.
The specification describes the parameters as shown below.
void glTexImage2D(GLenum target, // GL_TEXTURE_2D
GLint level, // 0
GLint internalFormat, // GL_RGBA
GLsizei width, // 2048
GLsizei height, // 2048
GLint border, // 0
GLenum format, // What's this?
GLenum type, // What's this?
const GLvoid * data);
What are the format
and type
parameters for and what should they be set to in this case?
glTexImage2D
needs image data (array of color values), not an image file like PNG. You'll need a PNG loading function that can take a PNG file format and convert it into an array of colors. The format/type parameters forglTexImage2D
will be the format of that array. \$\endgroup\$xxd
command did that but have now found that it's just a hex dump of the file's data. \$\endgroup\$