3#define _USE_MATH_DEFINES
10namespace fs = std::filesystem;
21#define DEBUG_BREAK __debugbreak()
30#define DEBUG_BREAK __builtin_trap()
39#define GLcall_P(y, x) \
42 ASSERT(GLLogCall(#x, __FILE__, __LINE__))
46 ASSERT(GLLogCall(#x, __FILE__, __LINE__))
49#define GLcall_P(y, x) y = x
59 while (glGetError() != GL_NO_ERROR)
63inline bool GLLogCall(
const char *
function,
const char *file,
int line) {
64 while (GLenum errorcode = glGetError()) {
68 error =
"INVALID_ENUM";
70 case GL_INVALID_VALUE:
71 error =
"INVALID_VALUE";
73 case GL_INVALID_OPERATION:
74 error =
"INVALID_OPERATION";
76 case GL_STACK_OVERFLOW:
77 error =
"STACK_OVERFLOW";
79 case GL_STACK_UNDERFLOW:
80 error =
"STACK_UNDERFLOW";
82 case GL_OUT_OF_MEMORY:
83 error =
"OUT_OF_MEMORY";
85 case GL_INVALID_FRAMEBUFFER_OPERATION:
86 error =
"INVALID_FRAMEBUFFER_OPERATION";
89 std::cout <<
"[Opengl Error] ( Error code :" << errorcode <<
" : " << error <<
" )" <<
function <<
" " << file <<
" : " << line << std::endl;
105 return vec3(temp.x, temp.y, temp.z);
169 color(uint8_t
r, uint8_t
g, uint8_t
b, uint8_t
a = 255) :
col((
a << 24u) | (
b << 16u) | (
g << 8u) |
r) {}
170 explicit color(
const vec3 &in) :
color(fabs(in.x) * 255, fabs(in.y) * 255, fabs(in.z) * 255) {}
173 auto temp = (uint8_t *)&
col;
174 return vec4(temp[0], temp[1], temp[2], temp[3]) / 255;
178 auto temp = (uint8_t *)&
col;
179 return vec3(temp[0], temp[1], temp[2]) / 255;
182 [[nodiscard]]
inline uint8_t
r()
const {
183 auto temp = (uint8_t *)&
col;
186 [[nodiscard]]
inline uint8_t
g()
const {
187 auto temp = (uint8_t *)&
col;
190 [[nodiscard]]
inline uint8_t
b()
const {
191 auto temp = (uint8_t *)&
col;
194 [[nodiscard]]
inline uint8_t
a()
const {
195 auto temp = (uint8_t *)&
col;
199 [[nodiscard]]
inline uint8_t &
r() {
200 auto temp = (uint8_t *)&
col;
203 [[nodiscard]]
inline uint8_t &
g() {
204 auto temp = (uint8_t *)&
col;
207 [[nodiscard]]
inline uint8_t &
b() {
208 auto temp = (uint8_t *)&
col;
211 [[nodiscard]]
inline uint8_t &
a() {
212 auto temp = (uint8_t *)&
col;
217 auto temp = (uint8_t *)&
col;
218 unsigned short r = (
unsigned short)temp[0] * in.
x;
219 unsigned short g = (
unsigned short)temp[1] * in.
y;
220 unsigned short b = (
unsigned short)temp[2] * in.
z;
221 return color(
r > 255 ? 255 :
r,
g > 255 ? 255 :
g,
b > 255 ? 255 :
b,
a());
225 auto temp = (uint8_t *)&
col;
226 unsigned short r = (
unsigned short)temp[0] * in.
x;
227 unsigned short g = (
unsigned short)temp[1] * in.
y;
228 unsigned short b = (
unsigned short)temp[2] * in.
z;
229 col = ((
a() << 24u) | (
b > 255 ? 255 :
b << 16u) | (
g > 255 ? 255 : g << 8u) | r > 255 ? 255 :
r);
233 auto temp = (uint8_t *)&
col;
234 auto temp1 = (uint8_t *)&in.
col;
235 auto r = ((
unsigned short)temp[0] * temp1[0]) / 255u;
236 auto g = ((
unsigned short)temp[1] * temp1[1]) / 255u;
237 auto b = ((
unsigned short)temp[2] * temp1[2]) / 255u;
238 auto a = ((
unsigned short)temp[3] * temp1[3]) / 255u;
240 return std::move(ret);
244 auto temp = (uint8_t *)&
col;
245 auto temp1 = (uint8_t *)&in.
col;
246 temp[0] = ((
unsigned short)temp[0] * temp1[0]) / 255u;
247 temp[1] = ((
unsigned short)temp[1] * temp1[1]) / 255u;
248 temp[2] = ((
unsigned short)temp[2] * temp1[2]) / 255u;
249 temp[3] = ((
unsigned short)temp[3] * temp1[3]) / 255u;
253 auto temp = (uint8_t *)&
col;
254 auto temp1 = (uint8_t *)&in.
col;
255 unsigned short r = (
unsigned short)temp[0] + temp1[0];
256 unsigned short g = (
unsigned short)temp[1] + temp1[1];
257 unsigned short b = (
unsigned short)temp[2] + temp1[2];
258 unsigned short a = (
unsigned short)temp[3] + temp1[3];
259 return color(
r > 255 ? 255 :
r,
g > 255 ? 255 :
g,
b > 255 ? 255 :
b,
a > 255 ? 255 :
a);
263 auto temp = (uint8_t *)&
col;
264 auto temp1 = (uint8_t *)&in.
col;
265 unsigned short r = (
unsigned short)temp[0] + temp1[0];
266 unsigned short g = (
unsigned short)temp[1] + temp1[1];
267 unsigned short b = (
unsigned short)temp[2] + temp1[2];
268 unsigned short a = (
unsigned short)temp[3] + temp1[3];
269 temp[0] =
r > 255 ? 255 :
r;
270 temp[1] =
g > 255 ? 255 :
g;
271 temp[2] =
b > 255 ? 255 :
b;
272 temp[3] =
a > 255 ? 255 :
a;
276 auto temp = (uint8_t *)&
col;
277 unsigned short r = (
unsigned short)temp[0] * in;
278 unsigned short g = (
unsigned short)temp[1] * in;
279 unsigned short b = (
unsigned short)temp[2] * in;
280 return color(
r > 255 ? 255 :
r,
g > 255 ? 255 :
g,
b > 255 ? 255 :
b);
284 auto temp = (uint8_t *)&
col;
285 unsigned short r = (
unsigned short)temp[0] * in;
286 unsigned short g = (
unsigned short)temp[1] * in;
287 unsigned short b = (
unsigned short)temp[2] * in;
288 temp[0] =
r > 255 ? 255 :
r;
289 temp[1] =
g > 255 ? 255 :
g;
290 temp[2] =
b > 255 ? 255 :
b;
299static std::string searchRes() {
300 auto currentPath = fs::current_path();
302 auto orgiPath = currentPath;
303 bool resPathFound =
false, appPathFound =
false;
306 if (!resPathFound && !appPathFound && currentPath.has_parent_path()) {
307 fs::current_path(currentPath.parent_path());
308 currentPath = fs::current_path();
309 }
else if (appPathFound) {
312 auto a = currentPath.string().append(
"\\res");
314 auto a = currentPath.string().append(
"/res");
317 fs::current_path(orgiPath);
319 }
catch (
const std::exception &e) {
320 std::cout << e.what() <<
"\n \"res\" folder not found inside \"Application\" folder \n";
321 return std::string();
328 for (
auto &dirs : fs::directory_iterator(currentPath)) {
329 if (dirs.is_directory() && dirs.path().filename().string() ==
"Application") {
336 std::cout <<
"folder \"Application\" not found in 4 back iterations" << std::endl;
338 return std::string();
A general matrix class for any size of matrix.
bool GLLogCall(const char *function, const char *file, int line)
const std::string pathDelemeter("/")
vec3 operator*(glm::mat4 mat, vec3 vec)
void operator*=(const float &f)
static Vertex perspectiveMul(Vertex in, const mat4f &per)
Vertex perspectiveMul(const mat4f &per)
Vertex(const vec4 &pos, const vec3 &nor=vec3(0), const vec2 &texcoord=vec2(0))
void operator/=(const float &f)
Vertex operator+(const Vertex &f) const
Vertex operator*(const float &f) const
Vertex operator-(const Vertex &f) const
class that holds color with 8 bits per channel with 4 channels rgba.
color operator*(const vec3 &in) const
void operator*=(const color &in)
color operator*(const color &in) const
bool operator==(const color &in)
void operator+=(const color &in)
vec3 getcolorVec3() const
color(uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
color operator+(const color &in) const
color operator*(const float &in) const
void operator*=(const float &in)
void operator*=(const vec3 &in)
dirLight(const vec3 &dir=vec3::normalize(vec3(1)), const float &intensity=1, const color &diffcol=color(255))
vec3_T< float > normalize()