00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "Teddy/Graphics/Device.h"
00026 #include "Teddy/Graphics/Texture.h"
00027 #include "Teddy/Materials/Material.h"
00028 #include "Teddy/PhysicalComponents/Projection.h"
00029 #include "Teddy/SysSupport/Messages.h"
00030 #include "Teddy/SysSupport/StdIO.h"
00031 using namespace Teddy::Graphics;
00032 using namespace Teddy::SysSupport;
00033
00034
00035 namespace Teddy {
00036 namespace Materials {
00037
00038
00039 const unsigned long Material::RENDER_MODE_POINT =0x01;
00040 const unsigned long Material::RENDER_MODE_LINE =0x02;
00041 const unsigned long Material::RENDER_MODE_FILL =0x03;
00042 const unsigned long Material::RENDER_MODE_FILL_OUTLINE =0x04;
00043
00044 const unsigned long Material::RENDER_LIGHTING_COLOR =0x01;
00045 const unsigned long Material::RENDER_LIGHTING_CUSTOM =0x02;
00046 const unsigned long Material::RENDER_LIGHTING_PRIMARY_LIGHT_ONLY =0x03;
00047 const unsigned long Material::RENDER_LIGHTING_SIMPLE =0x04;
00048 const unsigned long Material::RENDER_LIGHTING_FULL =0x05;
00049
00050 const unsigned long Material::RENDER_OPTION_RESERVED = 0l ;
00051 const unsigned long Material::RENDER_OPTION_SMOOTH = 1l ;
00052 const unsigned long Material::RENDER_OPTION_CULL_FACE = 2l ;
00053 const unsigned long Material::RENDER_OPTION_BLEND = 3l ;
00054 const unsigned long Material::RENDER_OPTION_FOG = 4l ;
00055 const unsigned long Material::RENDER_OPTION_NORMALIZE = 5l ;
00056 const unsigned long Material::RENDER_OPTION_ALPHA_TEST = 6l ;
00057 const unsigned long Material::RENDER_OPTION_DEPTH_TEST = 7l ;
00058 const unsigned long Material::RENDER_OPTION_STENCIL_TEST = 8l ;
00059 const unsigned long Material::RENDER_OPTION_SCISSOR_TEST = 9l ;
00060 const unsigned long Material::RENDER_OPTION_TEXTURE_1D =10l ;
00061 const unsigned long Material::RENDER_OPTION_TEXTURE_2D =11l ;
00062 const unsigned long Material::RENDER_OPTION_TEXTURE_3D =12l ;
00063 const unsigned long Material::RENDER_OPTION_POINT_SMOOTH =13l ;
00064 const unsigned long Material::RENDER_OPTION_LINE_SMOOTH =14l ;
00065 const unsigned long Material::RENDER_OPTION_POLYGON_SMOOTH =15l ;
00066 const unsigned long Material::RENDER_OPTION_AMBIENT =16l ;
00067 const unsigned long Material::RENDER_OPTION_DIFFUSE =17l ;
00068 const unsigned long Material::RENDER_OPTION_SPECULAR =18l ;
00069 const unsigned long Material::RENDER_OPTION_EMISSION =19l ;
00070 const unsigned long Material::RENDER_OPTION_SHINYNESS =20l ;
00071 const unsigned long Material::RENDER_OPTION_BORDER =21l ;
00072 const unsigned long Material::RENDER_OPTION_REMOVE_HIDDEN =22l ;
00073 const unsigned long Material::RENDER_OPTION_FRUSTUM_CULL =23l ;
00074 const unsigned long Material::RENDER_OPTION_SORT_OBJECTS =24l ;
00075 const unsigned long Material::RENDER_OPTION_SORT_ELEMENTS =25l ;
00076 const unsigned long Material::RENDER_OPTION_COLOR_MATERIAL =26l ;
00077 const unsigned long Material::RENDER_OPTION_MASTER_LIGHTING_ONLY =27l ;
00078
00079 const unsigned long Material::RENDER_OPTION_RESERVED_M = (1l<<RENDER_OPTION_RESERVED ) ;
00080 const unsigned long Material::RENDER_OPTION_SMOOTH_M = (1l<<RENDER_OPTION_SMOOTH ) ;
00081 const unsigned long Material::RENDER_OPTION_CULL_FACE_M = (1l<<RENDER_OPTION_CULL_FACE ) ;
00082 const unsigned long Material::RENDER_OPTION_BLEND_M = (1l<<RENDER_OPTION_BLEND ) ;
00083 const unsigned long Material::RENDER_OPTION_FOG_M = (1l<<RENDER_OPTION_FOG ) ;
00084 const unsigned long Material::RENDER_OPTION_NORMALIZE_M = (1l<<RENDER_OPTION_NORMALIZE ) ;
00085 const unsigned long Material::RENDER_OPTION_ALPHA_TEST_M = (1l<<RENDER_OPTION_ALPHA_TEST ) ;
00086 const unsigned long Material::RENDER_OPTION_DEPTH_TEST_M = (1l<<RENDER_OPTION_DEPTH_TEST ) ;
00087 const unsigned long Material::RENDER_OPTION_STENCIL_TEST_M = (1l<<RENDER_OPTION_STENCIL_TEST ) ;
00088 const unsigned long Material::RENDER_OPTION_SCISSOR_TEST_M = (1l<<RENDER_OPTION_SCISSOR_TEST ) ;
00089 const unsigned long Material::RENDER_OPTION_TEXTURE_1D_M = (1l<<RENDER_OPTION_TEXTURE_1D ) ;
00090 const unsigned long Material::RENDER_OPTION_TEXTURE_2D_M = (1l<<RENDER_OPTION_TEXTURE_2D ) ;
00091 const unsigned long Material::RENDER_OPTION_TEXTURE_3D_M = (1l<<RENDER_OPTION_TEXTURE_3D ) ;
00092 const unsigned long Material::RENDER_OPTION_POINT_SMOOTH_M = (1l<<RENDER_OPTION_POINT_SMOOTH ) ;
00093 const unsigned long Material::RENDER_OPTION_LINE_SMOOTH_M = (1l<<RENDER_OPTION_LINE_SMOOTH ) ;
00094 const unsigned long Material::RENDER_OPTION_POLYGON_SMOOTH_M = (1l<<RENDER_OPTION_POLYGON_SMOOTH ) ;
00095 const unsigned long Material::RENDER_OPTION_AMBIENT_M = (1l<<RENDER_OPTION_AMBIENT ) ;
00096 const unsigned long Material::RENDER_OPTION_DIFFUSE_M = (1l<<RENDER_OPTION_DIFFUSE ) ;
00097 const unsigned long Material::RENDER_OPTION_SPECULAR_M = (1l<<RENDER_OPTION_SPECULAR ) ;
00098 const unsigned long Material::RENDER_OPTION_EMISSION_M = (1l<<RENDER_OPTION_EMISSION ) ;
00099 const unsigned long Material::RENDER_OPTION_SHINYNESS_M = (1l<<RENDER_OPTION_SHINYNESS ) ;
00100 const unsigned long Material::RENDER_OPTION_BORDER_M = (1l<<RENDER_OPTION_BORDER ) ;
00101 const unsigned long Material::RENDER_OPTION_REMOVE_HIDDEN_M = (1l<<RENDER_OPTION_REMOVE_HIDDEN ) ;
00102 const unsigned long Material::RENDER_OPTION_FRUSTUM_CULL_M = (1l<<RENDER_OPTION_FRUSTUM_CULL ) ;
00103 const unsigned long Material::RENDER_OPTION_SORT_OBJECTS_M = (1l<<RENDER_OPTION_SORT_OBJECTS ) ;
00104 const unsigned long Material::RENDER_OPTION_SORT_ELEMENTS_M = (1l<<RENDER_OPTION_SORT_ELEMENTS ) ;
00105 const unsigned long Material::RENDER_OPTION_COLOR_MATERIAL_M = (1l<<RENDER_OPTION_COLOR_MATERIAL ) ;
00106 const unsigned long Material::RENDER_OPTION_MASTER_LIGHTING_ONLY_M= (1l<<RENDER_OPTION_MASTER_LIGHTING_ONLY ) ;
00107
00108
00109 const unsigned long Material::RENDER_MODE_DEFAULT = Material::RENDER_MODE_FILL_OUTLINE;
00110 const unsigned long Material::RENDER_LIGHTING_DEFAULT = Material::RENDER_LIGHTING_SIMPLE;
00111 const unsigned long Material::RENDER_OPTION_DEFAULT_M =
00112 RENDER_OPTION_CULL_FACE_M |
00113 RENDER_OPTION_DEPTH_TEST_M |
00114 RENDER_OPTION_DIFFUSE_M |
00115 RENDER_OPTION_FRUSTUM_CULL_M;
00116 const unsigned long Material::RENDER_OPTION_ALL_M =
00117 RENDER_OPTION_SMOOTH_M |
00118 RENDER_OPTION_CULL_FACE_M |
00119 RENDER_OPTION_BLEND_M |
00120 RENDER_OPTION_FOG_M |
00121 RENDER_OPTION_NORMALIZE_M |
00122 RENDER_OPTION_ALPHA_TEST_M |
00123 RENDER_OPTION_DEPTH_TEST_M |
00124 RENDER_OPTION_STENCIL_TEST_M |
00125 RENDER_OPTION_SCISSOR_TEST_M |
00126 RENDER_OPTION_TEXTURE_1D_M |
00127 RENDER_OPTION_TEXTURE_2D_M |
00128 RENDER_OPTION_TEXTURE_3D_M |
00129 RENDER_OPTION_POINT_SMOOTH_M |
00130 RENDER_OPTION_LINE_SMOOTH_M |
00131 RENDER_OPTION_POLYGON_SMOOTH_M |
00132 RENDER_OPTION_AMBIENT_M |
00133 RENDER_OPTION_DIFFUSE_M |
00134 RENDER_OPTION_SPECULAR_M |
00135 RENDER_OPTION_EMISSION_M |
00136 RENDER_OPTION_SHINYNESS_M |
00137 RENDER_OPTION_BORDER_M |
00138 RENDER_OPTION_REMOVE_HIDDEN_M |
00139 RENDER_OPTION_FRUSTUM_CULL_M |
00140 RENDER_OPTION_SORT_OBJECTS_M |
00141 RENDER_OPTION_SORT_ELEMENTS_M |
00142 RENDER_OPTION_COLOR_MATERIAL_M;
00143
00144
00145 int Material::mode_to_feature[32];
00146
00147 char *Material::render_option_to_str( int a ){
00148 switch( a ){
00149 case RENDER_OPTION_RESERVED : return "RENDER_OPTION_RESERVED ";
00150 case RENDER_OPTION_SMOOTH : return "RENDER_OPTION_SMOOTH ";
00151 case RENDER_OPTION_CULL_FACE : return "RENDER_OPTION_CULL_FACE ";
00152 case RENDER_OPTION_BLEND : return "RENDER_OPTION_BLEND ";
00153 case RENDER_OPTION_FOG : return "RENDER_OPTION_FOG ";
00154 case RENDER_OPTION_NORMALIZE : return "RENDER_OPTION_NORMALIZE ";
00155 case RENDER_OPTION_ALPHA_TEST : return "RENDER_OPTION_ALPHA_TEST ";
00156 case RENDER_OPTION_DEPTH_TEST : return "RENDER_OPTION_DEPTH_TEST ";
00157 case RENDER_OPTION_STENCIL_TEST : return "RENDER_OPTION_STENCIL_TEST ";
00158 case RENDER_OPTION_SCISSOR_TEST : return "RENDER_OPTION_SCISSOR_TEST ";
00159 case RENDER_OPTION_TEXTURE_1D : return "RENDER_OPTION_TEXTURE_1D ";
00160 case RENDER_OPTION_TEXTURE_2D : return "RENDER_OPTION_TEXTURE_2D ";
00161 case RENDER_OPTION_TEXTURE_3D : return "RENDER_OPTION_TEXTURE_3D ";
00162 case RENDER_OPTION_POINT_SMOOTH : return "RENDER_OPTION_POINT_SMOOTH ";
00163 case RENDER_OPTION_LINE_SMOOTH : return "RENDER_OPTION_LINE_SMOOTH ";
00164 case RENDER_OPTION_POLYGON_SMOOTH: return "RENDER_OPTION_POLYGON_SMOOTH";
00165 case RENDER_OPTION_AMBIENT : return "RENDER_OPTION_AMBIENT ";
00166 case RENDER_OPTION_DIFFUSE : return "RENDER_OPTION_DIFFUSE ";
00167 case RENDER_OPTION_SPECULAR : return "RENDER_OPTION_SPECULAR ";
00168 case RENDER_OPTION_EMISSION : return "RENDER_OPTION_EMISSION ";
00169 case RENDER_OPTION_SHINYNESS : return "RENDER_OPTION_SHINYNESS ";
00170 case RENDER_OPTION_BORDER : return "RENDER_OPTION_BORDER ";
00171 case RENDER_OPTION_REMOVE_HIDDEN : return "RENDER_OPTION_REMOVE_HIDDEN ";
00172 case RENDER_OPTION_FRUSTUM_CULL : return "RENDER_OPTION_FRUSTUM_CULL ";
00173 case RENDER_OPTION_SORT_OBJECTS : return "RENDER_OPTION_SORT_OBJECTS ";
00174 case RENDER_OPTION_SORT_ELEMENTS : return "RENDER_OPTION_SORT_ELEMENTS ";
00175 case RENDER_OPTION_COLOR_MATERIAL: return "RENDER_OPTION_COLOR_MATERIAL";
00176 default:
00177 return "unknown";
00178 break;
00179 }
00180 }
00181
00182 void Material::init(){
00183 dmsg( M_INIT, "init_materials..." );
00184 mode_to_feature[RENDER_OPTION_RESERVED ] = 0;
00185 mode_to_feature[RENDER_OPTION_SMOOTH ] = 0;
00186 mode_to_feature[RENDER_OPTION_CULL_FACE ] = View::CULL_FACE ;
00187 mode_to_feature[RENDER_OPTION_BLEND ] = View::BLEND ;
00188 mode_to_feature[RENDER_OPTION_FOG ] = View::FOG ;
00189 mode_to_feature[RENDER_OPTION_NORMALIZE ] = View::NORMALIZE ;
00190 mode_to_feature[RENDER_OPTION_ALPHA_TEST ] = View::ALPHA_TEST ;
00191 mode_to_feature[RENDER_OPTION_DEPTH_TEST ] = View::DEPTH_TEST ;
00192 mode_to_feature[RENDER_OPTION_STENCIL_TEST ] = View::STENCIL_TEST ;
00193 mode_to_feature[RENDER_OPTION_SCISSOR_TEST ] = View::SCISSOR_TEST ;
00194 mode_to_feature[RENDER_OPTION_TEXTURE_1D ] = View::TEXTURE_1D ;
00195 mode_to_feature[RENDER_OPTION_TEXTURE_2D ] = View::TEXTURE_2D ;
00196 mode_to_feature[RENDER_OPTION_TEXTURE_3D ] = 0;
00197 mode_to_feature[RENDER_OPTION_POINT_SMOOTH ] = View::POINT_SMOOTH ;
00198 mode_to_feature[RENDER_OPTION_LINE_SMOOTH ] = View::LINE_SMOOTH ;
00199 mode_to_feature[RENDER_OPTION_POLYGON_SMOOTH] = View::POLYGON_SMOOTH ;
00200 mode_to_feature[RENDER_OPTION_AMBIENT ] = 0;
00201 mode_to_feature[RENDER_OPTION_DIFFUSE ] = 0;
00202 mode_to_feature[RENDER_OPTION_SPECULAR ] = 0;
00203 mode_to_feature[RENDER_OPTION_EMISSION ] = 0;
00204 mode_to_feature[RENDER_OPTION_SHINYNESS ] = 0;
00205 mode_to_feature[RENDER_OPTION_BORDER ] = 0;
00206 mode_to_feature[RENDER_OPTION_REMOVE_HIDDEN ] = 0;
00207 mode_to_feature[RENDER_OPTION_FRUSTUM_CULL ] = 0;
00208 mode_to_feature[RENDER_OPTION_SORT_OBJECTS ] = 0;
00209 mode_to_feature[RENDER_OPTION_SORT_ELEMENTS ] = 0;
00210 mode_to_feature[RENDER_OPTION_COLOR_MATERIAL] = View::COLOR_MATERIAL ;
00211 }
00212
00213 int Material::getFeature( int a ){
00214 return mode_to_feature[a];
00215 }
00216
00217
00218
00219
00220
00221
00222
00223 Material Material::BLACK = Material( "Default Black Material", Color(C_BLACK ) );
00224 Material Material::GRAY_25 = Material( "Default Gray 25 Material", Color(C_GRAY_25 ) );
00225 Material Material::GRAY_50 = Material( "Default Gray 50 Material", Color(C_GRAY_50 ) );
00226 Material Material::GRAY_75 = Material( "Default Gray 75 Material", Color(C_GRAY_75 ) );
00227 Material Material::WHITE = Material( "Default White Material", Color(C_WHITE ) );
00228 Material Material::ORANGE = Material( "Default Orange Material", Color(C_ORANGE ) );
00229 Material Material::RED = Material( "Default Red Material", Color(C_RED ) );
00230 Material Material::YELLOW = Material( "Default Yellow Material", Color(C_YELLOW ) );
00231 Material Material::GREEN = Material( "Default Green Material", Color(C_GREEN ) );
00232 Material Material::CYAN = Material( "Default Cyan Material", Color(C_CYAN ) );
00233 Material Material::BLUE = Material( "Default Blue Material", Color(C_BLUE ) );
00234 Material Material::MAGENTA = Material( "Default Magenta Material", Color(C_MAGENTA ) );
00235 Material Material::DARK_ORANGE = Material( "Default Dark Orange Material", Color(C_DARK_ORANGE ) );
00236 Material Material::DARK_RED = Material( "Default Dark Red Material", Color(C_DARK_RED ) );
00237 Material Material::DARK_YELLOW = Material( "Default Dark Yellow Material", Color(C_DARK_YELLOW ) );
00238 Material Material::DARK_GREEN = Material( "Default Dark Green Material", Color(C_DARK_GREEN ) );
00239 Material Material::DARK_CYAN = Material( "Default Dark Cyan Material", Color(C_DARK_CYAN ) );
00240 Material Material::DARK_BLUE = Material( "Default Dark Blue Material", Color(C_DARK_BLUE ) );
00241 Material Material::DARK_MAGENTA = Material( "Default Dark Magenta Material", Color(C_DARK_MAGENTA ) );
00242 Material Material::LIGHT_ORANGE = Material( "Default Light Orange Material", Color(C_LIGHT_ORANGE ) );
00243 Material Material::LIGHT_RED = Material( "Default Light Red Material", Color(C_LIGHT_RED ) );
00244 Material Material::LIGHT_YELLOW = Material( "Default Light Yellow Material", Color(C_LIGHT_YELLOW ) );
00245 Material Material::LIGHT_GREEN = Material( "Default Light Green Material", Color(C_LIGHT_GREEN ) );
00246 Material Material::LIGHT_CYAN = Material( "Default Light Cyan Material", Color(C_LIGHT_CYAN ) );
00247 Material Material::LIGHT_BLUE = Material( "Default Light Blue Material", Color(C_LIGHT_BLUE ) );
00248 Material Material::LIGHT_MAGENTA = Material( "Default Light Magenta Material", Color(C_LIGHT_MAGENTA ) );
00249
00250
00252 Material::Material( const std::string &name )
00253 :
00254 Named (name),
00255 Options(0)
00256 {
00257 this->shininess = 0;
00258 this->ambient = Color( C_BLACK );
00259 this->diffuse = Color( C_BLACK );
00260 this->specular = Color( C_BLACK );
00261 this->emission = Color( C_BLACK );
00262 this->render_mode = RENDER_MODE_FILL;
00263 this->render_lighting = RENDER_LIGHTING_SIMPLE;
00264 this->texture = NULL;
00265 this->polygon_offset = 0;
00266 this->max_smoothing_angle = 60.0f;
00267 }
00268
00270 Material::Material( const std::string &name, const unsigned long options )
00271 :
00272 Named (name),
00273 Options(options)
00274 {
00275 this->shininess = 0;
00276 this->ambient = Color( C_BLACK );
00277 this->diffuse = Color( C_BLACK );
00278 this->specular = Color( C_BLACK );
00279 this->emission = Color( C_BLACK );
00280 this->render_mode = RENDER_MODE_FILL;
00281 this->render_lighting = RENDER_LIGHTING_SIMPLE;
00282 this->texture = NULL;
00283 this->polygon_offset = 0;
00284 this->max_smoothing_angle = 60.0f;
00285 }
00286
00287 void Material::copy( const Material &from ){
00288 this->shininess = from.shininess;
00289 this->ambient = from.ambient;
00290 this->diffuse = from.diffuse;
00291 this->specular = from.specular;
00292 this->emission = from.emission;
00293 this->border = from.border;
00294 this->render_lighting = from.render_lighting;
00295 this->render_mode = from.render_mode;
00296 this->polygon_offset = from.polygon_offset;
00297 this->max_smoothing_angle = from.max_smoothing_angle;
00298 this->texture = from.texture;
00299 this->options = from.options;
00300 }
00301
00302
00303
00305 Material::Material( const std::string &name, Uint8 mode, Uint8 lighting, unsigned long options )
00306 :
00307 Named ( name ),
00308 Options ( options ),
00309 texture ( NULL ),
00310 render_mode ( mode ),
00311 render_lighting( lighting ),
00312 shininess ( 0 ),
00313 ambient ( Color(C_BLACK ) ),
00314 diffuse ( Color(C_GRAY_50) ),
00315 specular ( Color(C_BLACK ) ),
00316 emission ( Color(C_BLACK ) ),
00317 border ( Color(C_GRAY_50) ),
00318 polygon_offset ( 0 ),
00319 max_smoothing_angle ( 60.0f )
00320 {
00321 }
00322
00323
00325 Material::Material( const Material &m )
00326 :
00327 Named ( m.name ),
00328 Options( m.options )
00329 {
00330 this->shininess = m.shininess;
00331 this->ambient = m.ambient;
00332 this->diffuse = m.diffuse;
00333 this->specular = m.specular;
00334 this->emission = m.emission;
00335 this->border = m.border;
00336 this->render_mode = m.render_mode;
00337 this->render_lighting = m.render_lighting;
00338 this->texture = m.texture;
00339 this->polygon_offset = 0;
00340 this->max_smoothing_angle = 60.0f;
00341 }
00342
00343
00345 Material::Material( const Material &m, Uint8 lighting )
00346 :
00347 Named ( m.name ),
00348 Options( m.options )
00349 {
00350 this->shininess = m.shininess;
00351 this->ambient = m.ambient;
00352 this->diffuse = m.diffuse;
00353 this->specular = m.specular;
00354 this->emission = m.emission;
00355 this->border = m.border;
00356 this->render_mode = m.render_mode;
00357 this->render_lighting = lighting;
00358 this->texture = m.texture;
00359 this->polygon_offset = 0;
00360 this->max_smoothing_angle = 60.0f;
00361 }
00362
00363
00365 Material::Material( const std::string &name, Color color )
00366 :
00367 Named (name),
00368 Options(
00369 RENDER_OPTION_CULL_FACE_M |
00370 RENDER_OPTION_DEPTH_TEST_M |
00371 RENDER_OPTION_AMBIENT_M |
00372 RENDER_OPTION_DIFFUSE_M |
00373 RENDER_OPTION_SPECULAR_M |
00374 RENDER_OPTION_EMISSION_M |
00375 RENDER_OPTION_SHINYNESS_M |
00376 RENDER_OPTION_SMOOTH_M
00377 )
00378 {
00379
00380 this->shininess = 40.0f;
00381 this->ambient = Color( C_BLACK );
00382 this->diffuse = color;
00383 this->specular = Color( C_WHITE );
00384 this->emission = Color( C_BLACK );
00385 this->border = Color( C_GRAY_75 );
00386 this->render_mode = RENDER_MODE_FILL;
00387 this->render_lighting = RENDER_LIGHTING_SIMPLE;
00388 this->texture = NULL;
00389 this->polygon_offset = 0;
00390 this->max_smoothing_angle = 60.0f;
00391 }
00392
00393
00395 Material::Material( Color color )
00396 :
00397 Named (""),
00398 Options(
00399 RENDER_OPTION_CULL_FACE_M |
00400 RENDER_OPTION_DEPTH_TEST_M |
00401 RENDER_OPTION_AMBIENT_M |
00402 RENDER_OPTION_DIFFUSE_M |
00403 RENDER_OPTION_SPECULAR_M |
00404 RENDER_OPTION_EMISSION_M |
00405 RENDER_OPTION_SHINYNESS_M |
00406 RENDER_OPTION_SMOOTH_M
00407 )
00408 {
00409
00410 this->shininess = 40.0f;
00411 this->ambient = Color( C_BLACK );
00412 this->diffuse = color;
00413 this->specular = Color( C_WHITE );
00414 this->emission = Color( C_BLACK );
00415 this->border = Color( C_GRAY_75 );
00416 this->render_mode = RENDER_MODE_FILL;
00417 this->render_lighting = RENDER_LIGHTING_SIMPLE;
00418 this->texture = NULL;
00419 this->polygon_offset = 0;
00420 this->max_smoothing_angle = 60.0f;
00421 }
00422
00423
00425 Material::~Material(){
00426 }
00427
00428
00430 void Material::applyAmbient( Uint8 lighting ){
00431 switch( lighting ){
00432 case RENDER_LIGHTING_COLOR: break;
00433 case RENDER_LIGHTING_CUSTOM: break;
00434 break;
00435 case RENDER_LIGHTING_PRIMARY_LIGHT_ONLY:
00436
00437 case RENDER_LIGHTING_FULL:
00438
00439 case RENDER_LIGHTING_SIMPLE:
00440 glMaterialfv( GL_FRONT, GL_AMBIENT, ambient.rgba );
00441 # ifdef DEBUG_MATERIALS
00442 printf( << "Ambient %d, %d, %d\n", ambient.rgba[0], ambient.rgba[1], ambient.rgba[2] );
00443 # endif
00444 break;
00445 default:
00446 printf( "Unknown lighting mode\n" );
00447 break;
00448 }
00449 }
00450
00451
00453 void Material::applyDiffuse( Uint8 lighting ){
00454
00455 switch( lighting ){
00456 case RENDER_LIGHTING_COLOR:
00457 diffuse.glApply();
00458
00459 break;
00460 case RENDER_LIGHTING_CUSTOM: break;
00461 case RENDER_LIGHTING_PRIMARY_LIGHT_ONLY:
00462
00463 case RENDER_LIGHTING_FULL:
00464
00465 case RENDER_LIGHTING_SIMPLE:
00466 glMaterialfv( GL_FRONT, GL_DIFFUSE, diffuse.rgba );
00467 # ifdef DEBUG_MATERIALS
00468 printf( "applyDiffuse %d, %d, %d\n", diffuse.rgba[0], diffuse.rgba[1], diffuse.rgba[2] );
00469 # endif
00470 break;
00471 default:
00472 printf( "Unknown lighting mode\n" );
00473 break;
00474 }
00475 }
00476
00477
00479 void Material::applySpecular( Uint8 lighting ){
00480 switch( lighting ){
00481 case RENDER_LIGHTING_COLOR: break;
00482 case RENDER_LIGHTING_CUSTOM: break;
00483 break;
00484 case RENDER_LIGHTING_PRIMARY_LIGHT_ONLY:
00485
00486 case RENDER_LIGHTING_FULL:
00487
00488 case RENDER_LIGHTING_SIMPLE:
00489 glMaterialfv( GL_FRONT, GL_SPECULAR, specular.rgba );
00490 # ifdef DEBUG_MATERIALS
00491 printf( "Specular %d, %d, %d\n", specular.rgba[0], specular.rgba[1], specular.rgba[2] );
00492 # endif
00493 break;
00494 default:
00495 printf( "Unknown lighting mode\n" );
00496 break;
00497 }
00498 }
00499
00500
00502 void Material::applyEmission( Uint8 lighting ){
00503 switch( lighting ){
00504 case RENDER_LIGHTING_COLOR: break;
00505 case RENDER_LIGHTING_CUSTOM: break;
00506 break;
00507 case RENDER_LIGHTING_PRIMARY_LIGHT_ONLY:
00508
00509 case RENDER_LIGHTING_FULL:
00510
00511 case RENDER_LIGHTING_SIMPLE:
00512 glMaterialfv( GL_FRONT, GL_EMISSION, emission.rgba );
00513 # ifdef DEBUG_MATERIALS
00514 printf( "Emission %d, %d, %d\n", emission.rgba[0], emission.rgba[1], emission.rgba[2] );
00515 # endif
00516 break;
00517 default:
00518 printf( "Unknown lighting mode\n" );
00519 break;
00520 }
00521 }
00522
00523
00525 void Material::applyBorder( Uint8 lighting ){
00526 switch( lighting ){
00527 case RENDER_LIGHTING_COLOR:
00528 border.glApply();
00529 break;
00530 case RENDER_LIGHTING_CUSTOM: break;
00531 case RENDER_LIGHTING_PRIMARY_LIGHT_ONLY:
00532
00533 case RENDER_LIGHTING_FULL:
00534
00535 case RENDER_LIGHTING_SIMPLE:
00536 glMaterialfv( GL_FRONT, GL_DIFFUSE, border.rgba );
00537 # ifdef DEBUG_MATERIALS
00538 printf( "Border Diffuse %d, %d, %d\n", border.rgba[0], border.rgba[1], border.rgba[2] );
00539 # endif
00540 break;
00541 default:
00542 printf( "Unknown lighting mode\n" );
00543 break;
00544 }
00545 }
00546
00547
00549 void Material::applyShinyness( Uint8 lighting ){
00550 switch( lighting ){
00551 case RENDER_LIGHTING_COLOR:
00552 case RENDER_LIGHTING_CUSTOM:
00553 break;
00554 case RENDER_LIGHTING_PRIMARY_LIGHT_ONLY:
00555
00556 case RENDER_LIGHTING_FULL:
00557
00558 case RENDER_LIGHTING_SIMPLE:
00559 glMaterialf( GL_FRONT, GL_SHININESS, shininess );
00560 # ifdef DEBUG_MATERIALS
00561 printf( "Shininess %f\n", shininess );
00562 # endif
00563 break;
00564 default:
00565 printf( "Unknown lighting mode\n" );
00566 break;
00567 }
00568 }
00569
00570
00572 void Material::setMode( Uint8 mode ){
00573 this->render_mode = mode;
00574 }
00575
00576
00578 Uint8 Material::getMode() const {
00579 return this->render_mode;
00580 }
00581
00582
00584 void Material::setLighting( Uint8 lighting ){
00585 this->render_lighting = lighting;
00586 }
00587
00588
00590 Uint8 Material::getLighting() const {
00591 return this->render_lighting;
00592 }
00593
00594
00596 void Material::setEmission( const Color &e ){
00597 this->emission = e;
00598 }
00599
00600
00602 Color Material::getEmission() const {
00603 return this->emission;
00604 }
00605
00606
00608 void Material::setAmbient( const Color &a ){
00609 this->ambient = a;
00610 }
00611
00612
00614 Color Material::getAmbient() const {
00615 return this->ambient;
00616 }
00617
00618
00620 void Material::setDiffuse( const Color &d ){
00621 this->diffuse = d;
00622 }
00623
00624
00626 Color Material::getDiffuse() const {
00627 return this->diffuse;
00628 }
00629
00630
00632 void Material::setSpecular( const Color &s ){
00633 this->specular = s;
00634 }
00635
00636
00638 Color Material::getSpecular() const {
00639 return this->specular;
00640 }
00641
00642
00644 void Material::setBorder( const Color &b ){
00645 this->border = b;
00646 }
00647
00648
00650 Color Material::getBorder() const {
00651 return this->border;
00652 }
00653
00654
00656 Texture *Material::getTexture(){
00657 return this->texture;
00658 }
00659
00660
00662 void Material::setTexture( Texture *t, bool enable ){
00663 this->texture = t;
00664 if( enable && texture->isGood() ){
00665 this->enable( RENDER_OPTION_TEXTURE_2D_M );
00666 }
00667 }
00668
00669
00671 void Material::setShininess( float s ){
00672 this->shininess = s;
00673 }
00674
00675
00677 float Material::getShininess() const {
00678 return this->shininess;
00679 }
00680
00681
00682 void Material::setPolygonOffset( const int offset ){
00683 this->polygon_offset = offset;
00684 }
00685
00686
00687 int Material::getPolygonOffset() const {
00688 return polygon_offset;
00689 }
00690
00691
00692 void Material::setMaxSmoothingAngle( const float angle ){
00693 this->max_smoothing_angle = angle;
00694 }
00695
00696
00697 float Material::getMaxSmoothingAngle() const {
00698 return max_smoothing_angle;
00699 }
00700
00701
00702 };
00703 };
00704