2 Copyright 2004 John Tsiombikas <nuclear@siggraph.org>
4 This file is part of the 3dengfx, realtime visualization system.
6 3dengfxis free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 3dengfx is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with 3dengfx; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "3dengfx_config.h"
24 #include "material.hpp"
26 Material::Material() {
27 ambient_color = diffuse_color = Color(1.0f, 1.0f, 1.0f);
28 specular_color = emissive_color = Color(0.0f, 0.0f, 0.0f);
30 specular_power = 1.0f;
32 bump_intensity = 1.0f;
36 shading = SHADING_GOURAUD;
45 memset(tex, 0, MAX_TEXTURES * sizeof(Texture*));
48 Material::Material(const Color &col) {
49 ambient_color = diffuse_color = col;
50 specular_color = emissive_color = Color(0.0f, 0.0f, 0.0f);
52 specular_power = 1.0f;
54 bump_intensity = 1.0f;
58 shading = SHADING_GOURAUD;
65 memset(tex, 0, MAX_TEXTURES * sizeof(Texture*));
68 void Material::set_texture(Texture *texture, TextureType type) {
69 if(texture) tex_count++;
73 Texture *Material::get_texture(TextureType type) {
77 int Material::get_texture_count() const {
81 void Material::set_glmaterial() const {
82 float amb[] = {ambient_color.r, ambient_color.g, ambient_color.b, ambient_color.a};
83 float dif[] = {diffuse_color.r, diffuse_color.g, diffuse_color.b, diffuse_color.a};
84 float spc[] = {specular_color.r, specular_color.g, specular_color.b, specular_color.a};
85 float ems[] = {emissive_color.r, emissive_color.g, emissive_color.b, emissive_color.a};
92 glMaterialfv(GL_FRONT, GL_AMBIENT, amb);
93 glMaterialfv(GL_FRONT, GL_DIFFUSE, dif);
94 glMaterialfv(GL_FRONT, GL_SPECULAR, spc);
95 glMaterialfv(GL_FRONT, GL_EMISSION, ems);
96 glMaterialf(GL_FRONT, GL_SHININESS, specular_power);