I\'ve had this problem a couple of times. Let\'s say I want to display a splash-screen or something in an OpenGL context (or DirectX for that matter, it\'s more of a conceptual
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:
GL_PACK_ROW_LENGTH
parameter to load sections of a larger image into a texture.I don't think there is a built-in opengl function, but you might find a library (or write the function yourself) to break the image down into smaller chunks and then print to screen the smaller chunks (128x128 tiles or similar).
I had problem with this using Slick2D for a Java game. You can check out their "BigImage" class for ideas here.