hx3d  1
2D/3D Simple Game Framework
texture.hpp
1 /*
2  Texture.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #ifndef HX3D_GRAPHICS_TEXTURE
22 #define HX3D_GRAPHICS_TEXTURE
23 
24 #include "hx3d/utils/ptr.hpp"
25 #include "hx3d/utils/resource.hpp"
26 
27 #include "hx3d/graphics/font.hpp"
28 #include "hx3d/graphics/image.hpp"
29 #include "hx3d/graphics/gl.hpp"
30 
31 #include <string>
32 
33 namespace hx3d {
34 namespace graphics {
35 
39 class Texture: public Resource {
40 
41 public:
45  enum class FilterType {
46 
48  Min,
50  Max,
51 
53  WrapX,
55  WrapY
56  };
57 
61  enum class FilterValue {
62 
63  /* Min and Max */
64 
66  Linear,
68  Nearest,
69 
70  /* Min only */
71 
73  LinearMipmapLinear,
75  NearestMipmapLinear,
77  LinearMipmapNearest,
79  NearestMipmapNearest,
80 
81  /* WrapX and WrapY */
82 
84  ClampToEdge,
86  MirroredRepeat,
88  Repeat
89  };
90 
93 
98  Texture();
99 
105  Texture(std::string pathToImage);
106 
112  Texture(Image& image);
113  ~Texture();
114 
122  bool load(std::string pathToImage);
123 
130  void setFilter(FilterType type, FilterValue value);
131 
141  void updateZone(unsigned int x, unsigned int y, unsigned int w, unsigned int h, Uint8* data);
142 
148  unsigned int getWidth();
149 
155  unsigned int getHeight();
156 
162  GLuint getID();
163 
165 
174  static Ptr<Texture> createColorBuffer(unsigned int width, unsigned int height);
175 
181  static void use(Ptr<Texture> texture);
182 
189  static void use(Ptr<Font> font, int characterSize);
190 
194  static void disable();
195 
199  static void generateBlankTexture();
200 
201  friend class Application;
202 
203 private:
205  GLuint _id;
207  unsigned int _width;
209  unsigned int _height;
210 
212 };
213 
214 } /* graphics */
215 } /* hx3d */
216 
217 #endif
Texture()
Construct an empty texture. See load to build the texture.
Definition: texture.cpp:59
unsigned int getWidth()
Get the texture width.
Definition: texture.cpp:165
hx3d framework namespace
Definition: audio.hpp:26
FilterValue
Filtering value.
Definition: texture.hpp:61
void setFilter(FilterType type, FilterValue value)
Set the texture filters.
Definition: texture.cpp:98
GLuint getID()
Get the texture ID.
Definition: texture.cpp:161
void updateZone(unsigned int x, unsigned int y, unsigned int w, unsigned int h, Uint8 *data)
Update a zone in the texture.
Definition: texture.cpp:173
bool load(std::string pathToImage)
Build the texture from an image.
Definition: texture.cpp:72
unsigned int getHeight()
Get the texture height.
Definition: texture.cpp:169
Resource type: to use in an asset manager.
Definition: resource.hpp:29
static Ptr< Texture > createColorBuffer(unsigned int width, unsigned int height)
Create a color buffer (used in framebuffers).
Definition: texture.cpp:140
Real-time editable texture.
Definition: image.hpp:36
static Ptr< Texture > Blank
Default blank texture.
Definition: texture.hpp:92
FilterType
Filtering type.
Definition: texture.hpp:45
2D/3D texture management.
Definition: texture.hpp:39
static void disable()
Clear the current texture for drawing.
Definition: texture.cpp:136
static void use(Ptr< Texture > texture)
Use the current texture for drawing.
Definition: texture.cpp:127
static void generateBlankTexture()
Used to create the Texture::Blank texture.
Definition: texture.cpp:179
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
Definition: ptr.hpp:34