void light_map_textures_save(char *base_path) { int n,txt_idx; char map_name[256],bitmap_name[256],path[1024],str[256]; // delete any old textures map_delete_texture(&map,(max_map_texture-light_map_max_textures),max_map_texture); // get better name light_map_texture_map_folder_name(map_name); // write textures txt_idx=max_map_texture-light_map_max_textures; for (n=0;n!=light_map_texture_count;n++) { sprintf(str,"Light Map: Saving Textures %d/%d",(n+1),light_map_texture_count); progress_next_title(str); if (light_map_textures[n].pixel_data==NULL) break; // some setup sprintf(map.textures[txt_idx].material_name,"Light Map %.3d",n); map.textures[txt_idx].shader_name[0]=0x0; map.textures[txt_idx].additive=FALSE; map.textures[txt_idx].compress=FALSE; // save bitmap sprintf(bitmap_name,"LightMaps/%s/lm%.3d",map_name,n); sprintf(path,"%s/%s.png",base_path,bitmap_name); bitmap_write_png_data(light_map_textures[n].pixel_data,light_map_pixel_size,light_map_pixel_size,FALSE,path); // put in texture list map_replace_texture(&map,txt_idx,bitmap_name); txt_idx++; } }
bool gl_screen_shot(int lft_x,int top_y,int wid,int high,bool thumbnail,char *path) { int x,y,x_skip,y_skip, ss_wid,ss_high,dsz; unsigned char *pixel_buffer,*data,*sptr,*dptr,*s2ptr,*d2ptr; bool ok; pixel_buffer=(unsigned char*)malloc((wid*3)*high); if (pixel_buffer==NULL) return(FALSE); glReadPixels(lft_x,top_y,wid,high,GL_RGB,GL_UNSIGNED_BYTE,pixel_buffer); // is there a limiting? x_skip=y_skip=1; ss_wid=wid; ss_high=high; if (thumbnail) { x_skip=wid/128; y_skip=high/128; ss_wid=ss_high=128; } // flip the data dsz=((ss_wid*3)*ss_high); data=(unsigned char*)malloc(dsz); if (data==NULL) { free(pixel_buffer); return(FALSE); } bzero(data,dsz); sptr=pixel_buffer; dptr=data+((ss_high-1)*(ss_wid*3)); for (y=0;y!=ss_high;y++) { s2ptr=sptr; d2ptr=dptr; for (x=0;x!=ss_wid;x++) { *d2ptr++=*s2ptr++; *d2ptr++=*s2ptr++; *d2ptr++=*s2ptr++; s2ptr+=((x_skip-1)*3); } sptr+=((wid*3)*y_skip); dptr-=(ss_wid*3); } free(pixel_buffer); // save screenshot ok=bitmap_write_png_data(data,ss_wid,ss_high,FALSE,path); free(data); return(ok); }
bool gl_screen_shot(int lft_x,int top_y,int wid,int high,bool thumbnail,char *path) { int x,y,ss_wid,ss_high,dsz; float x_off,y_off,x_add,y_add; unsigned char *pixel_buffer,*data,*sptr,*dptr,*s2ptr,*d2ptr; bool ok; pixel_buffer=(unsigned char*)malloc((wid*3)*high); if (pixel_buffer==NULL) return(FALSE); glReadPixels(lft_x,top_y,wid,high,GL_RGB,GL_UNSIGNED_BYTE,pixel_buffer); // is this is a thumbnail, // then reduce the picture (but keep // the dimensions) x_add=y_add=1.0f; ss_wid=wid; ss_high=high; dsz=(wid*3)*high; if (thumbnail) { x_add=((float)wid)/512.0f; ss_wid=512; ss_high=(high*512)/wid; y_add=((float)high)/((float)ss_high); dsz=(ss_wid*3)*ss_high; } // flip the data data=(unsigned char*)malloc(dsz); if (data==NULL) { free(pixel_buffer); return(FALSE); } bzero(data,dsz); y_off=0.0f; dptr=data+((ss_high-1)*(ss_wid*3)); for (y=0;y!=ss_high;y++) { x_off=0.0f; sptr=pixel_buffer+(((int)y_off)*(wid*3)); d2ptr=dptr; for (x=0;x!=ss_wid;x++) { s2ptr=sptr+(((int)x_off)*3); *d2ptr++=*s2ptr; *d2ptr++=*(s2ptr+1); *d2ptr++=*(s2ptr+2); x_off+=x_add; } dptr-=(ss_wid*3); y_off+=y_add; } free(pixel_buffer); // save screenshot ok=bitmap_write_png_data(data,ss_wid,ss_high,FALSE,path); free(data); return(ok); }
bool liquid_reflection_map_run_for_liquid(int txt_idx,int liq_idx,char *base_path,char *map_name,char *err_str) { int x,z,x_add,z_add,sz,pixel_size; unsigned char *pixel,*pixel_data,uc_alpha; char path[1024],bitmap_name[256]; d3pnt spt,ept,center; d3col col; map_liquid_type *liq; // get the liquid to render liq=&map.liquid.liquids[liq_idx]; pixel_size=(int)pow(2,(liq->reflect.texture_size+8)); // get the pixel data for texture sz=(pixel_size*pixel_size)*4; pixel_data=(unsigned char*)malloc(sz); bzero(pixel_data,sz); uc_alpha=(unsigned char)((int)(liq->reflect.alpha*255.0f)); // get scan ratio x_add=((liq->rgt-1)-liq->lft)/pixel_size; z_add=((liq->bot-1)-liq->top)/pixel_size; center.x=(liq->lft+liq->rgt)>>1; center.z=(liq->top+liq->bot)>>1; // scan through the quad pixel=pixel_data; spt.y=liq->y; spt.z=liq->top; for (z=0;z!=pixel_size;z++) { spt.x=liq->lft; for (x=0;x!=pixel_size;x++) { // create the ray. The further from // the center, the more it slants out ept.x=spt.x+(((spt.x-center.x)*liq->reflect.x_refract_factor)/(center.x-liq->lft)); ept.y=spt.y-liquid_reflection_mirror_distance; ept.z=spt.z+(((spt.z-center.z)*liq->reflect.z_refract_factor)/(center.z-liq->top)); // run the ray trace memmove(&col,&liq->reflect.no_hit_col,sizeof(d3col)); liquid_reflection_map_ray_trace_map(&spt,&ept,&col); // set color *pixel++=(unsigned char)((int)(col.r*255.0f)); *pixel++=(unsigned char)((int)(col.g*255.0f)); *pixel++=(unsigned char)((int)(col.b*255.0f)); *pixel++=uc_alpha; spt.x+=x_add; } spt.z+=z_add; } // save the texture sprintf(map.textures[txt_idx].material_name,"Light Map %.3d",liq_idx); map.textures[txt_idx].shader_name[0]=0x0; map.textures[txt_idx].additive=FALSE; map.textures[txt_idx].compress=FALSE; // save bitmap sprintf(bitmap_name,"ReflectionMaps/%s/rm%.3d",map_name,liq_idx); sprintf(path,"%s/%s.png",base_path,bitmap_name); bitmap_write_png_data(pixel_data,pixel_size,pixel_size,TRUE,path); liq->txt_idx=txt_idx; liq->flag.lock_uv=TRUE; liq->main_uv.offset.x=liq->main_uv.offset.y=0.0f; liq->main_uv.size.x=liq->main_uv.size.y=1.0f; // put in texture list map_replace_texture(&map,txt_idx,bitmap_name); return(TRUE); }