OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
texture.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_GFX_TEXTURE_HH
20 #define OST_GFX_TEXTURE_HH
21 
22 /*
23  texture
24 
25  Author: Ansgar Philippsen
26 */
27 
28 #include <boost/shared_array.hpp>
29 
30 #include "module_config.hh"
31 #include "glext_include.hh"
32 #include "color.hh"
33 #include "bitmap_io.hh"
34 
35 namespace ost { namespace gfx {
36 
37 class Texture
38 {
39 public:
41  w_(0),
42  h_(0),
43  d_()
44  {}
45 
46  Texture(GLint w, GLint h):
47  w_(w),
48  h_(h),
49  d_(new Color[w*h])
50  {}
51 
52  Texture(const Bitmap& b);
53 
54  bool IsValid() const {return d_;}
55 
56  Color& operator()(uint u, uint v) {return d_[v*w_+u];}
57  const Color& operator()(uint u, uint v) const {return d_[v*w_+u];}
58 
59  float* data() {return d_[0];}
60 
61  GLint width() const {return w_;}
62  GLint height() const {return h_;}
63  GLint format() const {return GL_RGBA;}
64  GLint type() const {return GL_FLOAT;}
65  GLint border() const {return 0;}
66 
67 private:
68  GLint w_,h_;
69  boost::shared_array<Color> d_;
70 };
71 
72 }} // ns
73 
74 #endif