mirror of
https://github.com/kuhyx/engineer-thesis-WUT.git
synced 2026-07-04 13:23:09 +02:00
feat: changing tecture opacity based on input
This commit is contained in:
parent
6a92a83f5e
commit
5b7b2efefa
@ -24,8 +24,8 @@
|
||||
#include "./stb_image.h"
|
||||
#include "./textures.hpp"
|
||||
|
||||
drawFigureReturn drawFigure(const int whatToDraw) {
|
||||
switch (whatToDraw) {
|
||||
drawFigureReturn drawFigure(const drawInput drawData) {
|
||||
switch (drawData.whatToDraw) {
|
||||
case 0:
|
||||
return draw(constants::VERTEX_SHADER_SOURCE_FILENAME,
|
||||
constants::FRAGMENT_SHADER_SOURCE_FILENAME,
|
||||
@ -188,7 +188,7 @@ drawFigureReturn drawFigure(const int whatToDraw) {
|
||||
constants::TEXTURE_INDICES,
|
||||
constants::TEXTURE_INDICES_SIZE,
|
||||
true, true, textureInfoArray,
|
||||
offsets, uniformInfo);
|
||||
offsets, uniformInfo, drawData);
|
||||
}
|
||||
default:
|
||||
throw "No function for this draw call";
|
||||
@ -223,7 +223,8 @@ drawFigureReturn draw(const char* vertexPath, const char* fragmentPath,
|
||||
const bool textureIncluded,
|
||||
std::vector<textureArgument> textureInfo,
|
||||
const offsetsStruct offsets,
|
||||
const std::vector<std::string> uniformName) {
|
||||
const std::vector<std::string> uniformName,
|
||||
const drawInput drawData) {
|
||||
// https://stackoverflow.com/questions/33883609/opengl-linker-error-linking-with-uncompiled-shader
|
||||
Shader ourShader(vertexPath,
|
||||
fragmentPath);
|
||||
@ -245,8 +246,9 @@ drawFigureReturn draw(const char* vertexPath, const char* fragmentPath,
|
||||
}
|
||||
if(uniformName.at(0) == "mixProportions") {
|
||||
srand (time(NULL));
|
||||
const float randomNumber = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
|
||||
ourShader.setFloat(uniformName.at(0), randomNumber);
|
||||
// const float randomNumber = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
|
||||
std::cout << drawData.whatToDraw << std::endl;
|
||||
ourShader.setFloat(uniformName.at(0), drawData.textureOpacity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
|
||||
#include "./constants.hpp"
|
||||
#include "./textures.hpp"
|
||||
#include "./renderLoop.hpp"
|
||||
|
||||
struct offsetsStruct {
|
||||
offsetsStruct() : xOffset(0), yOffset(0), zOffset(0) {}
|
||||
@ -25,7 +26,7 @@ struct drawFigureReturn {
|
||||
|
||||
|
||||
|
||||
drawFigureReturn drawFigure(const int whatToDraw);
|
||||
drawFigureReturn drawFigure(const drawInput drawData);
|
||||
|
||||
void updateUniformColor(const Shader shaderProgram,
|
||||
const std::string uniformName);
|
||||
@ -41,7 +42,8 @@ drawFigureReturn draw(
|
||||
const bool textureIncluded = false,
|
||||
std::vector<textureArgument> textureInfo = {},
|
||||
const offsetsStruct offsets = offsetsStruct(),
|
||||
const std::vector<std::string> uniformName = {}
|
||||
const std::vector<std::string> uniformName = {},
|
||||
const drawInput drawData = drawInput()
|
||||
);
|
||||
|
||||
#endif // ENGINE_ENGINE_DRAW_HPP_
|
||||
|
||||
Binary file not shown.
@ -13,14 +13,21 @@
|
||||
#include "./misc.hpp"
|
||||
#include "./shaders.hpp"
|
||||
|
||||
int processInput(GLFWwindow *window, const int whatToDraw) {
|
||||
static bool lockedLeft = false;
|
||||
drawInput processInput(GLFWwindow *window, drawInput drawData) {
|
||||
static bool lockedLeft = false; // czemu są static ?
|
||||
static bool lockedRight = false;
|
||||
static bool lockedUp = false;
|
||||
static bool lockedDown = false;
|
||||
const bool PRESSED_CHANGE_LEFT =
|
||||
(glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS);
|
||||
const bool PRESSED_CHANGE_RIGHT =
|
||||
(glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS);
|
||||
|
||||
const bool PRESSED_CHANGE_UP =
|
||||
(glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS);
|
||||
const bool PRESSED_CHANGE_DOWN =
|
||||
(glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS);
|
||||
|
||||
// glfwGetKey takes window and key as
|
||||
// an input and checks is currently being pressed
|
||||
// if the user pressed escape we close window
|
||||
@ -28,17 +35,35 @@ int processInput(GLFWwindow *window, const int whatToDraw) {
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
if (glfwGetKey(window, GLFW_KEY_C) == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
|
||||
if (!PRESSED_CHANGE_LEFT) lockedLeft = 0;
|
||||
if (!PRESSED_CHANGE_RIGHT) lockedRight = 0;
|
||||
if (!PRESSED_CHANGE_UP) lockedUp = 0;
|
||||
if (!PRESSED_CHANGE_DOWN) lockedDown = 0;
|
||||
|
||||
|
||||
if (PRESSED_CHANGE_RIGHT && lockedRight == 0) {
|
||||
lockedRight = 1;
|
||||
return (whatToDraw == constants::MAX_DRAW_CALL ? 0 : whatToDraw + 1);
|
||||
drawData.whatToDraw = (drawData.whatToDraw == constants::MAX_DRAW_CALL ? 0 : drawData.whatToDraw + 1);
|
||||
return drawData;
|
||||
}
|
||||
if (PRESSED_CHANGE_LEFT && lockedLeft == 0) {
|
||||
lockedLeft = 1;
|
||||
return (whatToDraw == 0 ? constants::MAX_DRAW_CALL : whatToDraw - 1);
|
||||
drawData.whatToDraw = (drawData.whatToDraw == 0 ? constants::MAX_DRAW_CALL : drawData.whatToDraw - 1);
|
||||
return drawData;
|
||||
}
|
||||
return whatToDraw;
|
||||
if (PRESSED_CHANGE_UP && lockedUp == 0) {
|
||||
lockedUp = 1;
|
||||
drawData.textureOpacity = drawData.textureOpacity + 0.1;
|
||||
std::cout << drawData.textureOpacity << std::endl;
|
||||
return drawData;
|
||||
}
|
||||
if (PRESSED_CHANGE_DOWN && lockedDown == 0) {
|
||||
lockedDown = 1;
|
||||
drawData.textureOpacity = drawData.textureOpacity - 0.1;
|
||||
return drawData;
|
||||
}
|
||||
return drawData;
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/25680092
|
||||
@ -165,9 +190,9 @@ void copyVerticesArray(const unsigned int vertexBufferObject,
|
||||
glBufferData(boundBufferTarget, sizeOfVertices, vertices, GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
int renderLoopInside(GLFWwindow *window, int whatToDraw) {
|
||||
drawInput renderLoopInside(GLFWwindow *window, drawInput drawData) {
|
||||
// input
|
||||
whatToDraw = processInput(window, whatToDraw);
|
||||
drawData = processInput(window, drawData);
|
||||
// We specify the color to clear the screen with
|
||||
// RGB and alpha value
|
||||
glClearColor(constants::LEARN_OPEN_GL_COLOR.red,
|
||||
@ -178,7 +203,7 @@ int renderLoopInside(GLFWwindow *window, int whatToDraw) {
|
||||
// GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT and GL_STENCIL_BUFFER_BIT
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
drawFigureReturn successAndVao = drawFigure(whatToDraw);
|
||||
drawFigureReturn successAndVao = drawFigure(drawData);
|
||||
if (successAndVao.success == -1) {
|
||||
print("error with drawing!");
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
@ -197,14 +222,14 @@ int renderLoopInside(GLFWwindow *window, int whatToDraw) {
|
||||
// (which we register via callback methods)
|
||||
glfwPollEvents();
|
||||
|
||||
return whatToDraw;
|
||||
return drawData;
|
||||
}
|
||||
|
||||
void renderLoop(GLFWwindow *window) {
|
||||
int whatToDraw = 0;
|
||||
drawInput drawData = drawInput();
|
||||
// glfwWindowShouldClose checks if GLFW was instructed to close
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
whatToDraw = renderLoopInside(window, whatToDraw);
|
||||
drawData = renderLoopInside(window, drawData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,8 +6,14 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
struct drawInput {
|
||||
drawInput() : whatToDraw(0), textureOpacity(0) {}
|
||||
int whatToDraw;
|
||||
float textureOpacity;
|
||||
};
|
||||
|
||||
void renderLoop(GLFWwindow *window);
|
||||
int renderLoopInside(GLFWwindow *window, int whatToDraw);
|
||||
drawInput renderLoopInside(GLFWwindow *window, drawInput drawData);
|
||||
|
||||
void copyVerticesArray(unsigned int vertexBufferObject, const float vertices[],
|
||||
const size_t sizeOfVertices,
|
||||
@ -18,7 +24,7 @@ unsigned int generateBindVAO();
|
||||
void configureVertexAttribute(const bool colorIncluded,
|
||||
const bool textureIncluded);
|
||||
|
||||
int processInput(GLFWwindow *window, int whatToDraw);
|
||||
drawInput processInput(GLFWwindow *window, drawInput drawData);
|
||||
|
||||
unsigned int copyVerticesMemory(const float vertices[],
|
||||
const size_t sizeOfVertices,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user