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
26
31{
32public:
36 Texture();
37 Texture(const std::string& fileName);
38 ~Texture();
39
40 Texture(const Texture& other);
41 Texture(Texture&& other) noexcept;
42 auto operator=(const Texture& other) -> Texture&;
43 auto operator=(Texture&& other) noexcept -> Texture&;
44
45 auto activate() const -> void;
46 auto deactivate() const -> void;
47
48 auto loadFile(const std::string& fileName) -> void;
49
50 [[nodiscard]] auto getTextureWidth() const -> int;
51
52 [[nodiscard]] auto getTextureHeight() const -> int;
53
54 [[nodiscard]] auto getTilesWide() const -> unsigned;
55
56 [[nodiscard]] auto getTilesHigh() const -> unsigned;
57
58 [[nodiscard]] auto getFrames() const -> unsigned;
59
60public:
61 auto save(Stream& stream) const -> void;
62 auto load(Stream& stream) -> void;
63
68 [[nodiscard]] auto name() const -> const std::string&;
69
74 auto name(const std::string& name) -> void;
75
76 friend auto to_json(json& j, const Texture& a) -> void;
77 friend auto from_json(const json& j, Texture& a) -> void;
78
80 auto getTextureID() const -> GLuint;
81
82private:
86 std::string _name;
90 std::string imagePath;
92 unsigned char* imageData;
93 GLenum format{GL_RGBA};
95
97 unsigned tilesWide = 1;
98 unsigned tilesHigh = 1;
100 unsigned frames = 1;
101};
sys::Json Stream
Definition AudioObject.h:20
unsigned int GLuint
Definition IndexBuffer.h:17
nlohmann::json json
Definition Json.cpp:19
~Texture()
Definition Texture.cpp:47
auto getTilesWide() const -> unsigned
Definition Texture.cpp:193
auto load(Stream &stream) -> void
Definition Texture.cpp:213
unsigned frames
The total number of frames the texture has if it is a spritesheet.
Definition Texture.h:100
int textureWidth
Definition Texture.h:91
auto save(Stream &stream) const -> void
Definition Texture.cpp:208
auto name() const -> const std::string &
Definition Texture.cpp:218
int textureHeight
Definition Texture.h:91
std::string imagePath
the path to the image that was loaded from
Definition Texture.h:90
GLenum format
Definition Texture.h:93
auto loadFile(const std::string &fileName) -> void
Definition Texture.cpp:126
auto getFrames() const -> unsigned
Definition Texture.cpp:203
auto deactivate() const -> void
Definition Texture.cpp:121
friend auto to_json(json &j, const Texture &a) -> void
Definition Texture.cpp:238
friend auto from_json(const json &j, Texture &a) -> void
Definition Texture.cpp:247
auto getTilesHigh() const -> unsigned
Definition Texture.cpp:198
unsigned char * imageData
Definition Texture.h:92
Texture()
default ctor, don't use, it doesn't make sense.
Definition Texture.cpp:30
unsigned tilesHigh
Definition Texture.h:98
auto getTextureWidth() const -> int
Definition Texture.cpp:183
unsigned tilesWide
The number of tiles wide of the image as a spritesheet.
Definition Texture.h:97
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:86
auto operator=(const Texture &other) -> Texture &
Definition Texture.cpp:84
GLuint textureID
Definition Texture.h:94
auto getTextureHeight() const -> int
Definition Texture.cpp:188
auto activate() const -> void
Definition Texture.cpp:116
auto getTextureID() const -> GLuint
get the opengl id of texture
Definition Texture.cpp:228
int numPerPixel
Definition Texture.h:91
Definition Json.h:32