If this is a single frame splash image with no animations, then there's no harm using glDrawPixels
. If performance is crucial and you are required to use a texture, then the correct way to do it is to determine at runtime, the maximum supported texture size, using a proxy texture.
GLint width = 0;
while ( 0 == width ) { /* use a better condition to prevent possible endless loop */
glTexImage2D(GL_PROXY_TEXTURE_2D,
0, /* mip map level */
GL_RGBA, /* internal format */
desiredWidth, /* width of image */
desiredHeight, /* height of image */
0, /* texture border */
GL_RGBA /* pixel data format, */
GL_UNSIGNED_BYTE, /* pixel data type */
NULL /* null pointer because this a proxy texture */
);
/* the queried width will NOT be 0, if the texture format is supported */
glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
desiredWidth /= 2; desiredHeight /= 2;
}
Once you know the maximum texture size supported by the system's OpenGL driver, you have at least two options if your image doesn't fit:
- Image tiling: use multiple quads after splitting your image into smaller supported chunks. Image tiling for something like a splash screen should not be too tricky. You can use glPixelStorei's
GL_PACK_ROW_LENGTH
parameter to load sections of a larger image into a texture.
- Image resizing: resize your image to fit the maximum supported texture size. There's even a GLU helper function to do this for you, gluScaleImage.