[845] | 1 | // Material.cpp: implementation of the Material class.
|
---|
| 2 | //
|
---|
| 3 | //////////////////////////////////////////////////////////////////////
|
---|
| 4 |
|
---|
| 5 | #include "Material.h"
|
---|
| 6 |
|
---|
| 7 | //////////////////////////////////////////////////////////////////////
|
---|
| 8 | // Construction/Destruction
|
---|
| 9 | //////////////////////////////////////////////////////////////////////
|
---|
| 10 |
|
---|
| 11 | Material::Material()
|
---|
| 12 | {
|
---|
| 13 | m_ColorTexture=NULL;
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | Material::~Material()
|
---|
| 17 | {
|
---|
| 18 |
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | void Material::setMaterial()
|
---|
| 22 | {
|
---|
| 23 | glMaterialfv(GL_FRONT,GL_AMBIENT,m_Ambient_Color.GetArrayf());
|
---|
| 24 | glMaterialfv(GL_FRONT,GL_DIFFUSE,m_Diffuse_Color.GetArrayf());
|
---|
| 25 | glMaterialfv(GL_FRONT,GL_SPECULAR,m_Specular_Color.GetArrayf());
|
---|
| 26 | glMaterialfv(GL_FRONT,GL_EMISSION,m_Emissive_Color.GetArrayf());
|
---|
| 27 |
|
---|
| 28 | glMaterialf(GL_FRONT,GL_SHININESS,(float)m_Shininess);
|
---|
| 29 |
|
---|
| 30 | if(m_ColorTexture)
|
---|
| 31 | {
|
---|
| 32 | glEnable(GL_TEXTURE_2D);
|
---|
| 33 | glBindTexture(GL_TEXTURE_2D,m_ColorTexture->getTextureHandler());
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | void Material::Load(ifstream *file)
|
---|
| 38 | {
|
---|
| 39 | fprintf(stderr, "Loading Material...\n");
|
---|
| 40 | char* tempchar=new char[500];
|
---|
| 41 | file->getline(tempchar,500,'\n');
|
---|
| 42 | sscanf(tempchar,"ambientcolor %lf %lf %lf",&m_Ambient_Color.x,&m_Ambient_Color.y,&m_Ambient_Color.z);
|
---|
| 43 | file->getline(tempchar,500,'\n');
|
---|
| 44 | sscanf(tempchar,"diffusecolor %lf %lf %lf",&m_Diffuse_Color.x,&m_Diffuse_Color.y,&m_Diffuse_Color.z);
|
---|
| 45 | file->getline(tempchar,500,'\n');
|
---|
| 46 | sscanf(tempchar,"transparency %f",&m_transparency);
|
---|
| 47 | file->getline(tempchar,500,'\n');
|
---|
| 48 | sscanf(tempchar,"emissivecolor %lf %lf %lf",&m_Emissive_Color.x,&m_Emissive_Color.y,&m_Emissive_Color.z);
|
---|
| 49 | file->getline(tempchar,500,'\n');
|
---|
| 50 | sscanf(tempchar,"specularcolor %lf %lf %lf",&m_Specular_Color.x,&m_Specular_Color.y,&m_Specular_Color.z);
|
---|
| 51 | file->getline(tempchar,500,'\n');
|
---|
| 52 | sscanf(tempchar,"shininess %lf",&m_Shininess);
|
---|
| 53 | file->getline(tempchar,500,'\n');
|
---|
| 54 | unsigned int texturecount;
|
---|
| 55 | sscanf(tempchar,"textures: %ui",&texturecount);
|
---|
| 56 |
|
---|
| 57 | //texturák
|
---|
| 58 | for(unsigned int i=0;i<texturecount;i++)
|
---|
| 59 | {
|
---|
| 60 | m_ColorTexture=new Texture;
|
---|
| 61 | file->getline(tempchar,500,' ');
|
---|
| 62 | file->getline(tempchar,500,'\n');
|
---|
| 63 | m_ColorTexture->setFilename(tempchar);
|
---|
| 64 | m_ColorTexture->LoadImage();
|
---|
| 65 | m_Diffuse_Color=Vector(1,1,1);
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 | void Material::MakeTexture()
|
---|
| 71 | {
|
---|
| 72 |
|
---|
| 73 | } |
---|