/* Raydium - CQFD Corp. http://raydium.org/ License: GPL - GNU General Public License, see "gpl.txt" file. */ #ifndef DONT_INCLUDE_HEADERS #include "index.h" #else #include "headers/shadow.h" #endif #include "shadow.h" void raydium_shadow_init(void) { raydium_shadow_tag=0; raydium_shadow_ground_mesh=-1; raydium_shadow_rendering=0; raydium_log("shadow: OK"); } void raydium_shadow_ground_change(int object) { //modelsize, center factors GLfloat min[3],max[3]; GLfloat tx,ty,tz; GLfloat x,y,z; if(!raydium_object_isvalid(object)) { raydium_log("shadow: ERROR: ground id or name is invalid"); return; } raydium_shadow_ground_mesh=object; raydium_object_find_center_factors(object,&x,&y,&z); raydium_shadow_ground_center_factor_x=0.5-x; raydium_shadow_ground_center_factor_y=0.5-y; raydium_object_find_minmax(object,min,max); tx=max[0]-min[0]; ty=max[1]-min[1]; tz=max[2]-min[2]; raydium_shadow_ground_modelsize=raydium_trigo_max(tx,raydium_trigo_max(ty,tz)); raydium_shadow_ground_modelsize/=2; raydium_log("shadow: ground (%i) modelsize is %.2f, center factors : %.2f/%.2f", raydium_shadow_ground_mesh, raydium_shadow_ground_modelsize, raydium_shadow_ground_center_factor_x, raydium_shadow_ground_center_factor_y); } void raydium_shadow_enable(void) { float S[]={1.0, 0.0, 0.0, 0.0}; float T[]={0.0, 1.0, 0.0, 0.0}; float R[]={0.0, 0.0, 1.0, 0.0}; float Q[]={0.0, 0.0, 0.0, 1.0}; int tmp; if(raydium_shadow_tag) return; raydium_shadow_tag=1; // There was a previous call if(raydium_texture_exists(RAYDIUM_SHADOW_TEXTURE)!=-1) return; tmp=1; while(tmp<=raydium_window_tx && tmp<=raydium_window_ty && tmp<=raydium_texture_size_max) { tmp*=2; } raydium_shadow_map_size=tmp/2; raydium_log("shadow: shadow map size detected to %ix%i",raydium_shadow_map_size,raydium_shadow_map_size); glPushMatrix(); glLoadIdentity(); glTexGenfv(GL_S,GL_EYE_PLANE,S); glTexGenfv(GL_T,GL_EYE_PLANE,T); glTexGenfv(GL_R,GL_EYE_PLANE,R); glTexGenfv(GL_Q,GL_EYE_PLANE,Q); glPopMatrix(); raydium_shadow_texture=raydium_texture_load_internal("",RAYDIUM_SHADOW_TEXTURE,1,raydium_shadow_map_size,raydium_shadow_map_size,4,-1); //raydium_shadow_texture=raydium_texture_load("shadowmap1.tga"); // debug } void raydium_shadow_disable(void) { raydium_shadow_tag=0; } signed char raydium_shadow_isenabled(void) { return raydium_shadow_tag; } void raydium_shadow_light_main(GLuint l) { raydium_shadow_light=l; } void raydium_shadow_object_draw(GLuint o) { #ifndef DEBUG_RENDER_DISABLE_DISPLAYLISTS static GLuint dl[RAYDIUM_MAX_OBJECTS]; static char dl_state[RAYDIUM_MAX_OBJECTS]; static int first=0; int i; if(first) for(i=0;i