Mondschein Engine  0.3.0
texture.cpp
1 /* Mondschein Engine is a fast, powerful, and easy-to-use 3D realtime rendering engine.
2  *
3  * Copyright (C) 2009-2013 by Andreas Amereller
4  * E-Mail: andreas.amereller.dev@googlemail.com
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation; either version 3 of the License, or (at your option)
9  * any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include "gl13/texture.h"
22 #include "gl13/renderer.h"
23 #include "core/texture.h"
24 #include <GL/gl.h>
25 #include <GL/glu.h>
26 
27 using namespace mondschein;
28 using namespace renderer;
29 
30 GL13_Texture::GL13_Texture() : unit(0), texture(0)
31 {
32  glGenTextures(1,&texture);
33  return;
34 }
35 
36 GL13_Texture::GL13_Texture(uint8 _u,uint32 _t) : unit(_u), texture(_t)
37 {
38  return;
39 }
40 
41 GL13_Texture::~GL13_Texture()
42 {
43  glDeleteTextures(1,&texture);
44  return;
45 }
46 
47 void GL13_Texture::set_unit(uint8 _u)
48 {
49  unit=_u;
50  return;
51 }
52 
53 uint8 GL13_Texture::get_unit() const
54 {
55  return unit;
56 }
57 
58 void GL13_Texture::set_texture(uint32 _t)
59 {
60  texture=_t;
61  return;
62 }
63 
64 uint32 GL13_Texture::get_texture() const
65 {
66  return texture;
67 }
68 
69 void GL13_Texture::render() const
70 {
71  if (glIsTexture(texture))
72  {
73  glActiveTexture(GL_TEXTURE0+unit);
74  glBindTexture(GL_TEXTURE_2D,texture);
75  }
76  else
77  {
78  std::string err("Mondschein Engine ERROR: Internal reference is not a valid OpenGL 1.3 compliant texture object. ");
79  err+="Exception raised in function\n\t";
80  err+="void mondschein::renderer::GL13_Texture::render() const";
81  throw boost::enable_current_exception(exception()) << exception_error(err);
82  }
83 }