Skip to content

Commit e39da1a

Browse files
committed
Added texture and window constructor
1 parent 00ba0c9 commit e39da1a

File tree

2 files changed

+39
-36
lines changed

2 files changed

+39
-36
lines changed

include/Texture.hpp

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@ namespace raylib {
1414
* Texture type
1515
*/
1616
class Texture : public ::Texture {
17-
public:
17+
public:
1818
/**
19-
* Default constructor to create an empty Texture object.
19+
* Default texture constructor.
2020
*/
21-
Texture(unsigned int id = 0,
22-
int width = 0,
23-
int height = 0,
24-
int mipmaps = 0,
25-
int format = 0) : ::Texture{id, width, height, mipmaps, format} {
26-
// Nothing.
21+
Texture() {
22+
set(::Texture{0, 0, 0, 0, 0});
23+
}
24+
25+
/**
26+
* Move/Create a texture structure manually.
27+
*/
28+
Texture(unsigned int id, int width, int height, int mipmaps, int format) {
29+
set(::Texture{id, width, height, mipmaps, format});
2730
}
2831

2932
/**
@@ -39,9 +42,7 @@ class Texture : public ::Texture {
3942
* @throws raylib::RaylibException Throws if failed to create the texture from the given image.
4043
*/
4144
Texture(const ::Image& image) {
42-
if (!Load(image)) {
43-
throw RaylibException("Failed to load Texture from Image");
44-
}
45+
Load(image);
4546
}
4647

4748
/**
@@ -52,9 +53,7 @@ class Texture : public ::Texture {
5253
* @see LoadTextureCubemap()
5354
*/
5455
Texture(const ::Image& image, int layout) {
55-
if (!Load(image, layout)) {
56-
throw RaylibException("Failed to load Texture from Cubemap");
57-
}
56+
Load(image, layout);
5857
}
5958

6059
/**
@@ -63,9 +62,7 @@ class Texture : public ::Texture {
6362
* @throws raylib::RaylibException Throws if failed to create the texture from the given file.
6463
*/
6564
Texture(const std::string& fileName) {
66-
if (!Load(fileName)) {
67-
throw RaylibException(TextFormat("Failed to load Texture from file: %s", fileName.c_str()));
68-
}
65+
Load(fileName);
6966
}
7067

7168
Texture(const Texture&) = delete;
@@ -124,25 +121,31 @@ class Texture : public ::Texture {
124121
/**
125122
* Load texture from image data
126123
*/
127-
bool Load(const ::Image& image) {
124+
void Load(const ::Image& image) {
128125
set(::LoadTextureFromImage(image));
129-
return IsReady();
126+
if (!IsReady()) {
127+
throw RaylibException("Failed to load Texture from Image");
128+
}
130129
}
131130

132131
/**
133132
* Load cubemap from image, multiple image cubemap layouts supported
134133
*/
135-
bool Load(const ::Image& image, int layoutType) {
134+
void Load(const ::Image& image, int layoutType) {
136135
set(::LoadTextureCubemap(image, layoutType));
137-
return IsReady();
136+
if (!IsReady()) {
137+
throw RaylibException("Failed to load Texture from Cubemap");
138+
}
138139
}
139140

140141
/**
141142
* Load texture from file into GPU memory (VRAM)
142143
*/
143-
bool Load(const std::string& fileName) {
144+
void Load(const std::string& fileName) {
144145
set(::LoadTexture(fileName.c_str()));
145-
return IsReady();
146+
if (!IsReady()) {
147+
throw RaylibException("Failed to load Texture from file: " + fileName);
148+
}
146149
}
147150

148151
/**
@@ -306,7 +309,7 @@ class Texture : public ::Texture {
306309
return id != 0;
307310
}
308311

309-
private:
312+
private:
310313
void set(const ::Texture& texture) {
311314
id = texture.id;
312315
width = texture.width;

include/Window.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,16 @@ namespace raylib {
1111
* Window and Graphics Device Functions.
1212
*/
1313
class Window {
14-
public:
14+
public:
15+
Window() {
16+
// need to create it manually with Init().
17+
}
18+
1519
/**
1620
* Initialize window and OpenGL context.
17-
*
18-
* @throws raylib::RaylibException Thrown if the window failed to initiate.
1921
*/
20-
Window(int width = 800, int height = 450, const std::string& title = "raylib",
21-
bool lateInit = false) {
22-
if (!lateInit) {
23-
if (!Init(width, height, title)) {
24-
throw RaylibException("Failed to create Window");
25-
}
26-
}
22+
Window(int width, int height, const std::string& title) {
23+
Init(width, height, title);
2724
}
2825

2926
/**
@@ -36,11 +33,14 @@ class Window {
3633
/**
3734
* Initializes the window.
3835
*
36+
* @throws raylib::RaylibException Thrown if the window failed to initiate.
3937
* @return True or false, depending on if the Window initialized properly.
4038
*/
41-
bool Init(int width = 800, int height = 450, const std::string& title = "raylib") {
39+
void Init(int width = 800, int height = 450, const std::string& title = "raylib") {
4240
::InitWindow(width, height, title.c_str());
43-
return IsWindowReady();
41+
if (!IsWindowReady()) {
42+
throw RaylibException("Failed to create Window");
43+
}
4444
}
4545

4646
/**

0 commit comments

Comments
 (0)