Brunot
Loading...
Searching...
No Matches
Texture.h
Go to the documentation of this file.
1
11// ____ __ __ __
12// /\__ _\/\ \ /\ \/\ \
13// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
14// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
15// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
16// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
17// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
18#pragma once
19#include <string>
20#include "System/opengl.h"
21#include "System/json.h"
22#include "Framework/Library.h"
23
24
25using Stream = sys::Json; // replace with whatever stream we are using
26namespace gfx
27{
28
33{
34public:
38 Texture();
39 Texture(const std::string& fileName);
40 ~Texture();
41
42 Texture(const Texture& other);
43 Texture(Texture&& other) noexcept;
44 auto operator=(const Texture& other) -> Texture&;
45 auto operator=(Texture&& other) noexcept -> Texture&;
46
47 auto activate() const -> void;
48 auto deactivate() const -> void;
49
50 auto loadFile(const std::string& fileName) -> void;
51
52 [[nodiscard]] auto getTextureWidth() const -> int;
53
54 [[nodiscard]] auto getTextureHeight() const -> int;
55
56 [[nodiscard]] auto getTilesWide() const -> unsigned;
57
58 [[nodiscard]] auto getTilesHigh() const -> unsigned;
59
60 [[nodiscard]] auto getFrames() const -> unsigned;
61
62 auto save(Stream& stream) const -> void;
63 auto load(const Stream& stream) -> void;
64
69 [[nodiscard]] auto name() const -> const std::string&;
70
75 auto name(const std::string& name) -> void;
76
77 friend auto to_json(json& j, const Texture& a) -> void;
78 friend auto from_json(const json& j, Texture& a) -> void;
79
81 auto getTextureID() const -> GLuint;
82
83private:
87 std::string _name;
91 std::string imagePath;
93 unsigned char* imageData;
94 GLenum format{GL_RGBA};
96
98 unsigned tilesWide = 1;
99 unsigned tilesHigh = 1;
101 unsigned frames = 1;
102};
103}
sys::Json Stream
Definition AudioObject.h:20
unsigned int GLuint
Definition IndexBuffer.h:17
nlohmann::json json
Definition Json.cpp:19
GLenum format
Definition Texture.h:94
auto deactivate() const -> void
Definition Texture.cpp:124
int textureHeight
Definition Texture.h:92
auto getFrames() const -> unsigned
Definition Texture.cpp:206
auto save(Stream &stream) const -> void
Definition Texture.cpp:211
auto getTilesWide() const -> unsigned
Definition Texture.cpp:196
unsigned tilesWide
The number of tiles wide of the image as a spritesheet.
Definition Texture.h:98
auto getTextureHeight() const -> int
Definition Texture.cpp:191
friend auto to_json(json &j, const Texture &a) -> void
Definition Texture.cpp:241
friend auto from_json(const json &j, Texture &a) -> void
Definition Texture.cpp:250
auto loadFile(const std::string &fileName) -> void
Definition Texture.cpp:129
auto operator=(const Texture &other) -> Texture &
Definition Texture.cpp:87
int textureWidth
Definition Texture.h:92
unsigned char * imageData
Definition Texture.h:93
auto name() const -> const std::string &
Definition Texture.cpp:221
auto activate() const -> void
Definition Texture.cpp:119
Texture()
default ctor, don't use, it doesn't make sense.
Definition Texture.cpp:33
GLuint textureID
Definition Texture.h:95
int numPerPixel
Definition Texture.h:92
auto getTextureID() const -> GLuint
get the opengl id of texture
Definition Texture.cpp:231
~Texture()
Definition Texture.cpp:50
unsigned tilesHigh
Definition Texture.h:99
auto load(const Stream &stream) -> void
Definition Texture.cpp:216
std::string imagePath
the path to the image that was loaded from
Definition Texture.h:91
auto getTextureWidth() const -> int
Definition Texture.cpp:186
unsigned frames
The total number of frames the texture has if it is a spritesheet.
Definition Texture.h:101
std::string _name
Sprite will save the name of the texture it needs to load, so that multiple sprites can use the same ...
Definition Texture.h:87
auto getTilesHigh() const -> unsigned
Definition Texture.cpp:201
Definition Json.h:32
Definition Sprite.h:25