mirror of
https://github.com/kuhyx/engineer-thesis-WUT.git
synced 2026-11-24 22:06:28 +01:00
chore: add copyrigtht info
This commit is contained in:
parent
7dbd77117e
commit
553c5f7397
3
.vscode/c_cpp_properties.json
vendored
3
.vscode/c_cpp_properties.json
vendored
@ -4,7 +4,8 @@
|
|||||||
"name": "linux-gcc-x64",
|
"name": "linux-gcc-x64",
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**",
|
"${workspaceFolder}/**",
|
||||||
"${workspaceFolder}/dependencies/include"
|
"${workspaceFolder}/dependencies/include",
|
||||||
|
"${workspaceFolder}/dependencies/include/glad/**"
|
||||||
],
|
],
|
||||||
"compilerPath": "/usr/bin/gcc",
|
"compilerPath": "/usr/bin/gcc",
|
||||||
"cStandard": "${default}",
|
"cStandard": "${default}",
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
|
// "Copyright [2023] <Krzysztof Rudnicki>"
|
||||||
#ifndef BEFORE_RENDER_CPP
|
#ifndef BEFORE_RENDER_CPP
|
||||||
#define BEFORE_RENDER_CPP
|
#define BEFORE_RENDER_CPP
|
||||||
|
#include "Engine/engine/beforeRender.hpp"
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "beforeRender.hpp"
|
#include "./constants.hpp"
|
||||||
#include "constants.hpp"
|
#include "./misc.hpp"
|
||||||
#include "misc.hpp"
|
|
||||||
|
|
||||||
void configureGLFW(const int GLFWMajorVersion, const int GLFWMinorVersion)
|
void configureGLFW(const int GLFWMajorVersion, const int GLFWMinorVersion) {
|
||||||
{
|
|
||||||
// first argument tells us what option to configure
|
// first argument tells us what option to configure
|
||||||
// second is to what we set the value of this option
|
// second is to what we set the value of this option
|
||||||
// see: https://www.glfw.org/docs/latest/window.html#window_hints
|
// see: https://www.glfw.org/docs/latest/window.html#window_hints
|
||||||
@ -17,7 +17,8 @@ void configureGLFW(const int GLFWMajorVersion, const int GLFWMinorVersion)
|
|||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, GLFWMinorVersion);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, GLFWMinorVersion);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
// we set GLFW to 3.3 CORE
|
// we set GLFW to 3.3 CORE
|
||||||
// core profile gives us access to smaller subset of OGL without backwards compatible features
|
// core profile gives us access to smaller subset of
|
||||||
|
// OGL without backwards compatible features
|
||||||
|
|
||||||
// if we are on Mac OS X we need this for our code to work
|
// if we are on Mac OS X we need this for our code to work
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
@ -25,27 +26,28 @@ void configureGLFW(const int GLFWMajorVersion, const int GLFWMinorVersion)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void instantiateGLFWwindow()
|
void instantiateGLFWwindow() {
|
||||||
{
|
|
||||||
// Initialize GLFW
|
// Initialize GLFW
|
||||||
glfwInit();
|
glfwInit();
|
||||||
configureGLFW(constants::GLFW_MAJOR_VERSION, constants::GLFW_MINOR_VERSION);
|
configureGLFW(constants::GLFW_MAJOR_VERSION, constants::GLFW_MINOR_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWwindow *createWindowObject()
|
GLFWwindow *createWindowObject() {
|
||||||
{
|
|
||||||
// First two arguments are width and height
|
// First two arguments are width and height
|
||||||
// Third is the name of the window
|
// Third is the name of the window
|
||||||
// We ignore last two
|
// We ignore last two
|
||||||
GLFWwindow *window = glfwCreateWindow(constants::MAIN_WINDOW_WIDTH, constants::MAIN_WINDOW_HEIGHT, constants::MAIN_WINDOW_NAME, nullptr, nullptr);
|
GLFWwindow *window = glfwCreateWindow(
|
||||||
|
constants::MAIN_WINDOW_WIDTH,
|
||||||
|
constants::MAIN_WINDOW_HEIGHT,
|
||||||
|
constants::MAIN_WINDOW_NAME,
|
||||||
|
nullptr,
|
||||||
|
nullptr);
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
int initializeGLAD()
|
int initializeGLAD() {
|
||||||
{
|
|
||||||
// we load address of OGL OS-specific function pointers
|
// we load address of OGL OS-specific function pointers
|
||||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||||
{
|
|
||||||
print("Failed to initialize GLAD");
|
print("Failed to initialize GLAD");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -53,33 +55,36 @@ int initializeGLAD()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// resizes viewport when user resizes window
|
// resizes viewport when user resizes window
|
||||||
void framebuffer_size_callback(GLFWwindow *window, const int width, const int height)
|
void framebuffer_size_callback(GLFWwindow *window,
|
||||||
{
|
const int width,
|
||||||
|
const int height) {
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void viewPort(GLFWwindow *window)
|
void viewPort(GLFWwindow *window) {
|
||||||
{
|
|
||||||
// We tell OGL size of rendering window
|
// We tell OGL size of rendering window
|
||||||
// First two define left corner of window
|
// First two define left corner of window
|
||||||
// 3th and 4th width and height of rendering window
|
// 3th and 4th width and height of rendering window
|
||||||
// we could set them to be smaller than window dimension, ogl rendering will be then displayed in smaller window
|
// we could set them to be smaller than window dimension,
|
||||||
glViewport(0, 0, constants::MAIN_WINDOW_WIDTH, constants::MAIN_WINDOW_HEIGHT);
|
// ogl rendering will be then displayed in smaller window
|
||||||
|
glViewport(0,
|
||||||
|
0,
|
||||||
|
constants::MAIN_WINDOW_WIDTH,
|
||||||
|
constants::MAIN_WINDOW_HEIGHT);
|
||||||
// processed coordinates are between -1 and 1 so here we map:
|
// processed coordinates are between -1 and 1 so here we map:
|
||||||
// (-1 to 1) to (0, constants::MAIN_WINDOW_WIDTH) and (0, constants::MAIN_WINDOW_HEIGHT)
|
// (-1 to 1) to (0, constants::MAIN_WINDOW_WIDTH)
|
||||||
|
// and (0, constants::MAIN_WINDOW_HEIGHT)
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
// we call framebuffer_size_callback on every window resize
|
// we call framebuffer_size_callback on every window resize
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWwindow *prepareForRender()
|
GLFWwindow *prepareForRender() {
|
||||||
{
|
|
||||||
instantiateGLFWwindow();
|
instantiateGLFWwindow();
|
||||||
|
|
||||||
GLFWwindow *window = createWindowObject();
|
GLFWwindow *window = createWindowObject();
|
||||||
// function returns GLFWWindow object
|
// function returns GLFWWindow object
|
||||||
|
|
||||||
if (window == nullptr)
|
if (window == nullptr) {
|
||||||
{
|
|
||||||
print("Failed to create GLFW window");
|
print("Failed to create GLFW window");
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return window;
|
return window;
|
||||||
@ -93,4 +98,4 @@ GLFWwindow *prepareForRender()
|
|||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
// "Copyright [2023] <Krzysztof Rudnicki>"
|
||||||
#ifndef BEFORE_RENDER_HPP
|
#ifndef BEFORE_RENDER_HPP
|
||||||
#define BEFORE_RENDER_HPP
|
#define BEFORE_RENDER_HPP
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
// "Copyright [2023] <Krzysztof Rudnicki>"
|
||||||
#ifndef CONSTANTS_HPP
|
#ifndef CONSTANTS_HPP
|
||||||
#define CONSTANTS_HPP
|
#define CONSTANTS_HPP
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|||||||
2
Engine/engine/cppCheckIgnore.txt
Normal file
2
Engine/engine/cppCheckIgnore.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*:stb_image.h:*
|
||||||
|
*:stb_images_implementation.cpp:*
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
// "Copyright [2023] <Krzysztof Rudnicki>"
|
||||||
#ifndef DRAW_CPP
|
#ifndef DRAW_CPP
|
||||||
#define DRAW_CPP
|
#define DRAW_CPP
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
@ -103,34 +104,10 @@ drawFigureReturn drawTriangleClass(const float triangleVertices[], const size_t
|
|||||||
return newReturn;
|
return newReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
drawFigureReturn drawTriangle(const float triangleVertices[], const size_t triangleVerticesSize, const char* vertexShaderSource, const char* fragmentShaderSource, const bool colorIncluded, const bool textureIncluded)
|
|
||||||
{
|
|
||||||
|
|
||||||
const unsigned int shaderProgram = getShaderProgram(vertexShaderSource, fragmentShaderSource);
|
|
||||||
drawFigureReturn newReturn;
|
|
||||||
if (shaderProgram == 0) {
|
|
||||||
newReturn.success = -1;
|
|
||||||
return newReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
const unsigned int vertexBufferObject = copyVerticesMemory(triangleVertices, triangleVerticesSize, GL_ARRAY_BUFFER);
|
|
||||||
const unsigned int vertexArrayObject = generateBindVAO();
|
|
||||||
copyVerticesArray(vertexBufferObject, triangleVertices, triangleVerticesSize, GL_ARRAY_BUFFER);
|
|
||||||
|
|
||||||
// set vertex attribute pointers
|
|
||||||
configureVertexAttribute(colorIncluded, textureIncluded);
|
|
||||||
doDrawArrays(shaderProgram, vertexArrayObject, GL_TRIANGLES, 0, triangleVerticesSize);
|
|
||||||
newReturn.success = 0;
|
|
||||||
newReturn.VAO = vertexArrayObject;
|
|
||||||
newReturn.VBO = vertexBufferObject;
|
|
||||||
newReturn.EBO = 0;
|
|
||||||
return newReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
drawFigureReturn drawSquare(const float squareVertices[], const size_t squareVerticesSize, const unsigned int squareIndices[], const size_t squareIndicesSize, const char* vertexShaderSource, const char* fragmentShaderSource, const bool colorIncluded, const bool textureIncluded, const offsetsStruct offsets)
|
drawFigureReturn drawSquare(const float squareVertices[], const size_t squareVerticesSize, const unsigned int squareIndices[], const size_t squareIndicesSize, const char* vertexShaderSource, const char* fragmentShaderSource, const bool colorIncluded, const bool textureIncluded, const offsetsStruct offsets)
|
||||||
{
|
{
|
||||||
const unsigned int shaderProgram = getShaderProgram(vertexShaderSource, fragmentShaderSource);
|
const unsigned int shaderProgram = getShaderProgram(vertexShaderSource, fragmentShaderSource);
|
||||||
drawFigureReturn newReturn;
|
drawFigureReturn newReturn = drawFigureReturn();
|
||||||
if (shaderProgram == 0) {
|
if (shaderProgram == 0) {
|
||||||
newReturn.success = -1;
|
newReturn.success = -1;
|
||||||
return newReturn;
|
return newReturn;
|
||||||
@ -145,27 +122,6 @@ drawFigureReturn drawSquare(const float squareVertices[], const size_t squareVer
|
|||||||
doDrawElements(shaderProgram, VAO, GL_TRIANGLES, GL_UNSIGNED_INT, squareIndicesSize);
|
doDrawElements(shaderProgram, VAO, GL_TRIANGLES, GL_UNSIGNED_INT, squareIndicesSize);
|
||||||
newReturn.success = 0;
|
newReturn.success = 0;
|
||||||
newReturn.VAO = VAO;
|
newReturn.VAO = VAO;
|
||||||
newReturn.VBO = 0;
|
|
||||||
newReturn.EBO = 0;
|
|
||||||
return newReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
drawFigureReturn drawSquareClass(const char* vertexPath, const char* fragmentPath, const bool colorIncluded, const bool textureIncluded, const offsetsStruct offsets)
|
|
||||||
{
|
|
||||||
Shader ourShader(vertexPath, fragmentPath);
|
|
||||||
ourShader.use();
|
|
||||||
const unsigned int vertexBufferObject = copyVerticesMemory(constants::SQUARE_VERTICES, constants::SQUARE_VERTICES_SIZE, GL_ARRAY_BUFFER);
|
|
||||||
const unsigned int vertexArrayObject = generateBindVAO();
|
|
||||||
copyVerticesArray(vertexBufferObject, constants::SQUARE_VERTICES, constants::SQUARE_VERTICES_SIZE, GL_ARRAY_BUFFER);
|
|
||||||
|
|
||||||
// set vertex attribute pointers
|
|
||||||
configureVertexAttribute(false, false);
|
|
||||||
doDrawArrays(ourShader.ID, vertexArrayObject, GL_TRIANGLES, 0, constants::SQUARE_VERTICES_SIZE);
|
|
||||||
drawFigureReturn newReturn;
|
|
||||||
newReturn.success = 0;
|
|
||||||
newReturn.VAO = vertexArrayObject;
|
|
||||||
newReturn.VBO = vertexBufferObject;
|
|
||||||
newReturn.EBO = 0;
|
|
||||||
return newReturn;
|
return newReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,8 +135,8 @@ drawFigureReturn drawDebilMode(const char* vertexPath, const char* fragmentPath,
|
|||||||
|
|
||||||
configureVertexAttribute(true, true);
|
configureVertexAttribute(true, true);
|
||||||
|
|
||||||
unsigned int texture1 = loadAndCreateTexture("assets/container.png", GL_RGB, true);
|
unsigned int texture1 = loadAndCreateTexture("assets/container.png", true);
|
||||||
unsigned int texture2 = loadAndCreateTexture("assets/awesomeface.png", GL_RGBA, false);
|
unsigned int texture2 = loadAndCreateTexture("assets/awesomeface.png", false);
|
||||||
|
|
||||||
ourShader.use(); // don't forget to activate/use the shader before setting uniforms!
|
ourShader.use(); // don't forget to activate/use the shader before setting uniforms!
|
||||||
// either set it manually like so:
|
// either set it manually like so:
|
||||||
@ -243,11 +199,4 @@ void doDrawArrays(const unsigned int shaderProgram, const unsigned int vertexArr
|
|||||||
glDrawArrays(drawArrayMode, firstIndex, numberOfIndicesToBeRendered);
|
glDrawArrays(drawArrayMode, firstIndex, numberOfIndicesToBeRendered);
|
||||||
}
|
}
|
||||||
|
|
||||||
int drawTexture() {
|
|
||||||
// we added new vertex attribute and need to inform opengl that we done so
|
|
||||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));
|
|
||||||
glEnableVertexAttribArray(2);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
// "Copyright [2023] <Krzysztof Rudnicki>"
|
||||||
#ifndef DRAW_HPP
|
#ifndef DRAW_HPP
|
||||||
#define DRAW_HPP
|
#define DRAW_HPP
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
@ -11,6 +12,7 @@ struct offsetsStruct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct drawFigureReturn {
|
struct drawFigureReturn {
|
||||||
|
drawFigureReturn(): success(-1), VAO(0), VBO(0), EBO(0){ }
|
||||||
int success;
|
int success;
|
||||||
unsigned int VAO;
|
unsigned int VAO;
|
||||||
unsigned int VBO;
|
unsigned int VBO;
|
||||||
@ -19,14 +21,10 @@ struct drawFigureReturn {
|
|||||||
|
|
||||||
drawFigureReturn drawFigure(const int whatToDraw);
|
drawFigureReturn drawFigure(const int whatToDraw);
|
||||||
drawFigureReturn drawSquare(const float squareVertices[] = constants::SQUARE_VERTICES, const size_t squareVerticesSize = constants::SQUARE_VERTICES_SIZE, const unsigned int squareIndices[] = constants::SQUARE_INDICES, const size_t squareIndicesSize = constants::SQUARE_INDICES_SIZE, const char* vertexShaderSource = constants::VERTEX_SHADER_SOURCE, const char* fragmentShaderSource = constants::FRAGMENT_SHADER_SOURCE, const bool colorIncluded = false, const bool textureIncluded = false, const offsetsStruct offsets = offsetsStruct());
|
drawFigureReturn drawSquare(const float squareVertices[] = constants::SQUARE_VERTICES, const size_t squareVerticesSize = constants::SQUARE_VERTICES_SIZE, const unsigned int squareIndices[] = constants::SQUARE_INDICES, const size_t squareIndicesSize = constants::SQUARE_INDICES_SIZE, const char* vertexShaderSource = constants::VERTEX_SHADER_SOURCE, const char* fragmentShaderSource = constants::FRAGMENT_SHADER_SOURCE, const bool colorIncluded = false, const bool textureIncluded = false, const offsetsStruct offsets = offsetsStruct());
|
||||||
drawFigureReturn drawSquareClass(const char* vertexPath, const char* fragmentPath, const bool colorIncluded = false, const bool textureIncluded = false, const offsetsStruct offsets = offsetsStruct());
|
|
||||||
void doDrawElements(const unsigned int shaderProgram, const unsigned int vertexArrayObject, const GLenum drawArrayMode, const GLenum drawType, const int numberOfElementsToDraw);
|
void doDrawElements(const unsigned int shaderProgram, const unsigned int vertexArrayObject, const GLenum drawArrayMode, const GLenum drawType, const int numberOfElementsToDraw);
|
||||||
drawFigureReturn drawTriangleClass(const float triangleVertices[], const size_t triangleVerticesSize, const char* vertexPath, const char* fragmentPath, const bool colorIncluded = false, const bool textureIncluded = false, const offsetsStruct offsets = offsetsStruct());
|
drawFigureReturn drawTriangleClass(const float triangleVertices[], const size_t triangleVerticesSize, const char* vertexPath, const char* fragmentPath, const bool colorIncluded = false, const bool textureIncluded = false, const offsetsStruct offsets = offsetsStruct());
|
||||||
drawFigureReturn drawTriangle(const float triangleVertices[], const size_t triangleVerticesSize, const char* vertexShaderSource, const char* fragmentShaderSource, const bool colorIncluded = false, const bool textureIncluded = false);
|
|
||||||
int drawTexture();
|
|
||||||
void updateUniformColor(const unsigned int shaderProgram, const GLchar* uniformName);
|
void updateUniformColor(const unsigned int shaderProgram, const GLchar* uniformName);
|
||||||
void doDrawArrays(const unsigned int shaderProgram, const unsigned int vertexArrayObject, const GLenum drawArrayMode, const int firstIndex, const unsigned int numberOfIndicesToBeRendered );
|
void doDrawArrays(const unsigned int shaderProgram, const unsigned int vertexArrayObject, const GLenum drawArrayMode, const int firstIndex, const unsigned int numberOfIndicesToBeRendered );
|
||||||
unsigned int drawSquareShaderProgram(const char* vertexShaderSource, const char* fragmentShaderSource);
|
|
||||||
drawFigureReturn drawDebilMode(const char* vertexPath, const char* fragmentPath, const float vertices[], const size_t verticesSize, const unsigned int indices[], const size_t indicesSize);
|
drawFigureReturn drawDebilMode(const char* vertexPath, const char* fragmentPath, const float vertices[], const size_t verticesSize, const unsigned int indices[], const size_t indicesSize);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Binary file not shown.
@ -1,3 +1,4 @@
|
|||||||
|
// "Copyright [2023] <Krzysztof Rudnicki>"
|
||||||
#ifndef MAIN_CPP
|
#ifndef MAIN_CPP
|
||||||
#define MAIN_CPP
|
#define MAIN_CPP
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
// "Copyright [2023] <Krzysztof Rudnicki>"
|
||||||
#ifndef MISC_CPP
|
#ifndef MISC_CPP
|
||||||
#define MISC_CPP
|
#define MISC_CPP
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
// "Copyright [2023] <Krzysztof Rudnicki>"
|
||||||
#ifndef MISC_HPP
|
#ifndef MISC_HPP
|
||||||
#define MISC_HPP
|
#define MISC_HPP
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
// "Copyright [2023] <Krzysztof Rudnicki>"
|
||||||
#ifndef RENDER_LOOP_CPP
|
#ifndef RENDER_LOOP_CPP
|
||||||
#define RENDER_LOOP_CPP
|
#define RENDER_LOOP_CPP
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
// "Copyright [2023] <Krzysztof Rudnicki>"
|
||||||
#ifndef RENDER_LOOP_HPP
|
#ifndef RENDER_LOOP_HPP
|
||||||
#define RENDER_LOOP_HPP
|
#define RENDER_LOOP_HPP
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
// "Copyright [2023] <Krzysztof Rudnicki>"
|
||||||
#ifndef SHADER_CPP
|
#ifndef SHADER_CPP
|
||||||
#define SHADER_CPP
|
#define SHADER_CPP
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
// "Copyright [2023] <Krzysztof Rudnicki>"
|
||||||
#ifndef SHADER_HPP
|
#ifndef SHADER_HPP
|
||||||
#define SHADER_HPP
|
#define SHADER_HPP
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
// "Copyright [2023] <Krzysztof Rudnicki>"
|
||||||
#ifndef SHADERS_CPP
|
#ifndef SHADERS_CPP
|
||||||
#define SHADERS_CPP
|
#define SHADERS_CPP
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
// "Copyright [2023] <Krzysztof Rudnicki>"
|
||||||
#ifndef SHADERS_HPP
|
#ifndef SHADERS_HPP
|
||||||
#define SHADERS_HPP
|
#define SHADERS_HPP
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
// "Copyright [2023] <Krzysztof Rudnicki>"
|
||||||
#ifndef TEXTURES_CPP
|
#ifndef TEXTURES_CPP
|
||||||
#define TEXTURES_CPP
|
#define TEXTURES_CPP
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
@ -72,14 +73,6 @@ void setTextureFilteringAndMipMap(const GLenum textureTarget, const GLenum filte
|
|||||||
glTexParameteri(textureTarget, filterType, textureFilteringMethod);
|
glTexParameteri(textureTarget, filterType, textureFilteringMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *loadTexture(const char* texturePath, int textureWidth, int textureHeight, int colorChannels)
|
|
||||||
{
|
|
||||||
// first argument is the location of an image
|
|
||||||
// second and third is its width and height
|
|
||||||
// fourth is number of color channels
|
|
||||||
unsigned char *data = stbi_load(texturePath, &textureWidth, &textureHeight, &colorChannels, 0);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int generateAndBindTexture(const GLenum textureTarget, const GLsizei numberOfTextures ) {
|
unsigned int generateAndBindTexture(const GLenum textureTarget, const GLsizei numberOfTextures ) {
|
||||||
unsigned int texture;
|
unsigned int texture;
|
||||||
@ -91,10 +84,10 @@ unsigned int generateAndBindTexture(const GLenum textureTarget, const GLsizei nu
|
|||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int loadAndBindTextureFile(unsigned int texture, const char* texturePath, GLenum rgbFormat, bool flipImage) {
|
unsigned int loadAndBindTextureFile(unsigned int texture, const char* texturePath, bool flipImage) {
|
||||||
int textureWidth, textureHeight, colorChannels;
|
int textureWidth, textureHeight, colorChannels;
|
||||||
stbi_set_flip_vertically_on_load(flipImage);
|
stbi_set_flip_vertically_on_load(flipImage);
|
||||||
unsigned char *data = stbi_load(texturePath, &textureWidth, &textureHeight, &colorChannels, 0);
|
unsigned char *data = stbi_load(texturePath, &textureWidth, &textureHeight, &colorChannels, STBI_rgb_alpha);
|
||||||
if(data) {
|
if(data) {
|
||||||
std::cout << "textureWidth " << textureWidth << " textureHeight " << textureHeight << " colorChannels " << colorChannels << std::endl;
|
std::cout << "textureWidth " << textureWidth << " textureHeight " << textureHeight << " colorChannels " << colorChannels << std::endl;
|
||||||
// generate texture
|
// generate texture
|
||||||
@ -107,7 +100,8 @@ unsigned int loadAndBindTextureFile(unsigned int texture, const char* texturePa
|
|||||||
7th and 8th are the format and datatype of source image, we store the image data as chars (bytes) so we pass that
|
7th and 8th are the format and datatype of source image, we store the image data as chars (bytes) so we pass that
|
||||||
9th last argument is actual data of the texture
|
9th last argument is actual data of the texture
|
||||||
*/
|
*/
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, rgbFormat, textureWidth, textureHeight, 0, rgbFormat, GL_UNSIGNED_BYTE, data);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
// after generating texture, lets free the memory from image
|
// after generating texture, lets free the memory from image
|
||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
@ -121,7 +115,7 @@ unsigned int loadAndBindTextureFile(unsigned int texture, const char* texturePa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// const char* texturePath, int textureWidth, int textureHeight, int colorChannels, const GLenum textureTarget, const GLint sCoordinateOption, const GLint tCoordinateOption, const GLint rCoordinateOption, const float* borderColor
|
// 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, GLenum RGBFormat, bool flipImage) {
|
unsigned int loadAndCreateTexture(const char* texturePath, bool flipImage) {
|
||||||
// load and create a texture
|
// load and create a texture
|
||||||
// -------------------------
|
// -------------------------
|
||||||
unsigned int texture = generateAndBindTexture(GL_TEXTURE_2D, 1);
|
unsigned int texture = generateAndBindTexture(GL_TEXTURE_2D, 1);
|
||||||
@ -131,7 +125,7 @@ unsigned int loadAndCreateTexture(const char* texturePath, GLenum RGBFormat, boo
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
// load image, create texture and generate mipmaps
|
// load image, create texture and generate mipmaps
|
||||||
texture = loadAndBindTextureFile(texture, texturePath, RGBFormat, flipImage);
|
texture = loadAndBindTextureFile(texture, texturePath, flipImage);
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
// "Copyright [2023] <Krzysztof Rudnicki>"
|
||||||
#ifndef TEXTURES_HPP
|
#ifndef TEXTURES_HPP
|
||||||
#define TEXTURES_HPP
|
#define TEXTURES_HPP
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -10,11 +11,10 @@ void setTextureTCoordinate(const GLenum textureTarget = GL_TEXTURE_2D, const GLi
|
|||||||
void setTextureRCoordinate(const GLenum textureTarget = GL_TEXTURE_3D, const GLint rCoordinateOption = GL_REPEAT, const float* borderColor = NULL);
|
void setTextureRCoordinate(const GLenum textureTarget = GL_TEXTURE_3D, const GLint rCoordinateOption = GL_REPEAT, const float* borderColor = NULL);
|
||||||
void setTextureFilteringAndMipMap(const GLenum textureTarget = GL_TEXTURE_2D, const GLenum filterType = GL_TEXTURE_MAG_FILTER, const GLint textureFilteringMethod = GL_NEAREST, const GLint mipMapFilteringMethod = GL_NEAREST_MIPMAP_NEAREST);
|
void setTextureFilteringAndMipMap(const GLenum textureTarget = GL_TEXTURE_2D, const GLenum filterType = GL_TEXTURE_MAG_FILTER, const GLint textureFilteringMethod = GL_NEAREST, const GLint mipMapFilteringMethod = GL_NEAREST_MIPMAP_NEAREST);
|
||||||
unsigned int generateAndBindTexture(const GLenum textureTarget);
|
unsigned int generateAndBindTexture(const GLenum textureTarget);
|
||||||
unsigned char* loadTexture(const char* texturePath, int textureWidth, int textureHeight, int colorChannels);
|
|
||||||
|
|
||||||
// const char* texturePath, int textureWidth, int textureHeight, int colorChannels, const GLenum textureTarget, const GLint sCoordinateOption, const GLint tCoordinateOption, const GLint rCoordinateOption, const float* borderColor
|
// 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, GLenum RGBFormat, bool flipImage);
|
unsigned int loadAndCreateTexture(const char* texturePath, bool flipImage);
|
||||||
void activateAndBindTextures(unsigned int texture, GLenum textureNumber);
|
void activateAndBindTextures(unsigned int texture, GLenum textureNumber);
|
||||||
unsigned int loadAndBindTextureFile(unsigned int texture, const char* texturePath, GLenum rgbFormat, bool flipImage);
|
unsigned int loadAndBindTextureFile(unsigned int texture, const char* texturePath, bool flipImage);
|
||||||
|
|
||||||
#endif // TEXTURES_HPP
|
#endif // TEXTURES_HPP
|
||||||
Loading…
Reference in New Issue
Block a user