Well, meanwhile someone do something with the official code, I 've done a (more or less) working test.
It compiles and works with simple textures, and environment, and lightmap textures (as long as I tested). The plain rgb textures and fonts are working wrong. I don't understand well the video textures so I didn't code them...
The good point, as this code uses SOIL you can load almost any image format file (jpeg, tga,psd,dds...).
This should +- work for people asking me for more image files, but there is place for a loooot of improvements and bugfixes.
odyncomp.sh
(just added the library for compiling)
Code:
...
$CC "$1" -g -Wall -DFORCE_LIBRAYDIUM -o test libraydium.so \
-Iraydium/php/ -Isoil/src/ -Iraydium/php/main/ -Iraydium/php/Zend -Iraydium/php/TSRM \
-Iraydium/ode/include/ libSOIL.a $AR_PATH_INCLUDE $AR_PATH_LIBS $LIBWII_PATH_INCLUDE $LIBWII_ADDS $ODYNCOMP_FLAGS
...
texture.c
(Just new include and full rewrite of raydium_texture_load_internal function)
Code:
...
#include "../soil/src/SOIL.h"
...
...
GLuint
raydium_texture_load_internal (char *filename, char *as, signed char faked,
int faked_tx, int faked_ty, int faked_bpp,
int or_live_id_fake)
{
//VARIABLES
int id = -1;
int tex_2d = 0;
int simulate = 0;
int rgb = 0;
int reflect = 0;
int lightmap = 0;
int hdr = 0;
int nolight = 0;
int blended = 0;
int infox = 0;
int infoy = 0;
int infocomp = 0;
int cutout = 0;
float r = 0.0f;
float g = 0.0f;
float b = 0.0f;
unsigned char filename2[RAYDIUM_MAX_NAME_LEN];
unsigned char temp[RAYDIUM_MAX_NAME_LEN];
unsigned char *img;
unsigned int soil_flags = SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT;
/*flags
SOIL_FLAG_POWER_OF_TWO
SOIL_FLAG_MIPMAPS
SOIL_FLAG_TEXTURE_REPEATS
SOIL_FLAG_MULTIPLY_ALPHA
SOIL_FLAG_INVERT_Y
SOIL_FLAG_COMPRESS_TO_DXT
SOIL_FLAG_DDS_LOAD_DIRECT
*/
//ALREADY LOADED? SKIP
//check if already loaded
for (id = 1; id < RAYDIUM_MAX_TEXTURES; id++)
{
if (raydium_texture_used[id])
{
if (!strcmp (raydium_texture_name[id], as))
{
raydium_log ("texture: (internal) %s is duplicated", as);
return id;
}
}
}
//is not already loaded
//REPLACE TEXTURE OR NEW TEXTURE
if (raydium_texture_to_replace)
{
id = raydium_texture_to_replace;
//TODO:WARNING: Not tested!!!!
raydium_texture_free (raydium_texture_to_replace);
raydium_texture_to_replace = 0;
}
else
{
//check if there is one texture slot free
id = raydium_texture_get_next_free_slot_internal ();
}
if ((int) id == -1) //Not free slot :(
{
raydium_log ("texture: No more texture slots left ! (%i max)",
RAYDIUM_MAX_TEXTURES);
return 0;
}
//SIMULATING? (what is this for?....)
//check if needed to simulate
if (raydium_window_mode == RAYDIUM_RENDERING_NONE)
{
simulate = 1;
}
//RGB COLOR
//check if it's a plain color
strcpy ((char *) temp, filename);
temp[4] = 0;
//Is an RGB color?
if (!strcmp ("rgb(", (char *) temp))
{
rgb = 1;
//
sscanf (filename, "rgb(%f,%f,%f)", &r, &g, &b);
raydium_texture_rgb[id][0] = r;
raydium_texture_rgb[id][1] = g;
raydium_texture_rgb[id][2] = b;
raydium_texture_rgb[id][3] = 1.f;
if (r < 0 && g < 0 && b < 0)
{
blended = RAYDIUM_TEXTURE_PHANTOM;
raydium_log ("Tex. num %i is Phantom (depth buffer only)", id);
}
else
{
blended = 0;
raydium_log ("Tex. num %i, rgb(%f,%f,%f) is RGB Color", id, r, g,
b);
}
}
else if (!faked)
//IT'S AN IMAGE
{
rgb = 0;
//ENV
//check if environment map
strcpy ((char *) temp, filename);
temp[3] = 0;
//Check if it's an ENV mapping texture?
if (!strcmp ("ENV", (char *) temp))
{
reflect = 1;
}
//check if Nonpoweroftwo textures are used
if (!raydium_texture_use_npot_textures ||
(!glutExtensionSupported ("GL_ARB_texture_non_power_of_two") &&
!glutExtensionSupported ("GL_ARB_texture_rectangle")))
{
soil_flags = soil_flags | SOIL_FLAG_POWER_OF_TWO;
}
//LIGHTMAP
if (strstr (filename, ".tri."))
{
lightmap = 1;
}
//DDS
if (strstr (filename, ".dds"))
{
//soil_flags=SOIL_FLAG_INVERT_Y | SOIL_FLAG_MIPMAPS ;
}
//HDR
memcpy (temp, filename, 3);
if (!strcmp ("HDR", (char *) temp)) // TEMP !!
{
hdr = 1;
nolight = 1;
}
//BOX
memcpy (temp, filename, 3);
temp[3] = 0;
if (!strcmp ("BOX", (char *) temp) || faked)
{
soil_flags = soil_flags;
}
else
{
soil_flags = soil_flags | SOIL_FLAG_TEXTURE_REPEATS;
}
//LOAD TEXTURE
//resolve filename
raydium_path_resolv (as, filename2, 'r'); //resolv the name of the image
raydium_log ("SOIL goes to load %s", filename2);
//GET IMAGE INFO
img = SOIL_load_image (filename2, &infox, &infoy, &infocomp, 0);
SOIL_free_image_data (img); //TODO: Waste of time....
raydium_log ("Image has size %dx%d with %d channels", infox, infoy,
infocomp);
//load texture into id slot
if (!simulate)
id = SOIL_load_OGL_texture
(filename2, SOIL_LOAD_AUTO, id, soil_flags);
//check texture slot after load
if (id == 0)
{
raydium_log ("About texture file: %s ( %s )", as, filename2);
raydium_log ("SOIL loading error: '%s'\n", SOIL_last_result ());
}
else
{
raydium_log ("Textures loaded ok!. Message: %s",
SOIL_last_result ());
}
//in this point the texture has been succesfully loaded
//check channels
switch (infocomp) //How many channels?
{
case 0:
break;
case 1: //GREY
soil_flags =
soil_flags | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_MIPMAPS;
blended = 1;
break;
case 2: // just 2 channels???
soil_flags = soil_flags | SOIL_FLAG_MIPMAPS;
break;
case 3: //RGB
soil_flags = soil_flags | SOIL_FLAG_MIPMAPS;
break;
case 4: //RGBA
soil_flags =
soil_flags | SOIL_FLAG_MIPMAPS | SOIL_FLAG_MULTIPLY_ALPHA;
if (temp[3] > 0 && temp[3] < 255)
blended = 1;
if (temp[3] == 0)
cutout = 1;
break;
default:
break;
}
}
else //It's a faked image
{
//TODO: I gues...
return 0;
}
//store its name
strcpy (raydium_texture_name[id], as);
//check if it has HDR
raydium_texture_hdr[id] = hdr;
//check if the texture ignores the light
raydium_texture_nolight[id] = nolight;
//check if the texture is part of an environment
raydium_texture_env[id] = reflect;
//check the size of the texture
raydium_texture_memory[id] = infox * infoy * infocomp; //TODO:wrong approximation
//check if it's a lightmap
raydium_texture_islightmap[id] = lightmap;
//check if it's a blender texture
if (cutout && !blended)
{
blended = 2;
}
raydium_texture_blended[id] = blended;
//mark its slot as used
raydium_texture_used[id] = 1;
//returns id of the used slot
return id;
}
...
Xfennec: Indented with (GNU) indent application sorry, no time for manual indentation right now