📄 ball.c
字号:
} } }}//void create_poolballtex( int nr, int * w, int * h, int * depth, char ** data)void create_balltex( int nr, int * w, int * h, int * depth, char ** data){ int x,y; int bg_r, bg_g, bg_b; int fg_r, fg_g, fg_b; double r_hole; r_hole=60; if(nr<=9) r_hole=50; if(nr==0) r_hole=16; options_col_ball=options_col_ball_pool; fg_r = ((options_col_ball[nr])>>16) & 0xFF; fg_g = ((options_col_ball[nr])>> 8) & 0xFF; fg_b = ((options_col_ball[nr])>> 0) & 0xFF; if(nr==0){ bg_r=0x00; bg_g=0x00; bg_b=0x00; } else { bg_r=0xFF; bg_g=0xFF; bg_b=0xFF; } *w=256; *h=256; *depth=24; *data=malloc((*w)*(*h)*3); /* bg color */ for(y=0;y<*h;y++){ for(x=0;x<*w;x++){ (*data)[(*w*y+x)*3+0]=bg_r; (*data)[(*w*y+x)*3+1]=bg_g; (*data)[(*w*y+x)*3+2]=bg_b; } } /* ball color (strip for half) */ for(y=0;y<*h;y++){ for(x=0;x<*w;x++){ if( nr<9 || (y>=64 && y<=192) ){ (*data)[(*w*y+x)*3+0]=fg_r; (*data)[(*w*y+x)*3+1]=fg_g; (*data)[(*w*y+x)*3+2]=fg_b; } } } /* number circle */ for(y=0;y<*h;y++){ for(x=0;x<*w;x++){ double r,dx,dy,fact; dx=x-(*w)/2; dy=y-(*h)/2; r=sqrt(dx*dx+dy*dy); if(r<r_hole+0.5){ if(r>r_hole-0.5) fact=r-r_hole+0.5; else fact=0.0; (*data)[(*w*y+x)*3+0]=(double)fg_r*fact+(double)bg_r*(1.0-fact); (*data)[(*w*y+x)*3+1]=(double)fg_g*fact+(double)bg_g*(1.0-fact); (*data)[(*w*y+x)*3+2]=(double)fg_b*fact+(double)bg_b*(1.0-fact); } } } /* number */ if(nr!=0){ char str[80]; char * nrdata; int width, height, dw, dh, i, xmin,xmax, ymin,ymax; double sx,sy,sum, sx2,sy2; sprintf(str,"%d",nr); getStringPixmapFT(str, options_ball_fontname, 124, &nrdata, &dw, &dh, &width, &height); sx=0.0; sy=0.0; sum=0.0; xmax=0; xmin=dw; ymax=0; ymin=dh; for(i=0;i<dw*dh;i++){ if(nrdata[i]==(char)0xFF){ if( (i%dw)<xmin ) xmin=(i%dw); if( (i%dw)>xmax ) xmax=(i%dw); if( (i/dw)<ymin ) ymin=(i/dw); if( (i/dw)>ymax ) ymax=(i/dw); } sx+=(double)(i%dw)*(double)((unsigned char)nrdata[i]); sy+=(double)(i/dw)*(double)((unsigned char)nrdata[i]); sum+=(double)((unsigned char)nrdata[i]);// fprintf(stderr,"%d",(unsigned char)nrdata[i]); nrdata[i]=~nrdata[i]; } if(nr==6 || nr==9){ for(y=ymax+5;y<ymax+10;y++){ for(x=xmin+6;x<xmax-6;x++){ nrdata[y*dw+x]=0x00; } } ymax=ymax+10; } sx/=sum; sy/=sum; sx2=(double)(xmin+xmax)/2.0; sy2=(double)(ymin+ymax)/2.0; sx=(sx+sx2)/2.0; sy=(sy+sy2)/2.0;// fprintf(stderr,"sx=%f, sy=%f\n"); my_copy_area_1_3( nrdata, dw, dh, width, height, (*w)/2-(sx+0.5), (*h)/2-(sy+0.5), *data, *w, *h ); } if( options_rgstereo_on ){ int i; double d; /* graying out texture */ for(i=0;i<(*h)*(*w);i++){ d=((unsigned char)(*data)[i*3+0]+ (unsigned char)(*data)[i*3+1]+ (unsigned char)(*data)[i*3+2])/3.0; (*data)[i*3+0]=d; (*data)[i*3+1]=d; (*data)[i*3+2]=d; } }}void create_balltex_snooker( int nr, int * w, int * h, int * depth, char ** data){ int x,y; int bg_r, bg_g, bg_b; int fg_r, fg_g, fg_b; double r_hole; r_hole=16; if(nr>8) nr=1; options_col_ball=options_col_ball_snooker; fg_r = ((options_col_ball[nr])>>16) & 0xFF; fg_g = ((options_col_ball[nr])>> 8) & 0xFF; fg_b = ((options_col_ball[nr])>> 0) & 0xFF; bg_r=0x00; bg_g=0x00; bg_b=0x00; *w=256; *h=256; *depth=24; *data=malloc((*w)*(*h)*3); /* ball color */ for(y=0;y<*h;y++){ for(x=0;x<*w;x++){ (*data)[(*w*y+x)*3+0]=fg_r; (*data)[(*w*y+x)*3+1]=fg_g; (*data)[(*w*y+x)*3+2]=fg_b; } } /* dot */ for(y=0;y<*h;y++){ for(x=0;x<*w;x++){ double r,dx,dy,fact; dx=x-(*w)/2; dy=y-(*h)/2; r=sqrt(dx*dx+dy*dy); if(r<r_hole+0.5){ if(r>r_hole-0.5) fact=r-r_hole+0.5; else fact=0.0; (*data)[(*w*y+x)*3+0]=(double)fg_r*fact+(double)bg_r*(1.0-fact); (*data)[(*w*y+x)*3+1]=(double)fg_g*fact+(double)bg_g*(1.0-fact); (*data)[(*w*y+x)*3+2]=(double)fg_b*fact+(double)bg_b*(1.0-fact); } } } if( options_rgstereo_on ){ int i; double d; /* graying out texture */ for(i=0;i<(*h)*(*w);i++){ d=((unsigned char)(*data)[i*3+0]+ (unsigned char)(*data)[i*3+1]+ (unsigned char)(*data)[i*3+2])/3.0; (*data)[i*3+0]=d; (*data)[i*3+1]=d; (*data)[i*3+2]=d; } }}void create_balltex_carambol( int nr, int * w, int * h, int * depth, char ** data){ int x,y; int bg_r, bg_g, bg_b; int fg_r, fg_g, fg_b; double r_hole; r_hole=16; options_col_ball=options_col_ball_carambol; fg_r = ((options_col_ball[nr])>>16) & 0xFF; fg_g = ((options_col_ball[nr])>> 8) & 0xFF; fg_b = ((options_col_ball[nr])>> 0) & 0xFF; bg_r=0x00; bg_g=0x00; bg_b=0x00; *w=256; *h=256; *depth=24; *data=malloc((*w)*(*h)*3); /* ball color */ for(y=0;y<*h;y++){ for(x=0;x<*w;x++){ (*data)[(*w*y+x)*3+0]=fg_r; (*data)[(*w*y+x)*3+1]=fg_g; (*data)[(*w*y+x)*3+2]=fg_b; } } /* dot */ for(y=0;y<*h;y++){ for(x=0;x<*w;x++){ double r,dx,dy,fact; dx=x-(*w)/2; dy=y-(*h)/2; r=sqrt(dx*dx+dy*dy); if(r<r_hole+0.5){ if(r>r_hole-0.5) fact=r-r_hole+0.5; else fact=0.0; (*data)[(*w*y+x)*3+0]=(double)fg_r*fact+(double)bg_r*(1.0-fact); (*data)[(*w*y+x)*3+1]=(double)fg_g*fact+(double)bg_g*(1.0-fact); (*data)[(*w*y+x)*3+2]=(double)fg_b*fact+(double)bg_b*(1.0-fact); } } } if( options_rgstereo_on ){ int i; double d; /* graying out texture */ for(i=0;i<(*h)*(*w);i++){ d=((unsigned char)(*data)[i*3+0]+ (unsigned char)(*data)[i*3+1]+ (unsigned char)(*data)[i*3+2])/3.0; (*data)[i*3+0]=d; (*data)[i*3+1]=d; (*data)[i*3+2]=d; } }}void free_pooltexbinds( void ){ int i; for(i=0;i<16;i++){ glDeleteTextures(1,&balltexbind[i]); } g_ballset=BALLSET_NONE;}void free_caramboltexbinds( void ){ int i; for(i=0;i<3;i++){ glDeleteTextures(1,&balltexbind[i]); } g_ballset=BALLSET_NONE;}void free_snookertexbinds( void ){ int i; for(i=0;i<8;i++){ glDeleteTextures(1,&balltexbind[i]); } g_ballset=BALLSET_NONE;}void create_pooltex_binds( void ){ char str[80]; int i; g_ballset=BALLSET_POOL; for(i=0;i<16;i++){ glGenTextures(1,&balltexbind[i]); sprintf(str,"billball%02d.png",i); if(options_autocreate_balltex){ create_balltex(i,&balltexw,&balltexh,&depth,&balltexdata[i]); } else { load_png(str,&balltexw,&balltexh,&depth,&balltexdata[i]); } glBindTexture(GL_TEXTURE_2D,balltexbind[i]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, options_tex_min_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, options_tex_mag_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, balltexw, balltexh, GL_RGB, GL_UNSIGNED_BYTE, balltexdata[i]); free(balltexdata[i]); DPRINTF("balltexbind[%d]=%d\n",i,balltexbind[i]); }}void create_caramboltex_binds( void ){ char str[80]; int i; g_ballset=BALLSET_CARAMBOL; for(i=0;i<3;i++){ glGenTextures(1,&balltexbind[i]); sprintf(str,"caramball%02d.png",i); if(options_autocreate_balltex){ create_balltex_carambol(i,&balltexw,&balltexh,&depth,&balltexdata[i]); } else { load_png(str,&balltexw,&balltexh,&depth,&balltexdata[i]); } glBindTexture(GL_TEXTURE_2D,balltexbind[i]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, options_tex_min_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, options_tex_mag_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, balltexw, balltexh, GL_RGB, GL_UNSIGNED_BYTE, balltexdata[i]); free(balltexdata[i]); DPRINTF("balltexbind[%d]=%d\n",i,balltexbind[i]); }}void create_snookertex_binds( void ){ char str[80]; int i; g_ballset=BALLSET_SNOOKER; for(i=0;i<8;i++){ glGenTextures(1,&balltexbind[i]); sprintf(str,"snookerball%02d.png",i); if(options_autocreate_balltex){ create_balltex_snooker(i,&balltexw,&balltexh,&depth,&balltexdata[i]); } else { load_png(str,&balltexw,&balltexh,&depth,&balltexdata[i]); } glBindTexture(GL_TEXTURE_2D,balltexbind[i]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, options_tex_min_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, options_tex_mag_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, balltexw, balltexh, GL_RGB, GL_UNSIGNED_BYTE, balltexdata[i]); free(balltexdata[i]); DPRINTF("balltexbind[%d]=%d\n",i,balltexbind[i]); } for(i=8;i<22;i++){ balltexbind[i]=balltexbind[1]; DPRINTF("balltexbind[%d]=%d\n",i,balltexbind[i]); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -