Premodularizzzation
This commit is contained in:
commit
4563397a44
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
build/
|
||||
.cache/
|
21
.gitmodules
vendored
Normal file
21
.gitmodules
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
[submodule "SOIL2"]
|
||||
path = SOIL2
|
||||
url = https://github.com/SpartanJ/SOIL2
|
||||
[submodule "include/SOIL2"]
|
||||
path = include/SOIL2
|
||||
url = https://github.com/SpartanJ/SOIL2
|
||||
[submodule "include/assimp"]
|
||||
path = include/assimp
|
||||
url = https://github.com/assimp/assimp
|
||||
[submodule "include/glew"]
|
||||
path = include/glew
|
||||
url = https://github.com/nigels-com/glew
|
||||
[submodule "include/glfw"]
|
||||
path = include/glfw
|
||||
url = https://github.com/glfw/glfw
|
||||
[submodule "include/glm"]
|
||||
path = include/glm
|
||||
url = https://github.com/g-truc/glm
|
||||
[submodule "include/imgui"]
|
||||
path = include/imgui
|
||||
url = https://github.com/ocornut/imgui
|
55
CMakeLists.txt
Normal file
55
CMakeLists.txt
Normal file
@ -0,0 +1,55 @@
|
||||
cmake_minimum_required(VERSION 3.11)
|
||||
project(fred)
|
||||
|
||||
# if($<CONFIG:Debug>)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # For my Clangd LSP
|
||||
# endif()
|
||||
|
||||
set(GLFW_BUILD_WAYLAND OFF) # This should be detected and not forced
|
||||
|
||||
find_package(OpenGL REQUIRED)
|
||||
|
||||
if(CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
|
||||
message(FATAL_ERROR "You fucking smell fr")
|
||||
endif()
|
||||
if(CMAKE_SOURCE_DIR MATCHES " ")
|
||||
message("Spaces in the source dir can cause errors, thou art been warned")
|
||||
endif()
|
||||
if(CMAKE_BIANRY_DIR MATCHES " ")
|
||||
message("Spaces in the build dir can cause errors, thou art been warned")
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${PROJECT_SOURCE_DIR}/include/glew/src/glew.c
|
||||
${PROJECT_SOURCE_DIR}/include/glewinfo.c
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/include/glew/auto
|
||||
COMMAND ${CMAKE_MAKE_PROGRAM})
|
||||
|
||||
add_subdirectory(include/glm)
|
||||
add_subdirectory(include/glew/build/cmake)
|
||||
add_subdirectory(include/glfw)
|
||||
add_subdirectory(include/SOIL2)
|
||||
add_subdirectory(include/assimp)
|
||||
|
||||
include_directories(include/imgui)
|
||||
add_library(
|
||||
imgui
|
||||
include/imgui/imgui.cpp
|
||||
include/imgui/imgui_demo.cpp
|
||||
include/imgui/imgui_draw.cpp
|
||||
include/imgui/imgui_tables.cpp
|
||||
include/imgui/imgui_widgets.cpp
|
||||
include/imgui/backends/imgui_impl_glfw.cpp # Zingaloid backend import
|
||||
include/imgui/backends/imgui_impl_opengl3.cpp)
|
||||
target_link_libraries(imgui glfw)
|
||||
|
||||
add_executable(fred engine.cpp shader.c)
|
||||
target_link_libraries(
|
||||
fred
|
||||
-lm
|
||||
glm
|
||||
glew
|
||||
glfw
|
||||
soil2
|
||||
assimp
|
||||
imgui)
|
353
engine.cpp
Normal file
353
engine.cpp
Normal file
@ -0,0 +1,353 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/trigonometric.hpp>
|
||||
|
||||
#include <backends/imgui_impl_glfw.h>
|
||||
#include <backends/imgui_impl_opengl3.h>
|
||||
#include <imgui.h>
|
||||
|
||||
#include <SOIL2.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/Logger.hpp>
|
||||
#include <assimp/postprocess.h>
|
||||
#include <assimp/scene.h>
|
||||
|
||||
extern "C" {
|
||||
#include "shader.h"
|
||||
}
|
||||
|
||||
#define WIDTH 1024
|
||||
#define HEIGHT 768
|
||||
|
||||
static void glfwErrorCallback(int e, const char *description) {
|
||||
fprintf(stderr, "GLFW Error %d: %s", e, description);
|
||||
}
|
||||
|
||||
bool loadModel(const char *path, std::vector<unsigned short> &indices,
|
||||
std::vector<glm::vec3> &vertices, std::vector<glm::vec2> &uvs,
|
||||
std::vector<glm::vec3> &normals) {
|
||||
Assimp::Importer importer;
|
||||
|
||||
const aiScene *scene = importer.ReadFile(
|
||||
path, aiProcess_Triangulate | aiProcess_JoinIdenticalVertices |
|
||||
aiProcess_SortByPType);
|
||||
if (!scene) {
|
||||
fprintf(stderr, "%s\n", importer.GetErrorString());
|
||||
return false;
|
||||
}
|
||||
const aiMesh *mesh = scene->mMeshes[0];
|
||||
|
||||
vertices.reserve(mesh->mNumVertices);
|
||||
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
|
||||
aiVector3D pos = mesh->mVertices[i];
|
||||
vertices.push_back(glm::vec3(pos.x, pos.y, pos.z));
|
||||
}
|
||||
|
||||
uvs.reserve(mesh->mNumVertices);
|
||||
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
|
||||
aiVector3D UVW = mesh->mTextureCoords[0][i]; // Multiple UVs? Prepsterous!
|
||||
uvs.push_back(glm::vec2(UVW.x, UVW.y));
|
||||
}
|
||||
|
||||
normals.reserve(mesh->mNumVertices);
|
||||
for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
|
||||
indices.push_back(mesh->mFaces[i].mIndices[0]);
|
||||
indices.push_back(mesh->mFaces[i].mIndices[1]);
|
||||
indices.push_back(mesh->mFaces[i].mIndices[2]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int initWindow() {
|
||||
glfwSetErrorCallback(glfwErrorCallback);
|
||||
|
||||
glewExperimental = true;
|
||||
if (!glfwInit()) {
|
||||
fprintf(stderr, "GLFW went shitty time\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
glfwWindowHint(GLFW_SAMPLES, 4); // 4x Antialiasing
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Loser MacOS is broken
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // New GL
|
||||
|
||||
GLFWwindow *window;
|
||||
window = glfwCreateWindow(WIDTH, HEIGHT, "Fred", NULL, NULL);
|
||||
if (window == NULL) {
|
||||
fprintf(stderr, "Failed to open window.\n");
|
||||
glfwTerminate();
|
||||
return 1;
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(1);
|
||||
int code;
|
||||
if ((code = glewInit()) != GLEW_OK) {
|
||||
fprintf(stderr, "Failed to init GLEW: %s\n", glewGetErrorString(code));
|
||||
return 1;
|
||||
}
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
(void)io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
|
||||
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||
ImGui_ImplOpenGL3_Init("#version 330");
|
||||
|
||||
std::vector<unsigned short> indices;
|
||||
std::vector<glm::vec3> indexed_vertices;
|
||||
std::vector<glm::vec2> indexed_uvs;
|
||||
std::vector<glm::vec3> indexed_normals;
|
||||
if (!loadModel("../models/model.obj", indices, indexed_vertices, indexed_uvs,
|
||||
indexed_normals)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLuint vertexArrayID;
|
||||
glGenVertexArrays(1, &vertexArrayID);
|
||||
glBindVertexArray(vertexArrayID);
|
||||
|
||||
GLuint vertexBuffer;
|
||||
glGenBuffers(1, &vertexBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, indexed_vertices.size() * sizeof(glm::vec3),
|
||||
&indexed_vertices[0], GL_STATIC_DRAW);
|
||||
|
||||
GLuint uvBuffer;
|
||||
glGenBuffers(1, &uvBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, uvBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, indexed_uvs.size() * sizeof(glm::vec2),
|
||||
&indexed_uvs[0], GL_STATIC_DRAW);
|
||||
|
||||
GLuint normalBuffer;
|
||||
glGenBuffers(1, &normalBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, normalBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, indexed_normals.size() * sizeof(glm::vec3),
|
||||
&indexed_normals[0], GL_STATIC_DRAW);
|
||||
|
||||
GLuint elementBuffer;
|
||||
glGenBuffers(1, &elementBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, elementBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, indices.size() * sizeof(unsigned short),
|
||||
&indices[0], GL_STATIC_DRAW);
|
||||
|
||||
GLuint texture = SOIL_load_OGL_texture(
|
||||
"../textures/results/texture_BMP_DXT5_3.DDS", SOIL_LOAD_AUTO,
|
||||
SOIL_CREATE_NEW_ID,
|
||||
SOIL_FLAG_MIPMAPS | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT);
|
||||
if (texture == 0) {
|
||||
printf("Texture failed to load\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLuint programID =
|
||||
loadShaders("../shaders/shader.vert", "../shaders/shader.frag");
|
||||
|
||||
// I love glm
|
||||
// Projection matrix, 45deg FOV, 4:3 Aspect Ratio, Planes: 0.1units ->
|
||||
// 100units
|
||||
glm::mat4 projection = glm::perspective(
|
||||
glm::radians(45.0f), (float)WIDTH / (float)HEIGHT, 0.1f, 100.0f);
|
||||
|
||||
// Camera matrix
|
||||
glm::mat4 view =
|
||||
glm::lookAt(glm::vec3(4, 3, 3), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
|
||||
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
|
||||
// Model view projection, the combination of the three vectors
|
||||
glm::mat4 mvp = projection * view * model;
|
||||
|
||||
GLuint matrixID = glGetUniformLocation(programID, "MVP");
|
||||
|
||||
glEnable(GL_DEPTH_TEST); // Turn on the Z-buffer
|
||||
glDepthFunc(GL_LESS); // Accept only the closest fragments
|
||||
|
||||
glEnable(GL_CULL_FACE); // Backface culling
|
||||
|
||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||
|
||||
// Define camera stuff
|
||||
glm::vec3 position = {4, 3, 3};
|
||||
float horizontalAngle = 3.14F; // Toward -Z, in Rads
|
||||
float verticalAngle = 0.0f; // On the horizon
|
||||
float initialFOV = 60.0f;
|
||||
|
||||
float speed = 3.0f;
|
||||
float mouseSpeed = 0.005f;
|
||||
|
||||
double xpos, ypos;
|
||||
|
||||
double lastTime = 0;
|
||||
while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS &&
|
||||
glfwWindowShouldClose(window) == 0) {
|
||||
// Clear this mf
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glUseProgram(programID);
|
||||
|
||||
// ImGui
|
||||
// if (glfwGetWindowAttrib(window, GLFW_ICONIFIED) != 0) {
|
||||
// ImGui_ImplGlfw_Sleep(10);
|
||||
// continue; // No rendering while minimized
|
||||
// }
|
||||
|
||||
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
|
||||
ImGui::NewFrame();
|
||||
|
||||
// ImGui::ShowDemoWindow();
|
||||
ImGui::Begin("DEBUG INFO");
|
||||
ImGui::Text("MVP:");
|
||||
if (ImGui::BeginTable("mvp", 4)) {
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%f", mvp[0][0]);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%f", mvp[0][1]);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%f", mvp[0][2]);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%f", mvp[0][3]);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%f", mvp[1][0]);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%f", mvp[1][1]);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%f", mvp[1][2]);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%f", mvp[1][3]);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%f", mvp[2][0]);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%f", mvp[2][1]);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%f", mvp[2][2]);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%f", mvp[2][3]);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%f", mvp[3][0]);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%f", mvp[3][1]);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%f", mvp[3][2]);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%f", mvp[3][3]);
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
// Compute a Fresh Super Sigma MVP
|
||||
// What would an input system be without delta time
|
||||
double currentTime = glfwGetTime();
|
||||
float deltaTime = (float)(currentTime - lastTime);
|
||||
|
||||
glfwGetCursorPos(window, &xpos, &ypos);
|
||||
glfwSetCursorPos(window, (float)(WIDTH) / 2, (float)(HEIGHT) / 2);
|
||||
|
||||
horizontalAngle +=
|
||||
mouseSpeed * deltaTime * (float)((float)(WIDTH) / 2 - xpos);
|
||||
verticalAngle +=
|
||||
mouseSpeed * deltaTime * (float)((float)(HEIGHT) / 2 - ypos);
|
||||
glm::vec3 direction(cos(verticalAngle) * sin(horizontalAngle),
|
||||
sin(verticalAngle),
|
||||
cos(verticalAngle) * cos(horizontalAngle));
|
||||
glm::vec3 right(sin(horizontalAngle - 3.14f / 2.0f), 0,
|
||||
cos(horizontalAngle - 3.14f / 2.0f));
|
||||
glm::vec3 up = glm::cross(right, direction);
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {
|
||||
position += direction * deltaTime * speed;
|
||||
}
|
||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
|
||||
position -= direction * deltaTime * speed;
|
||||
}
|
||||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
|
||||
position += right * deltaTime * speed;
|
||||
}
|
||||
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
|
||||
position -= right * deltaTime * speed;
|
||||
}
|
||||
|
||||
// float FOV = initialFOV;
|
||||
// Disabled because unchanged
|
||||
// glm_perspective(glm_rad(FOV), 4.0f/ 3.0f, 0.1f, 100.0f, projection);
|
||||
glm::mat4 view = glm::lookAt(position, position + direction, up);
|
||||
mvp = projection * view * model;
|
||||
|
||||
// Send mega sigma MVP to the vertex shader (transformations for the win)
|
||||
glUniformMatrix4fv(matrixID, 1, GL_FALSE, &mvp[0][0]);
|
||||
|
||||
// DRAWING HAPPENS HERE
|
||||
// Vertex Data
|
||||
glEnableVertexAttribArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void *)0);
|
||||
|
||||
// UV Data
|
||||
glEnableVertexAttribArray(1);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, uvBuffer);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void *)0);
|
||||
|
||||
// Normal Data
|
||||
glEnableVertexAttribArray(2);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, normalBuffer);
|
||||
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, (void *)0);
|
||||
|
||||
// Index buffer
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBuffer);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT, (void *)0);
|
||||
|
||||
glDisableVertexAttribArray(0);
|
||||
glDisableVertexAttribArray(1);
|
||||
glDisableVertexAttribArray(2);
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
// Swap buffers
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
|
||||
lastTime = currentTime; // Count total frame time
|
||||
}
|
||||
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
glDeleteBuffers(1, &vertexBuffer);
|
||||
glDeleteBuffers(1, &uvBuffer);
|
||||
glDeleteBuffers(1, &normalBuffer);
|
||||
glDeleteBuffers(1, &elementBuffer);
|
||||
glDeleteProgram(programID);
|
||||
glDeleteTextures(1, &texture);
|
||||
glDeleteVertexArrays(1, &vertexArrayID);
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() { return initWindow(); }
|
1
include/SOIL2
Submodule
1
include/SOIL2
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 229324688c26f1e31da0171f3f5193f12253619e
|
1
include/assimp
Submodule
1
include/assimp
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 1d99895e91829296c0ddfd06176735ccec313c34
|
1
include/glew
Submodule
1
include/glew
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit b323ebf9adeae6a3f26f91277d4f62df509037fc
|
1
include/glfw
Submodule
1
include/glfw
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit b35641f4a3c62aa86a0b3c983d163bc0fe36026d
|
1
include/glm
Submodule
1
include/glm
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 33b4a621a697a305bc3a7610d290677b96beb181
|
1
include/imgui
Submodule
1
include/imgui
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit cb16568fca5297512ff6a8f3b877f461c4323fbe
|
197
models/model.obj
Normal file
197
models/model.obj
Normal file
@ -0,0 +1,197 @@
|
||||
# Blender 4.2.2 LTS
|
||||
# www.blender.org
|
||||
o Cone
|
||||
v 0.000000 -1.000000 -1.000000
|
||||
v 0.195090 -1.000000 -0.980785
|
||||
v 0.382683 -1.000000 -0.923880
|
||||
v 0.555570 -1.000000 -0.831470
|
||||
v 0.707107 -1.000000 -0.707107
|
||||
v 0.831470 -1.000000 -0.555570
|
||||
v 0.923880 -1.000000 -0.382683
|
||||
v 0.980785 -1.000000 -0.195090
|
||||
v 1.000000 -1.000000 0.000000
|
||||
v 0.980785 -1.000000 0.195090
|
||||
v 0.923880 -1.000000 0.382683
|
||||
v 0.831470 -1.000000 0.555570
|
||||
v 0.707107 -1.000000 0.707107
|
||||
v 0.555570 -1.000000 0.831470
|
||||
v 0.382683 -1.000000 0.923880
|
||||
v 0.195090 -1.000000 0.980785
|
||||
v 0.000000 -1.000000 1.000000
|
||||
v -0.195090 -1.000000 0.980785
|
||||
v -0.382683 -1.000000 0.923880
|
||||
v -0.555570 -1.000000 0.831470
|
||||
v -0.707107 -1.000000 0.707107
|
||||
v -0.831470 -1.000000 0.555570
|
||||
v -0.923880 -1.000000 0.382683
|
||||
v -0.980785 -1.000000 0.195090
|
||||
v -1.000000 -1.000000 0.000000
|
||||
v -0.980785 -1.000000 -0.195090
|
||||
v -0.923880 -1.000000 -0.382683
|
||||
v -0.831470 -1.000000 -0.555570
|
||||
v -0.707107 -1.000000 -0.707107
|
||||
v -0.555570 -1.000000 -0.831470
|
||||
v -0.382683 -1.000000 -0.923880
|
||||
v -0.195090 -1.000000 -0.980785
|
||||
v 0.000000 1.000000 0.000000
|
||||
vn 0.0878 0.4455 -0.8910
|
||||
vn 0.2599 0.4455 -0.8567
|
||||
vn 0.4220 0.4455 -0.7896
|
||||
vn 0.5680 0.4455 -0.6921
|
||||
vn 0.6921 0.4455 -0.5680
|
||||
vn 0.7896 0.4455 -0.4220
|
||||
vn 0.8567 0.4455 -0.2599
|
||||
vn 0.8910 0.4455 -0.0878
|
||||
vn 0.8910 0.4455 0.0878
|
||||
vn 0.8567 0.4455 0.2599
|
||||
vn 0.7896 0.4455 0.4220
|
||||
vn 0.6921 0.4455 0.5680
|
||||
vn 0.5680 0.4455 0.6921
|
||||
vn 0.4220 0.4455 0.7896
|
||||
vn 0.2599 0.4455 0.8567
|
||||
vn 0.0878 0.4455 0.8910
|
||||
vn -0.0878 0.4455 0.8910
|
||||
vn -0.2599 0.4455 0.8567
|
||||
vn -0.4220 0.4455 0.7896
|
||||
vn -0.5680 0.4455 0.6921
|
||||
vn -0.6921 0.4455 0.5680
|
||||
vn -0.7896 0.4455 0.4220
|
||||
vn -0.8567 0.4455 0.2599
|
||||
vn -0.8910 0.4455 0.0878
|
||||
vn -0.8910 0.4455 -0.0878
|
||||
vn -0.8567 0.4455 -0.2599
|
||||
vn -0.7896 0.4455 -0.4220
|
||||
vn -0.6921 0.4455 -0.5680
|
||||
vn -0.5680 0.4455 -0.6921
|
||||
vn -0.4220 0.4455 -0.7896
|
||||
vn -0.0000 -1.0000 -0.0000
|
||||
vn -0.2599 0.4455 -0.8567
|
||||
vn -0.0878 0.4455 -0.8910
|
||||
vt 0.501953 1.013587
|
||||
vt 0.501953 0.501953
|
||||
vt 0.601768 1.003756
|
||||
vt 0.697747 0.974641
|
||||
vt 0.786201 0.927361
|
||||
vt 0.863733 0.863733
|
||||
vt 0.927361 0.786201
|
||||
vt 0.974641 0.697747
|
||||
vt 1.003756 0.601768
|
||||
vt 1.013587 0.501953
|
||||
vt 1.003756 0.402138
|
||||
vt 0.974641 0.306159
|
||||
vt 0.927361 0.217705
|
||||
vt 0.863733 0.140174
|
||||
vt 0.786201 0.076546
|
||||
vt 0.697747 0.029266
|
||||
vt 0.601768 0.000151
|
||||
vt 0.501953 -0.009680
|
||||
vt 0.402138 0.000151
|
||||
vt 0.306159 0.029266
|
||||
vt 0.217705 0.076546
|
||||
vt 0.140174 0.140174
|
||||
vt 0.076546 0.217705
|
||||
vt 0.029266 0.306159
|
||||
vt 0.000151 0.402138
|
||||
vt -0.009680 0.501953
|
||||
vt 0.000151 0.601768
|
||||
vt 0.029266 0.697747
|
||||
vt 0.076546 0.786201
|
||||
vt 0.140174 0.863733
|
||||
vt 0.217705 0.927361
|
||||
vt 0.306159 0.974641
|
||||
vt 0.327532 0.912128
|
||||
vt 0.921894 0.643171
|
||||
vt 0.652937 0.048809
|
||||
vt 0.402138 1.003756
|
||||
vt 0.565598 0.025362
|
||||
vt 0.475363 0.019404
|
||||
vt 0.385699 0.031164
|
||||
vt 0.300053 0.060191
|
||||
vt 0.221715 0.105369
|
||||
vt 0.153697 0.164962
|
||||
vt 0.098611 0.236680
|
||||
vt 0.058575 0.317766
|
||||
vt 0.035127 0.405105
|
||||
vt 0.029169 0.495340
|
||||
vt 0.040930 0.585004
|
||||
vt 0.069957 0.670650
|
||||
vt 0.115135 0.748988
|
||||
vt 0.174728 0.817007
|
||||
vt 0.246445 0.872092
|
||||
vt 0.414871 0.935576
|
||||
vt 0.505106 0.941534
|
||||
vt 0.594769 0.929773
|
||||
vt 0.680416 0.900746
|
||||
vt 0.758753 0.855568
|
||||
vt 0.826772 0.795975
|
||||
vt 0.881858 0.724258
|
||||
vt 0.945341 0.555833
|
||||
vt 0.951299 0.465597
|
||||
vt 0.939539 0.375934
|
||||
vt 0.910512 0.290288
|
||||
vt 0.865334 0.211950
|
||||
vt 0.805741 0.143931
|
||||
vt 0.734023 0.088845
|
||||
s 0
|
||||
f 1/1/1 33/2/1 2/3/1
|
||||
f 2/3/2 33/2/2 3/4/2
|
||||
f 3/4/3 33/2/3 4/5/3
|
||||
f 4/5/4 33/2/4 5/6/4
|
||||
f 5/6/5 33/2/5 6/7/5
|
||||
f 6/7/6 33/2/6 7/8/6
|
||||
f 7/8/7 33/2/7 8/9/7
|
||||
f 8/9/8 33/2/8 9/10/8
|
||||
f 9/10/9 33/2/9 10/11/9
|
||||
f 10/11/10 33/2/10 11/12/10
|
||||
f 11/12/11 33/2/11 12/13/11
|
||||
f 12/13/12 33/2/12 13/14/12
|
||||
f 13/14/13 33/2/13 14/15/13
|
||||
f 14/15/14 33/2/14 15/16/14
|
||||
f 15/16/15 33/2/15 16/17/15
|
||||
f 16/17/16 33/2/16 17/18/16
|
||||
f 17/18/17 33/2/17 18/19/17
|
||||
f 18/19/18 33/2/18 19/20/18
|
||||
f 19/20/19 33/2/19 20/21/19
|
||||
f 20/21/20 33/2/20 21/22/20
|
||||
f 21/22/21 33/2/21 22/23/21
|
||||
f 22/23/22 33/2/22 23/24/22
|
||||
f 23/24/23 33/2/23 24/25/23
|
||||
f 24/25/24 33/2/24 25/26/24
|
||||
f 25/26/25 33/2/25 26/27/25
|
||||
f 26/27/26 33/2/26 27/28/26
|
||||
f 27/28/27 33/2/27 28/29/27
|
||||
f 28/29/28 33/2/28 29/30/28
|
||||
f 29/30/29 33/2/29 30/31/29
|
||||
f 30/31/30 33/2/30 31/32/30
|
||||
f 16/33/31 24/34/31 32/35/31
|
||||
f 31/32/32 33/2/32 32/36/32
|
||||
f 32/36/33 33/2/33 1/1/33
|
||||
f 32/35/31 1/37/31 2/38/31
|
||||
f 2/38/31 3/39/31 4/40/31
|
||||
f 4/40/31 5/41/31 6/42/31
|
||||
f 6/42/31 7/43/31 8/44/31
|
||||
f 8/44/31 9/45/31 10/46/31
|
||||
f 10/46/31 11/47/31 12/48/31
|
||||
f 12/48/31 13/49/31 14/50/31
|
||||
f 14/50/31 15/51/31 16/33/31
|
||||
f 16/33/31 17/52/31 18/53/31
|
||||
f 18/53/31 19/54/31 20/55/31
|
||||
f 20/55/31 21/56/31 22/57/31
|
||||
f 22/57/31 23/58/31 24/34/31
|
||||
f 24/34/31 25/59/31 26/60/31
|
||||
f 26/60/31 27/61/31 28/62/31
|
||||
f 28/62/31 29/63/31 30/64/31
|
||||
f 30/64/31 31/65/31 32/35/31
|
||||
f 32/35/31 2/38/31 8/44/31
|
||||
f 2/38/31 4/40/31 8/44/31
|
||||
f 4/40/31 6/42/31 8/44/31
|
||||
f 8/44/31 10/46/31 16/33/31
|
||||
f 10/46/31 12/48/31 16/33/31
|
||||
f 12/48/31 14/50/31 16/33/31
|
||||
f 16/33/31 18/53/31 24/34/31
|
||||
f 18/53/31 20/55/31 24/34/31
|
||||
f 20/55/31 22/57/31 24/34/31
|
||||
f 24/34/31 26/60/31 32/35/31
|
||||
f 26/60/31 28/62/31 32/35/31
|
||||
f 28/62/31 30/64/31 32/35/31
|
||||
f 32/35/31 8/44/31 16/33/31
|
96
shader.c
Normal file
96
shader.c
Normal file
@ -0,0 +1,96 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <unistd.h>
|
||||
|
||||
GLuint loadShaders(const char *vertex_file_path,
|
||||
const char *fragment_file_path) {
|
||||
GLuint vertexShaderID = glCreateShader(GL_VERTEX_SHADER);
|
||||
GLuint fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
|
||||
FILE *vertexShaderFD;
|
||||
vertexShaderFD = fopen(vertex_file_path, "rb");
|
||||
if (vertexShaderFD == NULL) {
|
||||
fclose(vertexShaderFD);
|
||||
fprintf(stderr, "Failed to open Vertex Shader");
|
||||
return 1;
|
||||
}
|
||||
int vertexShaderLength = lseek(fileno(vertexShaderFD), 0L, SEEK_END) + 1;
|
||||
fseek(vertexShaderFD, 0L, SEEK_SET);
|
||||
char *vertexShaderCode = (char *)calloc(vertexShaderLength, sizeof(char));
|
||||
fread(vertexShaderCode, sizeof(*vertexShaderCode), vertexShaderLength,
|
||||
vertexShaderFD);
|
||||
fclose(vertexShaderFD);
|
||||
|
||||
FILE *fragmentShaderFD;
|
||||
fragmentShaderFD = fopen(fragment_file_path, "rb");
|
||||
if (fragmentShaderFD == NULL) {
|
||||
fclose(fragmentShaderFD);
|
||||
fprintf(stderr, "Failed to open Fragment Shader");
|
||||
return 1;
|
||||
}
|
||||
int fragmentShaderLength = lseek(fileno(fragmentShaderFD), 0L, SEEK_END) + 1;
|
||||
fseek(fragmentShaderFD, 0L, SEEK_SET);
|
||||
char *fragmentShaderCode = (char *)calloc(fragmentShaderLength, sizeof(char));
|
||||
fread(fragmentShaderCode, sizeof(*fragmentShaderCode), fragmentShaderLength,
|
||||
fragmentShaderFD);
|
||||
fclose(fragmentShaderFD);
|
||||
|
||||
GLint result = GL_FALSE;
|
||||
int infoLogLength;
|
||||
|
||||
printf("Compiling shader: %s\n", vertex_file_path);
|
||||
char const *vertexShaderCodeConst = vertexShaderCode;
|
||||
glShaderSource(vertexShaderID, 1, &vertexShaderCodeConst, NULL);
|
||||
glCompileShader(vertexShaderID);
|
||||
|
||||
glGetShaderiv(vertexShaderID, GL_COMPILE_STATUS, &result);
|
||||
glGetShaderiv(vertexShaderID, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||
if (infoLogLength > 0) {
|
||||
char *vertexShaderErrorMessage[infoLogLength + 1];
|
||||
glGetShaderInfoLog(vertexShaderID, infoLogLength, NULL,
|
||||
*vertexShaderErrorMessage);
|
||||
printf("%s\n", *vertexShaderErrorMessage);
|
||||
}
|
||||
|
||||
printf("Compiling shader: %s\n", fragment_file_path);
|
||||
char const *fragmentShaderCodeConst = fragmentShaderCode;
|
||||
glShaderSource(fragmentShaderID, 1, &fragmentShaderCodeConst, NULL);
|
||||
glCompileShader(fragmentShaderID);
|
||||
|
||||
glGetShaderiv(fragmentShaderID, GL_COMPILE_STATUS, &result);
|
||||
glGetShaderiv(fragmentShaderID, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||
if (infoLogLength > 0) {
|
||||
char *fragmentShaderErrorMessage[infoLogLength + 1];
|
||||
glGetShaderInfoLog(fragmentShaderID, infoLogLength, NULL,
|
||||
*fragmentShaderErrorMessage);
|
||||
printf("%s\n", *fragmentShaderErrorMessage);
|
||||
}
|
||||
|
||||
printf("Linking program\n");
|
||||
GLuint programID = glCreateProgram();
|
||||
glAttachShader(programID, vertexShaderID);
|
||||
glAttachShader(programID, fragmentShaderID);
|
||||
glLinkProgram(programID);
|
||||
|
||||
glGetProgramiv(programID, GL_COMPILE_STATUS, &result);
|
||||
glGetProgramiv(programID, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||
if (infoLogLength > 0) {
|
||||
char *programErrorMessage[infoLogLength + 1];
|
||||
glGetProgramInfoLog(programID, infoLogLength, NULL, *programErrorMessage);
|
||||
printf("%s\n", *programErrorMessage);
|
||||
}
|
||||
|
||||
glDetachShader(programID, vertexShaderID);
|
||||
glDetachShader(programID, fragmentShaderID);
|
||||
|
||||
glDeleteShader(vertexShaderID);
|
||||
glDeleteShader(fragmentShaderID);
|
||||
|
||||
free(vertexShaderCode);
|
||||
free(fragmentShaderCode);
|
||||
|
||||
return programID;
|
||||
}
|
11
shader.h
Normal file
11
shader.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef LOAD_SHADERS_H
|
||||
#define LOAD_SHADERS_H
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <unistd.h>
|
||||
|
||||
GLuint loadShaders(const char *vertex_file_path,
|
||||
const char *fragment_file_path);
|
||||
|
||||
#endif
|
14
shaders/shader.frag
Normal file
14
shaders/shader.frag
Normal file
@ -0,0 +1,14 @@
|
||||
#version 330 core
|
||||
|
||||
// Interpolated vals from vert shaders
|
||||
in vec2 UV;
|
||||
|
||||
out vec3 color;
|
||||
|
||||
// Values stay constant
|
||||
uniform sampler2D textureSampler;
|
||||
|
||||
void main() {
|
||||
color = texture(textureSampler, UV).rgb;
|
||||
//color = vec3(1, 1, 1);
|
||||
}
|
20
shaders/shader.vert
Normal file
20
shaders/shader.vert
Normal file
@ -0,0 +1,20 @@
|
||||
#version 330 core
|
||||
|
||||
layout(location = 0) in vec3 vertexPosition_modelspace;
|
||||
layout(location = 1) in vec2 vertexUV;
|
||||
|
||||
// To the frag shader
|
||||
out vec2 UV;
|
||||
|
||||
// Model view projection from the CPU
|
||||
uniform mat4 MVP;
|
||||
|
||||
void main() {
|
||||
gl_Position = MVP * vec4(vertexPosition_modelspace, 1);
|
||||
|
||||
vec2 UV_FLIPPED;
|
||||
UV_FLIPPED.x = vertexUV.x;
|
||||
UV_FLIPPED.y = 1.0 - vertexUV.y;
|
||||
|
||||
UV = vertexUV;
|
||||
}
|
41
textures/fred.cprj
Normal file
41
textures/fred.cprj
Normal file
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<PROJECT>
|
||||
<Image File="//wsl.localhost/Fedora/home/fedora/fred/textures/texture.bmp">
|
||||
<Compression Setting="texture_BMP_DXT3_2" Enabled="False">
|
||||
<Source>//wsl.localhost/Fedora/home/fedora/fred/textures/texture.bmp</Source>
|
||||
<Destination>//wsl.localhost/Fedora/home/fedora/fred/textures/results/texture_BMP_DXT3_2.DDS</Destination>
|
||||
<fd>DXT3</fd>
|
||||
<Quality>0.2</Quality>
|
||||
<WeightR>0.3086</WeightR>
|
||||
<WeightG>0.6094</WeightG>
|
||||
<WeightB>0.082</WeightB>
|
||||
<AlphaThreshold>0</AlphaThreshold>
|
||||
<RefineSteps>0</RefineSteps>
|
||||
<BlockRate>8.00</BlockRate>
|
||||
</Compression>
|
||||
<Compression Setting="texture_BMP_DXT5_3" Enabled="False">
|
||||
<Source>//wsl.localhost/Fedora/home/fedora/fred/textures/texture.bmp</Source>
|
||||
<Destination>//wsl.localhost/Fedora/home/fedora/fred/textures/results/texture_BMP_DXT5_3.DDS</Destination>
|
||||
<fd>DXT5</fd>
|
||||
<Quality>0.05</Quality>
|
||||
<WeightR>0.3086</WeightR>
|
||||
<WeightG>0.6094</WeightG>
|
||||
<WeightB>0.082</WeightB>
|
||||
<AlphaThreshold>0</AlphaThreshold>
|
||||
<RefineSteps>0</RefineSteps>
|
||||
<BlockRate>8.00</BlockRate>
|
||||
</Compression>
|
||||
<Compression Setting="texture_BMP_DXT1_1" Enabled="False">
|
||||
<Source>//wsl.localhost/Fedora/home/fedora/fred/textures/texture.bmp</Source>
|
||||
<Destination>//wsl.localhost/Fedora/home/fedora/fred/textures/results/texture_BMP_DXT1_1.DDS</Destination>
|
||||
<fd>DXT1</fd>
|
||||
<Quality>0.05</Quality>
|
||||
<WeightR>0.3086</WeightR>
|
||||
<WeightG>0.6094</WeightG>
|
||||
<WeightB>0.082</WeightB>
|
||||
<AlphaThreshold>0</AlphaThreshold>
|
||||
<RefineSteps>0</RefineSteps>
|
||||
<BlockRate>8.00</BlockRate>
|
||||
</Compression>
|
||||
</Image>
|
||||
</PROJECT>
|
BIN
textures/results/texture_BMP_DXT1_1.DDS
Normal file
BIN
textures/results/texture_BMP_DXT1_1.DDS
Normal file
Binary file not shown.
BIN
textures/results/texture_BMP_DXT3_2.DDS
Normal file
BIN
textures/results/texture_BMP_DXT3_2.DDS
Normal file
Binary file not shown.
BIN
textures/results/texture_BMP_DXT5_3.DDS
Normal file
BIN
textures/results/texture_BMP_DXT5_3.DDS
Normal file
Binary file not shown.
BIN
textures/texture.bmp
Normal file
BIN
textures/texture.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.0 MiB |
Loading…
Reference in New Issue
Block a user