tavli
diff src/object.cc @ 4:b41ceead1708
procedural playing field texture mask
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 25 Jun 2015 05:58:35 +0300 |
parents | 94aff2ff1934 |
children | a0d30f6f20d4 |
line diff
1.1 --- a/src/object.cc Mon Jun 22 21:46:57 2015 +0300 1.2 +++ b/src/object.cc Thu Jun 25 05:58:35 2015 +0300 1.3 @@ -4,6 +4,7 @@ 1.4 Object::Object() 1.5 { 1.6 mesh = 0; 1.7 + tex = 0; 1.8 } 1.9 1.10 Object::~Object() 1.11 @@ -31,10 +32,22 @@ 1.12 return mesh; 1.13 } 1.14 1.15 +void Object::set_texture(unsigned int tex) 1.16 +{ 1.17 + this->tex = tex; 1.18 +} 1.19 + 1.20 void Object::draw() const 1.21 { 1.22 if(!mesh) return; 1.23 1.24 + if(tex) { 1.25 + glBindTexture(GL_TEXTURE_2D, tex); 1.26 + glEnable(GL_TEXTURE_2D); 1.27 + } else { 1.28 + glDisable(GL_TEXTURE_2D); 1.29 + } 1.30 + 1.31 glMatrixMode(GL_MODELVIEW); 1.32 glPushMatrix(); 1.33 glMultTransposeMatrixf(matrix[0]); 1.34 @@ -42,6 +55,10 @@ 1.35 mesh->draw(); 1.36 1.37 glPopMatrix(); 1.38 + 1.39 + if(tex) { 1.40 + glDisable(GL_TEXTURE_2D); 1.41 + } 1.42 } 1.43 1.44 bool Object::intersect(const Ray &ray, HitPoint *hit) const