The current backdrop code is quite crude in that it first just tries to
open an image as jpg, and if that fails tries to open it as png. The
attached patch determines the type by the extension, and then opens it
as the correct type right away.
- Gerard
Index: lib/ivis_opengl/screen.c
===================================================================
--- lib/ivis_opengl/screen.c (revision 722)
+++ lib/ivis_opengl/screen.c (working copy)
@@ -399,55 +399,67 @@
{
pie_image image;
iSprite imagePNG;
- BOOL imageLoaded = FALSE;
char * buffer = NULL;
unsigned int dummy = 0;
+ char *extension;
- image_init(&image);
+ // determine the filetype
+ extension = strrchr(filename, '.');
+ if(extension) {
+ extension++;
+ } else {
+ debug(LOG_ERROR, "Image without extension: \"%s\"!", filename);
+ return; // filename without extension... don't bother
+ }
- if (!imageLoaded && !image_load_from_jpg(&image, filename)) {
- if (~backDropTexture == 0) {
- glGenTextures(1, &backDropTexture);
- }
+ if(strcmp(extension,"jpg") == 0 || strcmp(extension,"jpeg") == 0) {
+ image_init(&image);
- glBindTexture(GL_TEXTURE_2D, backDropTexture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
- image.width, image.height,
- 0, GL_RGB, GL_UNSIGNED_BYTE, image.data);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ if (!image_load_from_jpg(&image, filename)) {
+ if (~backDropTexture == 0) {
+ glGenTextures(1, &backDropTexture);
+ }
+
+ glBindTexture(GL_TEXTURE_2D, backDropTexture);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
+ image.width, image.height,
+ 0, GL_RGB, GL_UNSIGNED_BYTE, image.data);
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ }
- imageLoaded = TRUE;
- }
+ image_delete(&image);
+ return;
+ }
- image_delete(&image);
-
- // HACK : We should use a resource handler here!
- if ( !imageLoaded && loadFile( filename, &buffer, &dummy ) && pie_PNGLoadMem( buffer, &imagePNG ) )
- {
- FREE(buffer);
-
- if (~backDropTexture == 0) {
- glGenTextures(1, &backDropTexture);
- }
-
- glBindTexture(GL_TEXTURE_2D, backDropTexture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
- imagePNG.width, imagePNG.height,
- 0, GL_RGBA, GL_UNSIGNED_BYTE, imagePNG.bmp);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
-
- free(imagePNG.bmp);
-
- imageLoaded = TRUE;
- }
+ if(strcmp(extension,"png")==0) {
+ // HACK : We should use a resource handler here!
+ if (loadFile( filename, &buffer, &dummy ) && pie_PNGLoadMem( buffer, &imagePNG ) )
+ {
+ FREE(buffer);
+
+ if (~backDropTexture == 0) {
+ glGenTextures(1, &backDropTexture);
+ }
+
+ glBindTexture(GL_TEXTURE_2D, backDropTexture);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
+ imagePNG.width, imagePNG.height,
+ 0, GL_RGBA, GL_UNSIGNED_BYTE, imagePNG.bmp);
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+
+ free(imagePNG.bmp);
+ }
+ return;
+ }
+ debug(LOG_ERROR, "Unknown extension \"%s\" for image \"%s\"!", extension, filename);
}
//===================================================================
_______________________________________________
Warzone-dev mailing list
[email protected]
https://mail.gna.org/listinfo/warzone-dev