Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

MS_Material.cpp

Go to the documentation of this file.
00001 
00007 #include "MilkShape.h"
00008 
00009 MS_Material::MS_Material() {
00010 }
00011 
00012 MS_Material::~MS_Material() {
00013         clear();
00014 }
00015 
00016 void MS_Material::clear() {
00017         app->renderer->deleteTexture(this->texture);
00018 }
00019 
00020 void MS_Material::reloadTexture() {
00021         if (strlen(this->diffuse_name) > 0) {
00022                 this->texture = app->renderer->addTexture(this->diffuse_name);
00023         }
00024         else {
00025                 this->texture = TEXTURE_NONE;
00026         }
00027 }
00028 
00029 bool MS_Material::loadFromAsciiSegment(const char *path, FILE *file) {
00030         char szLine[256] = {0};
00031 
00032         //--------------------
00033         // Name
00034         //--------------------
00035         if (!fgets(szLine, 256, file))
00036                 return false;
00037         if (sscanf(szLine, "\"%[^\"]\"", this->name) != 1)
00038                 return false;
00039 
00040         //--------------------
00041         // Ambient
00042         //--------------------
00043         if (!fgets(szLine, 256, file))
00044                 return false;
00045         if (sscanf(szLine, "%f %f %f %f", &this->ambient[0], &this->ambient[1], &this->ambient[2], &this->ambient[3]) != 4)
00046                 return false;
00047 
00048         //--------------------
00049         // Diffuse
00050         //--------------------
00051         if (!fgets(szLine, 256, file))
00052                 return false;
00053         if (sscanf(szLine, "%f %f %f %f", &this->diffuse[0], &this->diffuse[1], &this->diffuse[2], &this->diffuse[3]) != 4)
00054                 return false;
00055 
00056         //--------------------
00057         // Specular
00058         //--------------------
00059         if (!fgets(szLine, 256, file))
00060                 return false;
00061         if (sscanf(szLine, "%f %f %f %f", &this->specular[0], &this->diffuse[1], &this->diffuse[2], &this->diffuse[3]) != 4)
00062                 return false;
00063 
00064         //--------------------
00065         // Emissive
00066         //--------------------
00067         if (!fgets(szLine, 256, file))
00068                 return false;
00069         if (sscanf(szLine, "%f %f %f %f", &this->emissive[0], &this->emissive[1], &this->emissive[2], &this->emissive[3]) != 4)
00070                 return false;
00071 
00072         //--------------------
00073         // Shininess
00074         //--------------------
00075         if (!fgets(szLine, 256, file))
00076                 return false;
00077         if (sscanf(szLine, "%f", &this->shininess) != 1)
00078                 return false;
00079 
00080         //--------------------
00081         // Transparency
00082         //--------------------
00083         if (!fgets(szLine, 256, file))
00084                 return false;
00085         if (sscanf(szLine, "%f", &this->transparency) != 1)
00086                 return false;
00087 
00088         //--------------------
00089         // Diffuse texture
00090         //--------------------
00091         if (!fgets(szLine, 256, file))
00092                 return false;
00093 
00094         strcpy(this->diffuse_name, "");
00095         char name[MAX_PATH] = {0};
00096         sscanf(szLine, "\"%[^\"]\"", name);
00097         sprintf(this->diffuse_name, "%s%s", path, name);
00098 
00099         //--------------------
00100         // Alpha texture
00101         //--------------------
00102         if (!fgets(szLine, 256, file))
00103                 return false;
00104 
00105         strcpy(this->alpha_name, "");
00106         sscanf(szLine, "\"%[^\"]\"", this->alpha_name);
00107 
00108         this->reloadTexture();
00109 
00110         return true;
00111 }
00112 
00113 //---------------------------
00114 // FIX THIS USING RENDERER INSTEAD!!!!!
00115 //---------------------------
00116 void MS_Material::activate() {
00117         //glMaterialfv(GL_FRONT, GL_AMBIENT, this->ambient);
00118         //glMaterialfv(GL_FRONT, GL_DIFFUSE, this->diffuse);
00119         //glMaterialfv(GL_FRONT, GL_SPECULAR, this->specular);
00120         //glMaterialfv(GL_FRONT, GL_EMISSION, this->emissive);
00121         //glMaterialf(GL_FRONT, GL_SHININESS, this->shininess);
00122 
00123         //if (this->texture > 0) {
00124         //      app->renderer->setTextures(this->texture);
00125                 //glBindTexture(GL_TEXTURE_2D, this->texture);
00126                 //glEnable(GL_TEXTURE_2D);
00127         //}
00128         //else {
00129                 //glDisable(GL_TEXTURE_2D);
00130         //}
00131 
00132 
00133         app->renderer->setTextures(this->texture);
00134         app->renderer->apply();
00135 }

Generated on Sun Jun 5 15:47:04 2005 for Defacto by  doxygen 1.4.3