mirror of
https://github.com/kuhyx/engineer-thesis-WUT.git
synced 2026-07-04 15:43:19 +02:00
chore: intermediate commit
This commit is contained in:
parent
7b6d1452e4
commit
305f04c2a7
@ -1,11 +1,8 @@
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec3 ourColor;
|
||||
in vec2 TexCoord;
|
||||
|
||||
uniform sampler2D ourTexture;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = texture(ourTexture, TexCoord);
|
||||
|
||||
@ -19,7 +19,7 @@ int drawFigure(const int whatToDraw)
|
||||
case 0:
|
||||
return drawTriangleClass(constants::TRIANGLE_VERTICES, constants::TRIANGLE_VERTICES_SIZE, constants::VERTEX_SHADER_SOURCE_FILENAME, constants::FRAGMENT_SHADER_SOURCE_FILENAME);
|
||||
case 1:
|
||||
return drawSquare(constants::VERTEX_SHADER_SOURCE, constants::FRAGMENT_SHADER_SOURCE);
|
||||
return drawSquare(constants::SQUARE_VERTICES, constants::SQUARE_VERTICES_SIZE, constants::SQUARE_INDICES, constants::SQUARE_INDICES_SIZE, constants::VERTEX_SHADER_SOURCE, constants::FRAGMENT_SHADER_SOURCE);
|
||||
case 2:
|
||||
// Try to draw 2 triangles next to each other using glDrawArrays by adding more vertices to your data.
|
||||
return drawTriangleClass(constants::TRIANGLES_VERTICES, constants::TRIANGLES_VERTICES_SIZE, constants::VERTEX_SHADER_SOURCE_FILENAME, constants::FRAGMENT_SHADER_SOURCE_FILENAME);
|
||||
@ -51,7 +51,7 @@ int drawFigure(const int whatToDraw)
|
||||
case 10:
|
||||
return drawTriangleClass(constants::TRIANGLE_VERTICES, constants::TRIANGLE_VERTICES_SIZE, constants::VERTEX_SHADER_TASK_THREE_FILENAME, constants::FRAGMENT_SHADER_TASK_THREE_FILENAME);
|
||||
case constants::MAX_DRAW_CALL:
|
||||
return drawTriangleClass(constants::POSITION_COLOR_TEXTURE, constants::POSITION_COLOR_TEXTURE_SIZE, constants::VERTEX_SHADER_TEXTURE_FILENAME, constants::FRAGMENT_SHADER_TEXTURE_FILENAME, true, true);
|
||||
return drawDebilMode();
|
||||
default:
|
||||
throw "No function for this draw call";
|
||||
}
|
||||
@ -112,23 +112,23 @@ int drawTriangle(const float triangleVertices[], const size_t triangleVerticesSi
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drawSquare(const char* vertexShaderSource, const char* fragmentShaderSource)
|
||||
int 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);
|
||||
if (shaderProgram == 0)
|
||||
return -1;
|
||||
const unsigned int VAO = generateBindVAO();
|
||||
copyVerticesMemory(constants::SQUARE_VERTICES, constants::SQUARE_VERTICES_SIZE, GL_ARRAY_BUFFER);
|
||||
copyVerticesMemory(constants::SQUARE_INDICES, constants::SQUARE_INDICES_SIZE, GL_ELEMENT_ARRAY_BUFFER);
|
||||
copyVerticesMemory(squareVertices, squareVerticesSize, GL_ARRAY_BUFFER);
|
||||
copyVerticesMemory(squareIndices, squareIndicesSize, GL_ELEMENT_ARRAY_BUFFER);
|
||||
|
||||
// set vertex attribute pointers
|
||||
configureVertexAttribute(false, false);
|
||||
configureVertexAttribute(colorIncluded, textureIncluded);
|
||||
|
||||
doDrawElements(shaderProgram, VAO, GL_TRIANGLES, GL_UNSIGNED_INT, std::size(constants::SQUARE_INDICES));
|
||||
doDrawElements(shaderProgram, VAO, GL_TRIANGLES, GL_UNSIGNED_INT, squareIndicesSize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drawSquareClass(const char* vertexPath, const char* fragmentPath)
|
||||
int drawSquareClass(const char* vertexPath, const char* fragmentPath, const bool colorIncluded, const bool textureIncluded, const offsetsStruct offsets)
|
||||
{
|
||||
Shader ourShader(vertexPath, fragmentPath);
|
||||
ourShader.use();
|
||||
@ -142,6 +142,12 @@ int drawSquareClass(const char* vertexPath, const char* fragmentPath)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drawDebilMode() {
|
||||
// https://stackoverflow.com/questions/33883609/opengl-linker-error-linking-with-uncompiled-shader
|
||||
Shader ourShader(constants::VERTEX_SHADER_TEXTURE_FILENAME, constants::FRAGMENT_SHADER_TEXTURE_FILENAME);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void doDrawElements(const unsigned int shaderProgram, const unsigned int vertexArrayObject, const GLenum drawArrayMode, const GLenum drawType, const int numberOfElementsToDraw)
|
||||
{
|
||||
glUseProgram(shaderProgram);
|
||||
@ -175,7 +181,7 @@ void doDrawArrays(const unsigned int shaderProgram, const unsigned int vertexArr
|
||||
// use shader program to render an object
|
||||
glUseProgram(shaderProgram);
|
||||
updateUniformColor(shaderProgram, "ourColor");
|
||||
const unsigned int texture = generateTexture("./assets/Preview.png", 500, 500, 3);
|
||||
const unsigned int texture = generateTexture("./assets/Preview.png", 430, 288, 3);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glBindVertexArray(vertexArrayObject);
|
||||
// From left:
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <string>
|
||||
#include "constants.hpp"
|
||||
|
||||
struct offsetsStruct {
|
||||
offsetsStruct(): xOffset(0), yOffset(0), zOffset(0) { }
|
||||
@ -10,8 +11,8 @@ struct offsetsStruct {
|
||||
};
|
||||
|
||||
int drawFigure(const int whatToDraw);
|
||||
int drawSquare(const char* vertexShaderSource, const char* fragmentShaderSource);
|
||||
int drawSquareClass(const char* vertexPath, const char* fragmentPath);
|
||||
int 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());
|
||||
int 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);
|
||||
int 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());
|
||||
int drawTriangle(const float triangleVertices[], const size_t triangleVerticesSize, const char* vertexShaderSource, const char* fragmentShaderSource, const bool colorIncluded = false, const bool textureIncluded = false);
|
||||
@ -19,5 +20,6 @@ int drawTexture();
|
||||
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 );
|
||||
unsigned int drawSquareShaderProgram(const char* vertexShaderSource, const char* fragmentShaderSource);
|
||||
int drawDebilMode();
|
||||
|
||||
#endif
|
||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user