GameKit  0.0.1a
C++ gamedev tools
Texture.hpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: Texture.hpp
5  *
6  * Description:
7  *
8  * Created: 20/12/2014 01:15:27
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
14 #ifndef GK_TEXTURE_HPP_
15 #define GK_TEXTURE_HPP_
16 
17 #include <string>
18 
19 #include "gk/core/IntTypes.hpp"
20 #include "gk/core/SDLHeaders.hpp"
21 #include "gk/gl/OpenGL.hpp"
22 #include "gk/utils/NonCopyable.hpp"
23 
24 namespace gk {
25 
30 class Texture : public NonCopyable {
31  public:
38  Texture() = default;
39 
46  Texture(const std::string &filename);
47 
54  Texture(SDL_Surface *surface);
55 
62  Texture(Texture &&texture);
63 
68  ~Texture() noexcept;
69 
76  Texture &operator=(Texture &&texture);
77 
84  void loadFromFile(const std::string &filename);
85 
92  void loadFromSurface(SDL_Surface *surface);
93 
100  static void bind(const Texture *texture);
101 
108  const std::string &filename() const { return m_filename; }
109 
116  u16 width() const { return m_width; }
117 
124  u16 height() const { return m_height; }
125 
126  private:
128  // Member data
130  std::string m_filename;
131 
134 
135  GLuint m_texture = 0;
136 };
137 
138 } // namespace gk
139 
140 #endif // GK_TEXTURE_HPP_
141 
void loadFromFile(const std::string &filename)
Load the texture from a file on the disk.
Definition: Texture.cpp:54
unsigned short u16
Definition: IntTypes.hpp:22
static void bind(const Texture *texture)
Bind a texture for rendering.
Definition: Texture.cpp:94
void loadFromSurface(SDL_Surface *surface)
Load the texture from a SDL_Surface.
Definition: Texture.cpp:67
GLuint m_texture
Internal OpenGL texture ID.
Definition: Texture.hpp:135
u16 m_width
Width of the texture.
Definition: Texture.hpp:132
Texture & operator=(Texture &&texture)
Move assignement operator.
Definition: Texture.cpp:42
Image living on the graphics card that can be used for drawing.
Definition: Texture.hpp:30
u16 height() const
Return the height of the texture.
Definition: Texture.hpp:124
const std::string & filename() const
Return the filename of the texture.
Definition: Texture.hpp:108
~Texture() noexcept
Destructor.
Definition: Texture.cpp:38
u16 width() const
Return the width of the texture.
Definition: Texture.hpp:116
std::string m_filename
Texture filename.
Definition: Texture.hpp:130
u16 m_height
Height of the texture.
Definition: Texture.hpp:133
Texture()=default
Default constructor.