mirror of
https://github.com/kuhyx/engineer-thesis-WUT.git
synced 2026-07-04 13:03:07 +02:00
feat: add infinite amount of textures
This commit is contained in:
parent
e5a609d7f9
commit
75054ed91f
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -98,7 +98,11 @@
|
||||
"cSpell.words": [
|
||||
"awesomeface",
|
||||
"kuchy",
|
||||
"MIPMAP",
|
||||
"mipmaps",
|
||||
"multiplatform",
|
||||
"Parameterfv",
|
||||
"Parameteri",
|
||||
"RENDERLOOP",
|
||||
"VERTICE"
|
||||
]
|
||||
|
||||
4
.vscode/tasks.json
vendored
4
.vscode/tasks.json
vendored
@ -20,7 +20,9 @@
|
||||
"-lGLU",
|
||||
"-lGL",
|
||||
"-lm",
|
||||
"-ldl"
|
||||
"-ldl",
|
||||
"-pipe",
|
||||
"-O0"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${fileDirname}"
|
||||
|
||||
16
Engine/engine/Shaders/fragmentShaderTextureTaskOne.fs
Normal file
16
Engine/engine/Shaders/fragmentShaderTextureTaskOne.fs
Normal file
@ -0,0 +1,16 @@
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec3 ourColor;
|
||||
in vec2 TexCoord;
|
||||
|
||||
// texture samplers
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D texture2;
|
||||
|
||||
void main()
|
||||
{
|
||||
// linearly interpolate between both textures (80% container, 20% awesomeface)
|
||||
FragColor = mix(texture(texture1, TexCoord), texture(texture2, vec2(1.0 - TexCoord.x, TexCoord.y)), 0.2);
|
||||
}
|
||||
|
||||
BIN
Engine/engine/assets/Textures/no_texture.png
Normal file
BIN
Engine/engine/assets/Textures/no_texture.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
@ -3,211 +3,238 @@
|
||||
#define ENGINE_ENGINE_CONSTANTS_HPP_
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string_view>
|
||||
|
||||
namespace constants {
|
||||
inline constexpr int GLFW_MAJOR_VERSION{3};
|
||||
inline constexpr int GLFW_MINOR_VERSION{3};
|
||||
// best practice is to use inline constexpr
|
||||
// std::string_view but glfwCreateWindow takes only char* as input
|
||||
inline const char* MAIN_WINDOW_NAME{"Match"};
|
||||
inline constexpr int MAIN_WINDOW_WIDTH{800};
|
||||
inline constexpr int MAIN_WINDOW_HEIGHT{600};
|
||||
inline constexpr struct {
|
||||
GLfloat red = 1.0f;
|
||||
GLfloat green = 0.0f;
|
||||
GLfloat blue = 0.0f;
|
||||
GLfloat alpha = 1.0f;
|
||||
} RED;
|
||||
inline constexpr int GLFW_MAJOR_VERSION{3};
|
||||
inline constexpr int GLFW_MINOR_VERSION{3};
|
||||
// best practice is to use inline constexpr
|
||||
// std::string_view but glfwCreateWindow takes only char* as input
|
||||
inline const char* MAIN_WINDOW_NAME{"Match"};
|
||||
inline constexpr int MAIN_WINDOW_WIDTH{800};
|
||||
inline constexpr int MAIN_WINDOW_HEIGHT{600};
|
||||
inline constexpr struct {
|
||||
GLfloat red = 1.0f;
|
||||
GLfloat green = 0.0f;
|
||||
GLfloat blue = 0.0f;
|
||||
GLfloat alpha = 1.0f;
|
||||
} RED;
|
||||
|
||||
inline constexpr struct {
|
||||
GLfloat red = 1.0f;
|
||||
GLfloat green = 1.0f;
|
||||
GLfloat blue = 1.0f;
|
||||
GLfloat alpha = 1.0f;
|
||||
} WHITE;
|
||||
inline constexpr struct {
|
||||
GLfloat red = 1.0f;
|
||||
GLfloat green = 1.0f;
|
||||
GLfloat blue = 1.0f;
|
||||
GLfloat alpha = 1.0f;
|
||||
} WHITE;
|
||||
|
||||
inline constexpr struct {
|
||||
GLfloat red = 0.2f;
|
||||
GLfloat green = 0.3f;
|
||||
GLfloat blue = 0.3f;
|
||||
GLfloat alpha = 1.0f;
|
||||
} LEARN_OPEN_GL_COLOR;
|
||||
inline constexpr struct {
|
||||
GLfloat red = 0.2f;
|
||||
GLfloat green = 0.3f;
|
||||
GLfloat blue = 0.3f;
|
||||
GLfloat alpha = 1.0f;
|
||||
} LEARN_OPEN_GL_COLOR;
|
||||
|
||||
inline const char* VERTEX_SHADER_COLOR_FILENAME{
|
||||
"./Shaders/vertexShaderColor.vs"};
|
||||
|
||||
inline const char* VERTEX_SHADER_UPSIDE_DOWN_FILENAME{
|
||||
"./Shaders/vertexShaderUpsideDown.vs"};
|
||||
|
||||
inline const char* VERTEX_SHADER_OFFSET_FILENAME{
|
||||
"./Shaders/vertexShaderOffset.vs"};
|
||||
// we write vertex shader
|
||||
// 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
|
||||
// DO NOT REMOVE UNTIL CAN DRAW SQUARE USING CLASS
|
||||
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"};
|
||||
inline const char* VERTEX_SHADER_SOURCE_FILENAME{
|
||||
"./Shaders/vertexShaderSource.vs"};
|
||||
|
||||
inline const char* VERTEX_SHADER_VERTICE_COLOR_FILENAME{
|
||||
"./Shaders/vertexShaderVerticeColor.vs"};
|
||||
|
||||
inline const char* VERTEX_SHADER_TASK_THREE_FILENAME{
|
||||
"./Shaders/vertexShaderTaskThree.vs"};
|
||||
|
||||
inline const char* VERTEX_SHADER_TEXTURE_FILENAME{
|
||||
"./Shaders/vertexShaderTexture.vs"};
|
||||
|
||||
inline const char* FRAGMENT_SHADER_TASK_THREE_FILENAME{
|
||||
"./Shaders/fragmentShaderTaskThree.fs"};
|
||||
|
||||
inline const char* FRAGMENT_SHADER_COLOR_FROM_VERTEX_FILENAME{
|
||||
"./Shaders/fragmentShaderColorFromVertex.fs"};
|
||||
|
||||
inline const char* FRAGMENT_SHADER_UNIFORMS_FILENAME{
|
||||
"./Shaders/fragmentShaderUniforms.fs"};
|
||||
|
||||
// write fragment shader
|
||||
// we set the color of each pixel to be orange
|
||||
// DO NOT REMOVE UNTIL CAN DRAW SQUARE USING CLASS
|
||||
inline const char* FRAGMENT_SHADER_SOURCE{
|
||||
"#version 330 core\n"
|
||||
"out vec4 FragColor;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
"FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
|
||||
"}\0"};
|
||||
|
||||
inline const char* FRAGMENT_SHADER_SOURCE_FILENAME{
|
||||
"./Shaders/fragmentShaderSource.fs"};
|
||||
inline const char* FRAGMENT_SHADER_SOURCE_YELLOW_FILENAME{
|
||||
"./Shaders/fragmentShaderSourceYellow.fs"};
|
||||
|
||||
inline const char* FRAGMENT_SHADER_TEXTURE_FILENAME{
|
||||
"./Shaders/fragmentShaderTexture.fs"};
|
||||
|
||||
// we specify three vertices
|
||||
// each of them with position in 3d space
|
||||
// x y z
|
||||
inline constexpr float TRIANGLE_VERTICES[]{
|
||||
-0.5f, -0.5f, 0.0f,
|
||||
0.5f, -0.5f, 0.0f,
|
||||
0.0f, 0.5f, 0.0f
|
||||
inline const char* NO_TEXTURE_TEXTURE = {
|
||||
"assets/Textures/no_texture.png"
|
||||
};
|
||||
|
||||
inline constexpr size_t TRIANGLE_VERTICES_SIZE = {sizeof(TRIANGLE_VERTICES)};
|
||||
inline const char* AWESOME_FACE_TEXTURE = {
|
||||
"assets/awesomeface.png"
|
||||
};
|
||||
|
||||
inline constexpr unsigned int TRIANGLE_INDICES[]{
|
||||
0, 1, 2, // first triangle
|
||||
};
|
||||
inline const char* CONTAINER_TEXTURE = {
|
||||
"assets/container.png"
|
||||
};
|
||||
|
||||
inline constexpr size_t TRIANGLE_INDICES_SIZE = {sizeof(TRIANGLE_INDICES)};
|
||||
|
||||
inline constexpr float TRIANGLES_VERTICES[]{
|
||||
|
||||
inline const char* VERTEX_SHADER_COLOR_FILENAME{
|
||||
"./Shaders/vertexShaderColor.vs"};
|
||||
|
||||
inline const char* VERTEX_SHADER_UPSIDE_DOWN_FILENAME{
|
||||
"./Shaders/vertexShaderUpsideDown.vs"};
|
||||
|
||||
inline const char* VERTEX_SHADER_OFFSET_FILENAME{
|
||||
"./Shaders/vertexShaderOffset.vs"};
|
||||
// we write vertex shader
|
||||
// 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
|
||||
// DO NOT REMOVE UNTIL CAN DRAW SQUARE USING CLASS
|
||||
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"};
|
||||
inline const char* VERTEX_SHADER_SOURCE_FILENAME{
|
||||
"./Shaders/vertexShaderSource.vs"};
|
||||
|
||||
inline const char* VERTEX_SHADER_VERTICE_COLOR_FILENAME{
|
||||
"./Shaders/vertexShaderVerticeColor.vs"};
|
||||
|
||||
inline const char* VERTEX_SHADER_TASK_THREE_FILENAME{
|
||||
"./Shaders/vertexShaderTaskThree.vs"};
|
||||
|
||||
inline const char* VERTEX_SHADER_TEXTURE_FILENAME{
|
||||
"./Shaders/vertexShaderTexture.vs"};
|
||||
|
||||
inline const char* FRAGMENT_SHADER_TASK_THREE_FILENAME{
|
||||
"./Shaders/fragmentShaderTaskThree.fs"};
|
||||
|
||||
inline const char* FRAGMENT_SHADER_COLOR_FROM_VERTEX_FILENAME{
|
||||
"./Shaders/fragmentShaderColorFromVertex.fs"};
|
||||
|
||||
inline const char* FRAGMENT_SHADER_UNIFORMS_FILENAME{
|
||||
"./Shaders/fragmentShaderUniforms.fs"};
|
||||
|
||||
// write fragment shader
|
||||
// we set the color of each pixel to be orange
|
||||
// DO NOT REMOVE UNTIL CAN DRAW SQUARE USING CLASS
|
||||
inline const char* FRAGMENT_SHADER_SOURCE{
|
||||
"#version 330 core\n"
|
||||
"out vec4 FragColor;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
"FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
|
||||
"}\0"};
|
||||
|
||||
inline const char* FRAGMENT_SHADER_SOURCE_FILENAME{
|
||||
"./Shaders/fragmentShaderSource.fs"};
|
||||
inline const char* FRAGMENT_SHADER_SOURCE_YELLOW_FILENAME{
|
||||
"./Shaders/fragmentShaderSourceYellow.fs"};
|
||||
|
||||
inline const char* FRAGMENT_SHADER_TEXTURE_FILENAME{
|
||||
"./Shaders/fragmentShaderTexture.fs"};
|
||||
|
||||
inline const char* FRAGMENT_SHADER_TEXTURE_TASK_ONE_FILENAME{
|
||||
"./Shaders/fragmentShaderTextureTaskOne.fs"};
|
||||
|
||||
// we specify three vertices
|
||||
// each of them with position in 3d space
|
||||
// x y z
|
||||
inline constexpr float TRIANGLE_VERTICES[]{
|
||||
-0.5f, -0.5f, 0.0f,
|
||||
0.5f, -0.5f, 0.0f,
|
||||
0.0f, 0.5f, 0.0f
|
||||
};
|
||||
|
||||
inline constexpr size_t TRIANGLE_VERTICES_SIZE = {sizeof(TRIANGLE_VERTICES)};
|
||||
|
||||
inline constexpr unsigned int TRIANGLE_INDICES[]{
|
||||
0, 1, 2, // first triangle
|
||||
};
|
||||
|
||||
inline constexpr size_t TRIANGLE_INDICES_SIZE = {sizeof(TRIANGLE_INDICES)};
|
||||
|
||||
inline constexpr float TRIANGLES_VERTICES[]{
|
||||
// first triangle
|
||||
-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
|
||||
};
|
||||
|
||||
inline constexpr size_t TRIANGLES_VERTICES_SIZE = {sizeof(TRIANGLES_VERTICES)};
|
||||
|
||||
inline constexpr unsigned int TRIANGLES_INDICES[]{
|
||||
0, 1, 2, // first triangle
|
||||
0, 1, 2 // second triangle
|
||||
};
|
||||
|
||||
inline constexpr size_t TRIANGLES_INDICES_SIZE = {sizeof(TRIANGLES_INDICES)};
|
||||
|
||||
inline constexpr float TRIANGLE_ONE[]{
|
||||
// first triangle
|
||||
-0.9f, -0.5f, 0.0f, // left
|
||||
-0.0f, -0.5f, 0.0f, // right
|
||||
-0.45f, 0.5f, 0.0f, // top
|
||||
};
|
||||
|
||||
inline constexpr size_t TRIANGLE_ONE_SIZE = {sizeof(TRIANGLE_ONE)};
|
||||
|
||||
inline constexpr float TRIANGLE_TWO[]{
|
||||
// second triangle
|
||||
0.0f, -0.5f, 0.0f, // left
|
||||
0.9f, -0.5f, 0.0f, // right
|
||||
0.45f, 0.5f, 0.0f // top
|
||||
};
|
||||
|
||||
inline constexpr size_t TRIANGLE_TWO_SIZE = {sizeof(TRIANGLE_TWO)};
|
||||
|
||||
inline constexpr float TRIANGLE_COLORS[]{
|
||||
// positions // colors
|
||||
0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom right
|
||||
-0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom left
|
||||
0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f // top
|
||||
};
|
||||
|
||||
inline constexpr size_t TRIANGLE_COLORS_SIZE = {sizeof(TRIANGLE_COLORS)};
|
||||
|
||||
// compare with square done with only vertices:
|
||||
/*
|
||||
float vertices[] = {
|
||||
// first triangle
|
||||
-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
|
||||
};
|
||||
|
||||
inline constexpr size_t TRIANGLES_VERTICES_SIZE = {sizeof(TRIANGLES_VERTICES)};
|
||||
|
||||
inline constexpr unsigned int TRIANGLES_INDICES[]{
|
||||
0, 1, 2, // first triangle
|
||||
0, 1, 2 // second triangle
|
||||
};
|
||||
|
||||
inline constexpr size_t TRIANGLES_INDICES_SIZE = {sizeof(TRIANGLES_INDICES)};
|
||||
|
||||
inline constexpr float TRIANGLE_ONE[]{
|
||||
// first triangle
|
||||
-0.9f, -0.5f, 0.0f, // left
|
||||
-0.0f, -0.5f, 0.0f, // right
|
||||
-0.45f, 0.5f, 0.0f, // top
|
||||
};
|
||||
|
||||
inline constexpr size_t TRIANGLE_ONE_SIZE = {sizeof(TRIANGLE_ONE)};
|
||||
|
||||
inline constexpr float TRIANGLE_TWO[]{
|
||||
0.5f, 0.5f, 0.0f, // top right
|
||||
0.5f, -0.5f, 0.0f, // bottom right
|
||||
-0.5f, 0.5f, 0.0f, // top left
|
||||
// second triangle
|
||||
0.0f, -0.5f, 0.0f, // left
|
||||
0.9f, -0.5f, 0.0f, // right
|
||||
0.45f, 0.5f, 0.0f // top
|
||||
};
|
||||
0.5f, -0.5f, 0.0f, // bottom right
|
||||
-0.5f, -0.5f, 0.0f, // bottom left
|
||||
-0.5f, 0.5f, 0.0f // top left
|
||||
};
|
||||
bottom right and top left is specified twice !
|
||||
*/
|
||||
inline constexpr float SQUARE_VERTICES[]{
|
||||
0.5f, 0.5f, 0.0f, // top right
|
||||
0.5f, -0.5f, 0.0f, // bottom right
|
||||
-0.25f, -0.5f, 0.0f, // bottom left
|
||||
-0.25f, 0.5f, 0.0f // top left
|
||||
};
|
||||
|
||||
inline constexpr size_t TRIANGLE_TWO_SIZE = {sizeof(TRIANGLE_TWO)};
|
||||
inline constexpr unsigned int SQUARE_INDICES[]{
|
||||
0, 1, 3, // first triangle
|
||||
1, 2, 3, // second triangle
|
||||
};
|
||||
|
||||
inline constexpr float TRIANGLE_COLORS[]{
|
||||
// positions // colors
|
||||
0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom right
|
||||
-0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom left
|
||||
0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f // top
|
||||
};
|
||||
inline constexpr size_t SQUARE_INDICES_SIZE = {sizeof(SQUARE_INDICES)};
|
||||
|
||||
inline constexpr size_t TRIANGLE_COLORS_SIZE = {sizeof(TRIANGLE_COLORS)};
|
||||
inline constexpr size_t SQUARE_VERTICES_SIZE = {sizeof(SQUARE_VERTICES)};
|
||||
|
||||
// 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
|
||||
-0.5f, 0.5f, 0.0f, // top left
|
||||
// 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
|
||||
};
|
||||
bottom right and top left is specified twice !
|
||||
*/
|
||||
inline constexpr float SQUARE_VERTICES[]{
|
||||
0.5f, 0.5f, 0.0f, // top right
|
||||
0.5f, -0.5f, 0.0f, // bottom right
|
||||
-0.25f, -0.5f, 0.0f, // bottom left
|
||||
-0.25f, 0.5f, 0.0f // top left
|
||||
};
|
||||
inline constexpr int MAX_DRAW_CALL = {13};
|
||||
|
||||
inline constexpr unsigned int SQUARE_INDICES[]{
|
||||
0, 1, 3, // first triangle
|
||||
1, 2, 3, // second triangle
|
||||
};
|
||||
// https://learnopengl.com/img/getting-started/tex_coords.png
|
||||
inline constexpr float TEXTURE_VERTICES[]{
|
||||
// positions // colors // texture coords
|
||||
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // top right
|
||||
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom right
|
||||
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom left
|
||||
-0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f // top left
|
||||
};
|
||||
|
||||
inline constexpr size_t SQUARE_INDICES_SIZE = {sizeof(SQUARE_INDICES)};
|
||||
inline constexpr size_t TEXTURE_VERTICES_SIZE = {sizeof(TEXTURE_VERTICES)};
|
||||
|
||||
inline constexpr size_t SQUARE_VERTICES_SIZE = {sizeof(SQUARE_VERTICES)};
|
||||
inline constexpr float TEXTURE_VERTICES_2F[]{
|
||||
// positions // colors // texture coords
|
||||
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 2.0f, 2.0f, // top right
|
||||
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 2.0f, 0.0f, // bottom right
|
||||
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom left
|
||||
-0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 2.0f // top left
|
||||
};
|
||||
|
||||
inline constexpr int MAX_DRAW_CALL = {11};
|
||||
inline constexpr size_t TEXTURE_VERTICES_2F_SIZE = {
|
||||
sizeof(TEXTURE_VERTICES_2F)};
|
||||
|
||||
// https://learnopengl.com/img/getting-started/tex_coords.png
|
||||
inline constexpr float TEXTURE_VERTICES[]{
|
||||
// positions // colors // texture coords
|
||||
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // top right
|
||||
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom right
|
||||
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom left
|
||||
-0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f // top left
|
||||
};
|
||||
inline constexpr unsigned int TEXTURE_INDICES[]{
|
||||
0, 1, 3, // first triangle
|
||||
1, 2, 3 // second triangle
|
||||
};
|
||||
|
||||
inline constexpr size_t TEXTURE_VERTICES_SIZE = {sizeof(TEXTURE_VERTICES)};
|
||||
|
||||
inline constexpr unsigned int TEXTURE_INDICES[]{
|
||||
0, 1, 3, // first triangle
|
||||
1, 2, 3 // second triangle
|
||||
};
|
||||
|
||||
inline constexpr size_t TEXTURE_INDICES_SIZE = {sizeof(TEXTURE_INDICES)};
|
||||
} // namespace constants
|
||||
inline constexpr size_t TEXTURE_INDICES_SIZE = {sizeof(TEXTURE_INDICES)};
|
||||
}; // namespace constants
|
||||
|
||||
#endif // ENGINE_ENGINE_CONSTANTS_HPP_
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "./constants.hpp"
|
||||
#include "./misc.hpp"
|
||||
@ -23,9 +24,9 @@ drawFigureReturn drawFigure(const int whatToDraw) {
|
||||
switch (whatToDraw) {
|
||||
case 0:
|
||||
return draw(constants::VERTEX_SHADER_SOURCE_FILENAME,
|
||||
constants::FRAGMENT_SHADER_SOURCE_FILENAME,
|
||||
constants::TRIANGLE_VERTICES,
|
||||
constants::TRIANGLE_VERTICES_SIZE);
|
||||
constants::FRAGMENT_SHADER_SOURCE_FILENAME,
|
||||
constants::TRIANGLE_VERTICES,
|
||||
constants::TRIANGLE_VERTICES_SIZE);
|
||||
case 1:
|
||||
return draw(
|
||||
constants::VERTEX_SHADER_SOURCE_FILENAME,
|
||||
@ -73,7 +74,6 @@ drawFigureReturn drawFigure(const int whatToDraw) {
|
||||
constants::TRIANGLE_VERTICES, constants::TRIANGLE_VERTICES_SIZE);
|
||||
case 6:
|
||||
// set color from opengl code to uniform value in fragment shader
|
||||
// toDo: fix
|
||||
return draw(constants::VERTEX_SHADER_COLOR_FILENAME,
|
||||
constants::FRAGMENT_SHADER_UNIFORMS_FILENAME,
|
||||
constants::TRIANGLE_VERTICES,
|
||||
@ -102,21 +102,51 @@ drawFigureReturn drawFigure(const int whatToDraw) {
|
||||
constants::TRIANGLE_VERTICES_SIZE,
|
||||
constants::TRIANGLE_INDICES,
|
||||
constants::TRIANGLE_INDICES_SIZE,
|
||||
false, false, offsets);
|
||||
false, false, {}, offsets);
|
||||
}
|
||||
case 10:
|
||||
return draw(constants::VERTEX_SHADER_TASK_THREE_FILENAME,
|
||||
constants::FRAGMENT_SHADER_TASK_THREE_FILENAME,
|
||||
constants::TRIANGLE_VERTICES,
|
||||
constants::TRIANGLE_VERTICES_SIZE);
|
||||
case constants::MAX_DRAW_CALL: {
|
||||
case 11: {
|
||||
std::vector<textureArgument> textureInfoArray = {
|
||||
texture_constants::CONTAINER_ARGUMENT,
|
||||
texture_constants::AWESOME_FACE_ARGUMENT
|
||||
};
|
||||
return draw(
|
||||
constants::VERTEX_SHADER_TEXTURE_FILENAME,
|
||||
constants::FRAGMENT_SHADER_TEXTURE_FILENAME,
|
||||
constants::TEXTURE_VERTICES, constants::TEXTURE_VERTICES_SIZE,
|
||||
constants::TEXTURE_INDICES,
|
||||
constants::TEXTURE_INDICES_SIZE,
|
||||
true, true);
|
||||
true, true, textureInfoArray);
|
||||
}
|
||||
case 12: {
|
||||
std::vector<textureArgument> textureInfoArray = {
|
||||
texture_constants::CONTAINER_ARGUMENT,
|
||||
texture_constants::AWESOME_FACE_ARGUMENT
|
||||
};
|
||||
return draw(
|
||||
constants::VERTEX_SHADER_TEXTURE_FILENAME,
|
||||
constants::FRAGMENT_SHADER_TEXTURE_TASK_ONE_FILENAME,
|
||||
constants::TEXTURE_VERTICES, constants::TEXTURE_VERTICES_SIZE,
|
||||
constants::TEXTURE_INDICES,
|
||||
constants::TEXTURE_INDICES_SIZE,
|
||||
true, true, textureInfoArray);
|
||||
}
|
||||
case constants::MAX_DRAW_CALL: {
|
||||
std::vector<textureArgument> textureInfoArray = {
|
||||
texture_constants::CONTAINER_ARGUMENT,
|
||||
texture_constants::AWESOME_FACE_ARGUMENT
|
||||
};
|
||||
return draw(
|
||||
constants::VERTEX_SHADER_TEXTURE_FILENAME,
|
||||
constants::FRAGMENT_SHADER_TEXTURE_FILENAME,
|
||||
constants::TEXTURE_VERTICES_2F, constants::TEXTURE_VERTICES_2F_SIZE,
|
||||
constants::TEXTURE_INDICES,
|
||||
constants::TEXTURE_INDICES_SIZE,
|
||||
true, true, textureInfoArray);
|
||||
}
|
||||
default:
|
||||
throw "No function for this draw call";
|
||||
@ -149,13 +179,12 @@ drawFigureReturn draw(const char* vertexPath, const char* fragmentPath,
|
||||
const size_t indicesSize,
|
||||
const bool colorIncluded,
|
||||
const bool textureIncluded,
|
||||
std::vector<textureArgument> textureInfo,
|
||||
const offsetsStruct offsets) {
|
||||
// https://stackoverflow.com/questions/33883609/opengl-linker-error-linking-with-uncompiled-shader
|
||||
Shader ourShader(vertexPath,
|
||||
fragmentPath);
|
||||
ourShader.use(); // don't forget to activate/use
|
||||
// the shader before setting uniforms!
|
||||
// set it via the texture class
|
||||
ourShader.use();
|
||||
setOffsets(ourShader, offsets);
|
||||
|
||||
unsigned int VBO =
|
||||
@ -170,17 +199,27 @@ drawFigureReturn draw(const char* vertexPath, const char* fragmentPath,
|
||||
doDrawArrays(ourShader.ID, VAO, GL_TRIANGLES, 0,
|
||||
verticesSize);
|
||||
|
||||
unsigned int texture1 = loadAndCreateTexture("assets/container.png", true);
|
||||
unsigned int texture2 = loadAndCreateTexture("assets/awesomeface.png", false);
|
||||
drawTextureArray(textureInfo, ourShader);
|
||||
// unsigned int texture1 = loadAndCreateTexture(
|
||||
// textureInfo.texturePath,
|
||||
// textureInfo.flipImage,
|
||||
// textureInfo.wrappingMethod);
|
||||
// unsigned int texture2 = loadAndCreateTexture(
|
||||
// "assets/awesomeface.png", false, GL_REPEAT);
|
||||
|
||||
ourShader.setInt("texture1", 0);
|
||||
ourShader.setInt("texture2", 1);
|
||||
// ourShader.setInt("texture1", 0);
|
||||
// ourShader.setInt("texture2", 1);
|
||||
|
||||
activateAndBindTextures(texture1, GL_TEXTURE0);
|
||||
activateAndBindTextures(texture2, GL_TEXTURE1);
|
||||
// don't forget to activate/use
|
||||
// the shader before setting uniforms!
|
||||
// set it via the texture class
|
||||
// (texture1, GL_TEXTURE0);
|
||||
// activateAndBindTextures(texture2, GL_TEXTURE1);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, indicesSize, GL_UNSIGNED_INT, 0);
|
||||
|
||||
glDeleteVertexArrays(1, &VAO);
|
||||
glDeleteBuffers(1, &VBO);
|
||||
glDeleteBuffers(1, &EBO);
|
||||
drawFigureReturn newReturn;
|
||||
newReturn.success = 0;
|
||||
newReturn.VAO = VAO;
|
||||
|
||||
@ -5,8 +5,10 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "./constants.hpp"
|
||||
#include "./textures.hpp"
|
||||
|
||||
struct offsetsStruct {
|
||||
offsetsStruct() : xOffset(0), yOffset(0), zOffset(0) {}
|
||||
@ -21,6 +23,8 @@ struct drawFigureReturn {
|
||||
unsigned int EBO;
|
||||
};
|
||||
|
||||
|
||||
|
||||
drawFigureReturn drawFigure(const int whatToDraw);
|
||||
|
||||
void updateUniformColor(const unsigned int shaderProgram,
|
||||
@ -40,6 +44,8 @@ drawFigureReturn draw(
|
||||
const size_t indicesSize = constants::TRIANGLE_INDICES_SIZE,
|
||||
const bool colorIncluded = false,
|
||||
const bool textureIncluded = false,
|
||||
const offsetsStruct offsets = offsetsStruct());
|
||||
std::vector<textureArgument> textureInfo = {},
|
||||
const offsetsStruct offsets = offsetsStruct()
|
||||
);
|
||||
|
||||
#endif // ENGINE_ENGINE_DRAW_HPP_
|
||||
|
||||
Binary file not shown.
@ -197,10 +197,6 @@ int renderLoopInside(GLFWwindow *window, int whatToDraw) {
|
||||
// (which we register via callback methods)
|
||||
glfwPollEvents();
|
||||
|
||||
glDeleteVertexArrays(1, &successAndVao.VAO);
|
||||
glDeleteBuffers(1, &successAndVao.VBO);
|
||||
glDeleteBuffers(1, &successAndVao.EBO);
|
||||
|
||||
return whatToDraw;
|
||||
}
|
||||
|
||||
|
||||
@ -1,12 +1,15 @@
|
||||
// "Copyright [2023] <Krzysztof Rudnicki>"
|
||||
#ifndef TEXTURES_CPP
|
||||
#define TEXTURES_CPP
|
||||
#include "textures.hpp"
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "stb_image.h"
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <array>
|
||||
#include "./textures.hpp"
|
||||
#include "./stb_image.h"
|
||||
#include "./shader.hpp"
|
||||
|
||||
void setTextureSCoordinate(const GLenum textureTarget,
|
||||
const GLint sCoordinateOption,
|
||||
@ -105,9 +108,6 @@ unsigned int loadAndBindTextureFile(unsigned int texture,
|
||||
unsigned char* data = stbi_load(texturePath, &textureWidth, &textureHeight,
|
||||
&colorChannels, STBI_rgb_alpha);
|
||||
if (data) {
|
||||
std::cout << "textureWidth " << textureWidth << " textureHeight "
|
||||
<< textureHeight << " colorChannels " << colorChannels
|
||||
<< std::endl;
|
||||
// generate texture
|
||||
/*
|
||||
first argument is texture target, setting it to GL_TEXTURE_2D will only
|
||||
@ -132,15 +132,40 @@ unsigned int loadAndBindTextureFile(unsigned int texture,
|
||||
}
|
||||
}
|
||||
|
||||
void drawTextureArray(const std::vector<textureArgument> texturesInfo, Shader ourShader) {
|
||||
std::vector<unsigned int> texture;
|
||||
uint64_t arrayLength = texturesInfo.size();
|
||||
for (uint64_t i = 0; i < arrayLength; i++) {
|
||||
const unsigned int tempTexture = loadAndCreateTexture(
|
||||
texturesInfo.at(i).texturePath,
|
||||
texturesInfo.at(i).flipImage,
|
||||
texturesInfo.at(i).wrappingMethod);
|
||||
texture.push_back(tempTexture);
|
||||
|
||||
// don't forget to activate/use
|
||||
// the shader before setting uniforms!
|
||||
// set it via the texture class
|
||||
}
|
||||
for (uint64_t i = 1; i <= texture.size(); i++) {
|
||||
const std::string textureString = "texture" + std::to_string(i);
|
||||
ourShader.setInt(textureString, i - 1);
|
||||
}
|
||||
|
||||
for (uint64_t i = 0; i < texture.size(); i++) {
|
||||
activateAndBindTextures(texture.at(i), GL_TEXTURE0 + i);
|
||||
}
|
||||
}
|
||||
|
||||
// const char* texturePath, int textureWidth, int textureHeight, int
|
||||
// colorChannels, const GLenum textureTarget, const GLint sCoordinateOption,
|
||||
// const GLint tCoordinateOption, const GLint rCoordinateOption, const float*
|
||||
// borderColor
|
||||
unsigned int loadAndCreateTexture(const char* texturePath, bool flipImage) {
|
||||
unsigned int loadAndCreateTexture(
|
||||
const char* texturePath, bool flipImage, GLint wrappingMethod) {
|
||||
// load and create a texture
|
||||
// -------------------------
|
||||
unsigned int texture = generateAndBindTexture(GL_TEXTURE_2D, 1);
|
||||
setTextureParametersINT(GL_TEXTURE_2D, GL_REPEAT, GL_REPEAT);
|
||||
setTextureParametersINT(GL_TEXTURE_2D, wrappingMethod, wrappingMethod);
|
||||
|
||||
// set texture filtering parameters
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
@ -1,10 +1,32 @@
|
||||
// "Copyright [2023] <Krzysztof Rudnicki>"
|
||||
#ifndef TEXTURES_HPP
|
||||
#define TEXTURES_HPP
|
||||
#ifndef ENGINE_ENGINE_TEXTURES_HPP_
|
||||
#define ENGINE_ENGINE_TEXTURES_HPP_
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "./constants.hpp"
|
||||
#include "./shader.hpp"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
struct textureArgument {
|
||||
textureArgument() :
|
||||
texturePath(constants::NO_TEXTURE_TEXTURE),
|
||||
flipImage(false), wrappingMethod(GL_REPEAT) {}
|
||||
textureArgument(const char* tP, const bool fI, const GLint wM) :
|
||||
texturePath(tP),
|
||||
flipImage(fI),
|
||||
wrappingMethod(wM) {}
|
||||
const char* texturePath;
|
||||
bool flipImage;
|
||||
GLint wrappingMethod;
|
||||
};
|
||||
|
||||
namespace texture_constants {
|
||||
inline const textureArgument CONTAINER_ARGUMENT =
|
||||
textureArgument(constants::CONTAINER_TEXTURE, true, GL_CLAMP_TO_EDGE);
|
||||
inline const textureArgument AWESOME_FACE_ARGUMENT =
|
||||
textureArgument(constants::AWESOME_FACE_TEXTURE, false, GL_REPEAT);
|
||||
}
|
||||
|
||||
void setTextureParametersINT(const GLenum textureTarget = GL_TEXTURE_2D,
|
||||
const GLint sCoordinateOption = GL_REPEAT,
|
||||
@ -31,9 +53,10 @@ unsigned int generateAndBindTexture(const GLenum textureTarget);
|
||||
// colorChannels, const GLenum textureTarget, const GLint sCoordinateOption,
|
||||
// const GLint tCoordinateOption, const GLint rCoordinateOption, const float*
|
||||
// borderColor
|
||||
unsigned int loadAndCreateTexture(const char* texturePath, bool flipImage);
|
||||
unsigned int loadAndCreateTexture(const char* texturePath, bool flipImage, GLint wrappingMethod);
|
||||
void activateAndBindTextures(unsigned int texture, GLenum textureNumber);
|
||||
unsigned int loadAndBindTextureFile(unsigned int texture,
|
||||
const char* texturePath, bool flipImage);
|
||||
void drawTextureArray(const std::vector<textureArgument> texturesInfo, Shader ourShader);
|
||||
|
||||
#endif // TEXTURES_HPP
|
||||
#endif // ENGINE_ENGINE_TEXTURES_HPP_
|
||||
Loading…
Reference in New Issue
Block a user