2022-08-29 21:01:55 +02:00
|
|
|
#ifndef CONSTANTS_HPP
|
2022-09-05 20:17:25 +02:00
|
|
|
#define CONSTANTS_HPP
|
2022-08-31 20:40:41 +02:00
|
|
|
#include <GLFW/glfw3.h>
|
2022-08-29 21:01:55 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
#include <string_view>
|
|
|
|
|
|
2022-10-19 15:46:29 +02:00
|
|
|
namespace constants
|
2022-08-29 21:01:55 +02:00
|
|
|
{
|
2022-10-19 15:46:29 +02:00
|
|
|
inline constexpr int GLFW_MAJOR_VERSION{3};
|
|
|
|
|
inline constexpr int GLFW_MINOR_VERSION{3};
|
2022-08-29 21:01:55 +02:00
|
|
|
// best practice is to use inline constexpr std::string_view but glfwCreateWindow takes only char* as input
|
2022-10-19 15:46:29 +02:00
|
|
|
inline const char *MAIN_WINDOW_NAME{"Match"};
|
|
|
|
|
inline constexpr int MAIN_WINDOW_WIDTH{800};
|
|
|
|
|
inline constexpr int MAIN_WINDOW_HEIGHT{600};
|
|
|
|
|
inline constexpr struct
|
|
|
|
|
{
|
2022-08-31 20:40:41 +02:00
|
|
|
GLfloat red = 1.0f;
|
|
|
|
|
GLfloat green = 0.0f;
|
|
|
|
|
GLfloat blue = 0.0f;
|
|
|
|
|
GLfloat alpha = 1.0f;
|
|
|
|
|
} RED;
|
|
|
|
|
|
2022-10-19 15:46:29 +02:00
|
|
|
inline constexpr struct
|
|
|
|
|
{
|
2022-08-31 20:40:41 +02:00
|
|
|
GLfloat red = 1.0f;
|
|
|
|
|
GLfloat green = 1.0f;
|
|
|
|
|
GLfloat blue = 1.0f;
|
|
|
|
|
GLfloat alpha = 1.0f;
|
|
|
|
|
} WHITE;
|
|
|
|
|
|
2022-10-19 15:46:29 +02:00
|
|
|
inline constexpr struct
|
|
|
|
|
{
|
2022-08-31 20:40:41 +02:00
|
|
|
GLfloat red = 0.2f;
|
|
|
|
|
GLfloat green = 0.3f;
|
|
|
|
|
GLfloat blue = 0.3f;
|
|
|
|
|
GLfloat alpha = 1.0f;
|
|
|
|
|
} LEARN_OPEN_GL_COLOR;
|
2022-08-29 21:01:55 +02:00
|
|
|
|
2022-10-19 15:46:29 +02:00
|
|
|
// we write vertex shader
|
2022-09-01 20:08:15 +02:00
|
|
|
// version of glsl (since ogl 3.3 same as ogl so we pick 330)
|
|
|
|
|
// in this shader we just forward input data to shader output
|
2022-10-19 15:46:29 +02:00
|
|
|
inline const char *VERTEX_SHADER_SOURCE{"#version 330 core\n"
|
|
|
|
|
"layout (location = 0) in vec3 aPos;\n"
|
|
|
|
|
"void main()\n"
|
|
|
|
|
"{\n"
|
|
|
|
|
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
|
|
|
|
"}\0"};
|
2022-09-17 16:32:48 +02:00
|
|
|
|
2022-09-01 20:08:15 +02:00
|
|
|
// write fragment shader
|
|
|
|
|
// we set the color of each pixel to be orange
|
2022-10-19 15:46:29 +02:00
|
|
|
inline const char *FRAGMENT_SHADER_SOURCE{
|
2022-09-01 20:08:15 +02:00
|
|
|
"#version 330 core\n"
|
|
|
|
|
"out vec4 FragColor;\n"
|
|
|
|
|
"void main()\n"
|
|
|
|
|
"{\n"
|
2022-10-19 15:46:29 +02:00
|
|
|
"FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
|
|
|
|
|
"}\0"};
|
2022-09-01 20:08:15 +02:00
|
|
|
|
2022-10-19 15:46:29 +02:00
|
|
|
inline const char *FRAGMENT_SHADER_SOURCE_YELLOW{
|
2022-09-17 14:14:08 +02:00
|
|
|
"#version 330 core\n"
|
|
|
|
|
"out vec4 FragColor;\n"
|
|
|
|
|
"void main()\n"
|
|
|
|
|
"{\n"
|
2022-10-19 15:46:29 +02:00
|
|
|
"FragColor = vec4(1.0f, 1.0f, 0.0f, 1.0f);\n"
|
|
|
|
|
"}\0"};
|
2022-09-17 14:14:08 +02:00
|
|
|
|
2022-09-02 19:57:09 +02:00
|
|
|
// we specify three vertices
|
|
|
|
|
// each of them with position in 3d space
|
|
|
|
|
// x y z
|
2022-10-19 15:46:29 +02:00
|
|
|
inline constexpr float TRIANGLE_VERTICES[]{
|
2022-09-02 19:57:09 +02:00
|
|
|
-0.5f, -0.5f, 0.0f,
|
|
|
|
|
0.5f, -0.5f, 0.0f,
|
2022-10-19 15:46:29 +02:00
|
|
|
0.0f, 0.5f, 0.0f};
|
2022-09-02 19:57:09 +02:00
|
|
|
|
2022-10-19 15:46:29 +02:00
|
|
|
inline constexpr size_t TRIANGLE_VERTICES_SIZE = {sizeof(TRIANGLE_VERTICES)};
|
2022-09-02 19:57:09 +02:00
|
|
|
|
2022-10-19 15:46:29 +02:00
|
|
|
inline constexpr float TRIANGLES_VERTICES[]{
|
2022-09-17 14:14:08 +02:00
|
|
|
// first triangle
|
2022-10-19 15:46:29 +02:00
|
|
|
-0.9f, -0.5f, 0.0f, // left
|
|
|
|
|
-0.0f, -0.5f, 0.0f, // right
|
|
|
|
|
-0.45f, 0.5f, 0.0f, // top
|
|
|
|
|
// second triangle
|
|
|
|
|
0.0f, -0.5f, 0.0f, // left
|
|
|
|
|
0.9f, -0.5f, 0.0f, // right
|
|
|
|
|
0.45f, 0.5f, 0.0f // top
|
2022-09-17 14:14:08 +02:00
|
|
|
};
|
|
|
|
|
|
2022-10-19 15:46:29 +02:00
|
|
|
inline constexpr size_t TRIANGLES_VERTICES_SIZE = {sizeof(TRIANGLES_VERTICES)};
|
2022-09-17 14:14:08 +02:00
|
|
|
|
2022-10-19 15:46:29 +02:00
|
|
|
inline constexpr float TRIANGLE_ONE[]{
|
2022-09-17 14:14:08 +02:00
|
|
|
// first triangle
|
2022-10-19 15:46:29 +02:00
|
|
|
-0.9f, -0.5f, 0.0f, // left
|
|
|
|
|
-0.0f, -0.5f, 0.0f, // right
|
|
|
|
|
-0.45f, 0.5f, 0.0f, // top
|
2022-09-17 14:14:08 +02:00
|
|
|
};
|
|
|
|
|
|
2022-10-19 15:46:29 +02:00
|
|
|
inline constexpr size_t TRIANGLE_ONE_SIZE = {sizeof(TRIANGLE_ONE)};
|
2022-09-17 14:14:08 +02:00
|
|
|
|
2022-10-19 15:46:29 +02:00
|
|
|
inline constexpr float TRIANGLE_TWO[]{
|
2022-09-17 14:14:08 +02:00
|
|
|
// second triangle
|
2022-10-19 15:46:29 +02:00
|
|
|
0.0f, -0.5f, 0.0f, // left
|
|
|
|
|
0.9f, -0.5f, 0.0f, // right
|
|
|
|
|
0.45f, 0.5f, 0.0f // top
|
2022-09-17 14:14:08 +02:00
|
|
|
};
|
|
|
|
|
|
2022-10-19 15:46:29 +02:00
|
|
|
inline constexpr size_t TRIANGLE_TWO_SIZE = {sizeof(TRIANGLE_TWO)};
|
2022-09-17 14:14:08 +02:00
|
|
|
|
2022-09-04 21:25:01 +02:00
|
|
|
// compare with square done with only vertices:
|
|
|
|
|
/*
|
|
|
|
|
float vertices[] = {
|
|
|
|
|
// first triangle
|
|
|
|
|
0.5f, 0.5f, 0.0f, // top right
|
|
|
|
|
0.5f, -0.5f, 0.0f, // bottom right
|
2022-10-19 15:46:29 +02:00
|
|
|
-0.5f, 0.5f, 0.0f, // top left
|
2022-09-04 21:25:01 +02:00
|
|
|
// second triangle
|
|
|
|
|
0.5f, -0.5f, 0.0f, // bottom right
|
|
|
|
|
-0.5f, -0.5f, 0.0f, // bottom left
|
|
|
|
|
-0.5f, 0.5f, 0.0f // top left
|
|
|
|
|
};
|
2022-10-19 15:46:29 +02:00
|
|
|
bottom right and top left is specified twice !
|
2022-09-04 21:25:01 +02:00
|
|
|
*/
|
2022-10-19 15:46:29 +02:00
|
|
|
inline constexpr float SQUARE_VERTICES[]{
|
|
|
|
|
0.5f, 0.5f, 0.0f, // top right
|
2022-09-04 21:25:01 +02:00
|
|
|
0.5f, -0.5f, 0.0f, // bottom right
|
2022-10-19 15:46:29 +02:00
|
|
|
-0.5f, -0.5f, 0.0f, // bottom left
|
|
|
|
|
-0.5f, 0.5f, 0.0f // top left
|
2022-09-04 21:25:01 +02:00
|
|
|
};
|
|
|
|
|
|
2022-10-19 15:46:29 +02:00
|
|
|
inline constexpr unsigned int SQUARE_INDICES[]{
|
|
|
|
|
0, 1, 3, // first triangle
|
|
|
|
|
1, 2, 3 // second triangle
|
2022-09-04 21:25:01 +02:00
|
|
|
};
|
|
|
|
|
|
2022-10-19 15:46:29 +02:00
|
|
|
inline constexpr size_t SQUARE_INDICES_SIZE = {sizeof(SQUARE_INDICES)};
|
2022-09-04 21:25:01 +02:00
|
|
|
|
2022-10-19 15:46:29 +02:00
|
|
|
inline constexpr size_t SQUARE_VERTICES_SIZE = {sizeof(SQUARE_VERTICES)};
|
2022-09-04 21:25:01 +02:00
|
|
|
|
2022-10-19 15:46:29 +02:00
|
|
|
inline constexpr int MAX_DRAW_CALL = {4};
|
2022-09-10 13:40:58 +02:00
|
|
|
|
2022-08-29 21:01:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|