commit
9ad4d9c3a4
32
.github/workflows/compile.yml
vendored
Normal file
32
.github/workflows/compile.yml
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
name: Test Compilation
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ $default-branch ]
|
||||
pull_request:
|
||||
branches: [ $default-branch ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install python depdencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install jinja2
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
DEBIAN_FRONTEND=noninteractive apt update -y
|
||||
DEBIAN_FRONTEND=noninteractive apt install -y build-essential cmake pkg-config mesa-utils mesa-common-dev libao-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev
|
||||
- name: CMake build files
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
- name: Build project
|
||||
run: |
|
||||
cd build
|
||||
make
|
41
.gitmodules
vendored
41
.gitmodules
vendored
@ -1,30 +1,27 @@
|
||||
[submodule "SOIL2"]
|
||||
path = SOIL2
|
||||
[submodule "extern/SOIL2"]
|
||||
path = extern/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
|
||||
[submodule "extern/assimp"]
|
||||
path = extern/assimp
|
||||
url = https://github.com/assimp/assimp
|
||||
[submodule "include/glew"]
|
||||
path = include/glew
|
||||
[submodule "extern/glew"]
|
||||
path = extern/glew
|
||||
url = https://github.com/nigels-com/glew
|
||||
[submodule "include/glfw"]
|
||||
path = include/glfw
|
||||
[submodule "extern/glfw"]
|
||||
path = extern/glfw
|
||||
url = https://github.com/glfw/glfw
|
||||
[submodule "include/glm"]
|
||||
path = include/glm
|
||||
[submodule "extern/glm"]
|
||||
path = extern/glm
|
||||
url = https://github.com/g-truc/glm
|
||||
[submodule "include/imgui"]
|
||||
path = include/imgui
|
||||
[submodule "extern/imgui"]
|
||||
path = extern/imgui
|
||||
url = https://github.com/ocornut/imgui
|
||||
[submodule "include/CLog"]
|
||||
path = include/CLog
|
||||
[submodule "extern/CLog"]
|
||||
path = extern/CLog
|
||||
url = https://github.com/williamistGitHub/CLog.git
|
||||
[submodule "include/glad"]
|
||||
path = include/glad
|
||||
[submodule "extern/glad"]
|
||||
path = extern/glad
|
||||
url = https://github.com/Dav1dde/glad.git
|
||||
[submodule "include/imGuIZMO.quat"]
|
||||
path = include/imGuIZMO.quat
|
||||
url = https://github.com/BrutPitt/imGuIZMO.quat.git
|
||||
[submodule "extern/imGuIZMO.quat"]
|
||||
path = extern/imGuIZMO.quat
|
||||
url = https://github.com/BrutPitt/imGuIZMO.quat
|
||||
|
@ -30,60 +30,31 @@ if(CMAKE_BINARY_DIR MATCHES " ")
|
||||
WARNING "Spaces in the build dir can cause errors, thou art been warned\n")
|
||||
endif()
|
||||
|
||||
add_subdirectory(include/glm)
|
||||
add_subdirectory(include/glfw)
|
||||
add_subdirectory(include/SOIL2)
|
||||
add_subdirectory(include/assimp)
|
||||
add_subdirectory(include/CLog)
|
||||
add_subdirectory(extern/glm)
|
||||
add_subdirectory(extern/glfw)
|
||||
add_subdirectory(extern/SOIL2)
|
||||
add_subdirectory(extern/assimp)
|
||||
add_subdirectory(extern/CLog)
|
||||
|
||||
# Glad is configured using cmake (unlike glew)
|
||||
# https://github.com/Dav1dde/glad/wiki/C#cmake
|
||||
set(GLAD_SOURCES_DIR "${PROJECT_SOURCE_DIR}/include/glad")
|
||||
set(GLAD_SOURCES_DIR "${PROJECT_SOURCE_DIR}/extern/glad")
|
||||
add_subdirectory("${GLAD_SOURCES_DIR}/cmake" glad_cmake)
|
||||
|
||||
glad_add_library(glad_gl_core_33 REPRODUCIBLE API gl:core=3.3)
|
||||
|
||||
include_directories(include/imgui) # ImGui doesn't have a CMakeLists of its own
|
||||
include_directories(extern/imgui) # ImGui doesn't have a CMakeLists of its own
|
||||
add_library(
|
||||
imgui STATIC
|
||||
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)
|
||||
extern/imgui/imgui.cpp
|
||||
extern/imgui/imgui_demo.cpp
|
||||
extern/imgui/imgui_draw.cpp
|
||||
extern/imgui/imgui_tables.cpp
|
||||
extern/imgui/imgui_widgets.cpp
|
||||
extern/imgui/backends/imgui_impl_glfw.cpp # Zingaloid backend import
|
||||
extern/imgui/backends/imgui_impl_opengl3.cpp)
|
||||
target_link_libraries(imgui glfw)
|
||||
|
||||
# include_directories(include) # Kill me please. this is horrendously bad but ImGuIZMO.quat hardcodes imgui to be in a folder called ImGui
|
||||
include_directories(include/imGuIZMO.quat)
|
||||
add_library(
|
||||
imGuIZMO STATIC
|
||||
include/imGuIZMO.quat/imGuIZMO.quat/imGuIZMOquat.cpp
|
||||
)
|
||||
target_link_libraries(imGuIZMO imgui -DIMGUIZMO_IMGUI_FOLDER=${CMAKE_SOURCE_DIR}/include/imgui)
|
||||
|
||||
add_executable(fred engine.cpp shader.c)
|
||||
if(UNIX)
|
||||
target_link_libraries(
|
||||
fred
|
||||
-lm
|
||||
glad_gl_core_33
|
||||
glm
|
||||
glfw
|
||||
soil2
|
||||
assimp
|
||||
imgui
|
||||
clog)
|
||||
endif()
|
||||
if(WIN32)
|
||||
target_link_libraries(
|
||||
fred
|
||||
glad_gl_core_33
|
||||
glm
|
||||
glfw
|
||||
soil2
|
||||
assimp
|
||||
imgui
|
||||
clog)
|
||||
endif()
|
||||
add_executable(fred src/engine.cpp src/shader.c)
|
||||
target_link_libraries(fred $<$<PLATFORM_ID:Linux>:-lm> glad_gl_core_33 glm glfw
|
||||
soil2 assimp imgui clog)
|
||||
|
31
TODO.md
31
TODO.md
@ -1,3 +1,28 @@
|
||||
[ ] Make ImGuIZMO.quat work
|
||||
[ ] Make SOIL2 stop giving that smelly error message
|
||||
[ ] Overhaul asset debug screen
|
||||
### Todo
|
||||
|
||||
- [ ] Finish modularization
|
||||
- [ ] Lightmapped/Shadowmapped Lighting
|
||||
- [ ] Get ziggy with it
|
||||
- [ ] Convert manual memory alloc to shared and unique pointers
|
||||
- [ ] Text
|
||||
- [ ] RT/texture rendering
|
||||
- [ ] Additional constructors for arguements that are potentially optional
|
||||
- [ ] Billboards / Instancing
|
||||
- [ ] Multiple lights
|
||||
- [ ] Physics
|
||||
- [ ] Sound
|
||||
- [ ] Mesh deformation/animation
|
||||
|
||||
### In progress
|
||||
|
||||
- [ ] Tools for making UI, assets and other engine specific things
|
||||
- [ ] Custom file formats
|
||||
- [ ] Make ImGuIZMO.quat work
|
||||
|
||||
### Done
|
||||
|
||||
- [x] Implement Cameras
|
||||
- [x] Simple Lighting
|
||||
- [x] Overhaul asset debug screen
|
||||
- [x] Make SOIL2 stop giving that smelly error message (My PR was accepted)
|
||||
- [x] Destruct all at the end
|
||||
|
1
extern/CLog
vendored
Submodule
1
extern/CLog
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 78f58ffefc782c3bcc0bccaf7df38b064da6f170
|
0
include/SOIL2 → extern/SOIL2
vendored
0
include/SOIL2 → extern/SOIL2
vendored
0
include/assimp → extern/assimp
vendored
0
include/assimp → extern/assimp
vendored
0
include/glad → extern/glad
vendored
0
include/glad → extern/glad
vendored
0
include/glfw → extern/glfw
vendored
0
include/glfw → extern/glfw
vendored
0
include/glm → extern/glm
vendored
0
include/glm → extern/glm
vendored
0
include/imgui → extern/imgui
vendored
0
include/imgui → extern/imgui
vendored
@ -1 +0,0 @@
|
||||
Subproject commit 906059bd02731184f80d8b3e789e61c5499213d0
|
2068
models/suzanne.obj
Normal file
2068
models/suzanne.obj
Normal file
File diff suppressed because it is too large
Load Diff
24900
models/teapot.obj
Normal file
24900
models/teapot.obj
Normal file
File diff suppressed because it is too large
Load Diff
@ -7,10 +7,10 @@ layout(location = 1) in vec2 vertexUV;
|
||||
out vec2 UV;
|
||||
|
||||
// Model view projection from the CPU
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 mvp;
|
||||
|
||||
void main() {
|
||||
gl_Position = MVP * vec4(vertexPosition_modelspace, 1);
|
||||
gl_Position = mvp * vec4(vertexPosition_modelspace, 1);
|
||||
//gl_Position = vec4(vertexPosition_modelspace, 1);
|
||||
|
||||
vec2 UV_FLIPPED;
|
34
shaders/basic_lit.frag
Normal file
34
shaders/basic_lit.frag
Normal file
@ -0,0 +1,34 @@
|
||||
#version 330 core
|
||||
|
||||
in vec2 UV;
|
||||
in vec3 position_worldspace;
|
||||
in vec3 normal_cameraspace;
|
||||
in vec3 eyeDirection_cameraspace;
|
||||
in vec3 lightDirection_cameraspace;
|
||||
|
||||
out vec3 color;
|
||||
|
||||
uniform sampler2D albedoSampler;
|
||||
uniform sampler2D specularSampler;
|
||||
uniform mat4 mv; // mv of mvp (Model, View, Projection)
|
||||
uniform vec3 lightPosition_worldspace;
|
||||
uniform vec3 lightColor;
|
||||
uniform float lightPower;
|
||||
|
||||
void main() {
|
||||
vec3 materialDiffuseColor = texture(albedoSampler, UV).rgb;
|
||||
vec3 materialAmbientColor = vec3(0.1, 0.1, 0.1) * materialDiffuseColor;
|
||||
vec3 materialSpecularColor = texture(specularSampler, UV).rgb;
|
||||
|
||||
float distance = length(lightPosition_worldspace - position_worldspace);
|
||||
|
||||
vec3 n = normalize(normal_cameraspace);
|
||||
vec3 l = normalize(lightDirection_cameraspace);
|
||||
float cosTheta = clamp(dot(n, vec3(1.0)), 0, 1);
|
||||
|
||||
vec3 E = normalize(eyeDirection_cameraspace);
|
||||
vec3 R = reflect(vec3(-1.0), n);
|
||||
float cosAlpha = clamp(dot(E, R), 0, 1);
|
||||
|
||||
color = materialAmbientColor + materialDiffuseColor * lightColor * lightPower * cosTheta / (distance*distance) + materialSpecularColor * lightColor * lightPower * pow(cosAlpha, 5) / (distance * distance);
|
||||
}
|
32
shaders/basic_lit.vert
Normal file
32
shaders/basic_lit.vert
Normal file
@ -0,0 +1,32 @@
|
||||
#version 330 core
|
||||
|
||||
layout(location = 0) in vec3 vertexPosition_modelspace;
|
||||
layout(location = 1) in vec2 vertexUV;
|
||||
layout(location = 2) in vec3 vertexNormal_modelspace;
|
||||
|
||||
out vec2 UV;
|
||||
out vec3 position_worldspace;
|
||||
out vec3 normal_cameraspace;
|
||||
out vec3 eyeDirection_cameraspace;
|
||||
out vec3 lightDirection_cameraspace;
|
||||
|
||||
uniform mat4 mvp;
|
||||
uniform mat4 v;
|
||||
uniform mat4 m;
|
||||
uniform vec3 lightPosition_worldspace;
|
||||
|
||||
void main() {
|
||||
gl_Position = mvp * vec4(vertexPosition_modelspace, 1);
|
||||
|
||||
position_worldspace = (m * vec4(vertexPosition_modelspace, 1)).xyz;
|
||||
|
||||
vec3 vertexPosition_cameraspace = (v * m * vec4(vertexPosition_modelspace, 1)).xyz;
|
||||
eyeDirection_cameraspace = vec3(0, 0, 0) - vertexPosition_cameraspace;
|
||||
|
||||
vec3 lightPosition_cameraspace = (v * vec4(lightPosition_worldspace, 1)).xyz;
|
||||
lightDirection_cameraspace = lightPosition_cameraspace + eyeDirection_cameraspace;
|
||||
|
||||
normal_cameraspace = (v * m * vec4(vertexNormal_modelspace, 0)).xyz;
|
||||
|
||||
UV = vertexUV;
|
||||
}
|
@ -15,9 +15,7 @@
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS // ImGui
|
||||
#include <backends/imgui_impl_glfw.h>
|
||||
#include <backends/imgui_impl_opengl3.h>
|
||||
#include <imgui/imgui.h>
|
||||
#define VGIZMO_USES_GLM
|
||||
#include <imGuIZMO.quat/imGuIZMOquat.h>
|
||||
#include <imgui.h>
|
||||
#include <clog/clog.h>
|
||||
|
||||
#include <SOIL2.h>
|
||||
@ -42,6 +40,7 @@ static 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) {
|
||||
clog_log(CLOG_LEVEL_DEBUG, "Loading model: %s", path);
|
||||
Assimp::Importer importer;
|
||||
|
||||
const aiScene *scene = importer.ReadFile(
|
||||
@ -66,6 +65,10 @@ static bool loadModel(const char *path, std::vector<unsigned short> &indices,
|
||||
}
|
||||
|
||||
normals.reserve(mesh->mNumVertices);
|
||||
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
|
||||
aiVector3D normal = mesh->mNormals[i];
|
||||
normals.push_back(glm::vec3(normal.x, normal.y, normal.z));
|
||||
}
|
||||
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]);
|
||||
@ -76,6 +79,7 @@ static bool loadModel(const char *path, std::vector<unsigned short> &indices,
|
||||
}
|
||||
|
||||
GLuint loadTexture(const char *path) {
|
||||
clog_log(CLOG_LEVEL_DEBUG, "Loading texture: %s", path);
|
||||
GLuint texture = SOIL_load_OGL_texture(
|
||||
path, SOIL_LOAD_AUTO,
|
||||
SOIL_CREATE_NEW_ID,
|
||||
@ -164,50 +168,123 @@ public:
|
||||
GLuint *elementBuffer;
|
||||
|
||||
GLuint matrixID;
|
||||
GLuint textureID;
|
||||
GLuint viewMatrixID;
|
||||
GLuint modelMatrixID;
|
||||
|
||||
GLuint albedoTextureID;
|
||||
GLuint specularTextureID;
|
||||
|
||||
GLuint lightID;
|
||||
GLuint lightColor;
|
||||
GLuint lightPower;
|
||||
|
||||
glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
glm::quat rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f); // https://en.wikipedia.org/wiki/Quaternion
|
||||
glm::vec3 scaling = glm::vec3(1.0f, 1.0f, 1.0f);
|
||||
|
||||
GLuint *modelTexture;
|
||||
GLuint *albedoTexture;
|
||||
GLuint *specularTexture;
|
||||
|
||||
GLuint *shaderProgram;
|
||||
|
||||
Asset(Model &model, Texture &texture, Shader &shader) {
|
||||
Asset(Model &model, Texture &albedoTextureI, Texture &specularTextureI, Shader &shader) {
|
||||
indices = &model.indices;
|
||||
vertexBuffer = &model.vertexBuffer;
|
||||
uvBuffer = &model.uvBuffer;
|
||||
normalBuffer = &model.normalBuffer;
|
||||
elementBuffer = &model.elementBuffer;
|
||||
|
||||
modelTexture = &texture.texture;
|
||||
albedoTexture = &albedoTextureI.texture;
|
||||
specularTexture = &specularTextureI.texture;
|
||||
|
||||
shaderProgram = &shader.shaderProgram;
|
||||
|
||||
matrixID = glGetUniformLocation(*shaderProgram, "MVP");
|
||||
textureID = glGetUniformLocation(*shaderProgram, "textureSampler");
|
||||
matrixID = glGetUniformLocation(*shaderProgram, "mvp");
|
||||
viewMatrixID = glGetUniformLocation(*shaderProgram, "v");
|
||||
modelMatrixID = glGetUniformLocation(*shaderProgram, "m");
|
||||
|
||||
albedoTextureID = glGetUniformLocation(*shaderProgram, "albedoSampler");
|
||||
specularTextureID = glGetUniformLocation(*shaderProgram, "specularSampler");
|
||||
|
||||
lightID = glGetUniformLocation(*shaderProgram, "lightPosition_worldspace");
|
||||
lightColor = glGetUniformLocation(*shaderProgram, "lightColor");
|
||||
lightPower = glGetUniformLocation(*shaderProgram, "lightPower");
|
||||
}
|
||||
};
|
||||
|
||||
class Camera {
|
||||
public:
|
||||
glm::vec3 position;
|
||||
glm::quat rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
float fov = glm::radians(60.0f);
|
||||
float nearPlane = 0.1f;
|
||||
float farPlane = 100.0f;
|
||||
|
||||
|
||||
Camera(glm::vec3 initPosition) {
|
||||
position = initPosition;
|
||||
}
|
||||
Camera(glm::vec3 initPosition, glm::quat initRotation) {
|
||||
position = initPosition;
|
||||
rotation = initRotation;
|
||||
}
|
||||
Camera(glm::vec3 initPosition, glm::quat initRotation, float initFov) {
|
||||
position = initPosition;
|
||||
rotation = initRotation;
|
||||
fov = initFov;
|
||||
}
|
||||
Camera(glm::vec3 initPosition, glm::quat initRotation, float initFov, float initNearPlane, float initFarPlane) {
|
||||
position = initPosition;
|
||||
rotation = initRotation;
|
||||
fov = initFov;
|
||||
nearPlane = initNearPlane;
|
||||
farPlane = initFarPlane;
|
||||
}
|
||||
void lookAt(glm::vec3 target) { // I think I lost it writing this
|
||||
glm::mat4 lookAtMatrix = glm::lookAt(position, target, glm::vec3(0, 1, 0));
|
||||
rotation = glm::conjugate(glm::quat(lookAtMatrix));
|
||||
}
|
||||
};
|
||||
|
||||
class Scene {
|
||||
public:
|
||||
std::vector<Asset*> assets;
|
||||
void addAsset(Asset *asset) {
|
||||
assets.push_back(asset);
|
||||
std::vector<Camera*> cameras;
|
||||
void (*renderCallback)() = NULL;
|
||||
|
||||
int activeCamera = 0;
|
||||
|
||||
void addAsset(Asset &asset) {
|
||||
assets.push_back(&asset);
|
||||
}
|
||||
void addCamera(Camera &camera) {
|
||||
cameras.push_back(&camera);
|
||||
}
|
||||
void setRenderCallback(void (*callback)()) {
|
||||
renderCallback = callback;
|
||||
}
|
||||
};
|
||||
|
||||
GLFWwindow *window;
|
||||
GLuint vertexArrayID;
|
||||
float deltaTime = 0;
|
||||
float deltaTimeMultiplier = 1.0f;
|
||||
|
||||
void setDeltaTimeMultiplier(float mult) {
|
||||
deltaTimeMultiplier = mult;
|
||||
}
|
||||
float getDeltaTime() {
|
||||
return deltaTime * deltaTimeMultiplier;
|
||||
}
|
||||
float getUnscaledDeltaTime() {
|
||||
return deltaTime;
|
||||
}
|
||||
|
||||
static bool shouldExit() {
|
||||
return glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0;
|
||||
}
|
||||
|
||||
glm::mat4 mvp; // TODO: REMOVE THIS PLLAAAHSE
|
||||
glm::mat4 viewMatrix;
|
||||
glm::mat4 projectionMatrix;
|
||||
|
||||
static int initWindow() {
|
||||
glfwSetErrorCallback(glfwErrorCallback);
|
||||
|
||||
@ -253,22 +330,6 @@ static int initWindow() {
|
||||
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||
ImGui_ImplOpenGL3_Init("#version 330");
|
||||
|
||||
|
||||
// I love glm
|
||||
// Projection matrix, 45deg FOV, 4:3 Aspect Ratio, Planes: 0.1units ->
|
||||
// 100units
|
||||
projectionMatrix = glm::perspective(
|
||||
glm::radians(45.0f), (float)WIDTH / (float)HEIGHT, 0.1f, 100.0f);
|
||||
|
||||
// Camera matrix
|
||||
viewMatrix =
|
||||
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
|
||||
mvp = projectionMatrix * viewMatrix * model;
|
||||
|
||||
glEnable(GL_DEPTH_TEST); // Turn on the Z-buffer
|
||||
glDepthFunc(GL_LESS); // Accept only the closest fragments
|
||||
|
||||
@ -276,52 +337,58 @@ static int initWindow() {
|
||||
|
||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||
|
||||
GLuint vertexArrayID;
|
||||
glGenVertexArrays(1, &vertexArrayID);
|
||||
glBindVertexArray(vertexArrayID);
|
||||
|
||||
// Define camera stuff
|
||||
//glm::vec3 position = {4, 3, 3};
|
||||
//float horizontalAngle = 3.14f;
|
||||
//float verticalAngle = -0.1f;
|
||||
//float initialFOV = 60.0f;
|
||||
|
||||
//float speed = 3.0f;
|
||||
//float mouseSpeed = 0.005f;
|
||||
|
||||
//double xpos, ypos;
|
||||
|
||||
//glDeleteVertexArrays(1, &vertexArrayID);
|
||||
//ImGui_ImplOpenGL3_Shutdown();
|
||||
//ImGui_ImplGlfw_Shutdown();
|
||||
//ImGui::DestroyContext();
|
||||
|
||||
//glfwDestroyWindow(window);
|
||||
//glfwTerminate();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//void imguiMat4Table(glm::mat4 matrix, const char *name) {
|
||||
// if (ImGui::BeginTable(name, 4)) {
|
||||
// for (int i = 0; i < 4; i++) {
|
||||
// for (int j = 0; j < 4; j++) {
|
||||
// ImGui::TableNextColumn();
|
||||
// ImGui::Text("%f", matrix[i][j]);
|
||||
// }
|
||||
// }
|
||||
// ImGui::EndTable();
|
||||
// }
|
||||
//}
|
||||
void destroy() {
|
||||
glDeleteVertexArrays(1, &vertexArrayID);
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
/*void imguiMat4Table(glm::mat4 matrix, const char *name) {*/
|
||||
/* if (ImGui::BeginTable(name, 4)) {*/
|
||||
/* for (int i = 0; i < 4; i++) {*/
|
||||
/* for (int j = 0; j < 4; j++) {*/
|
||||
/* ImGui::TableNextColumn();*/
|
||||
/* ImGui::Text("%f", matrix[i][j]);*/
|
||||
/* }*/
|
||||
/* }*/
|
||||
/* ImGui::EndTable();*/
|
||||
/* }*/
|
||||
/*}*/
|
||||
|
||||
void render(Scene scene) {
|
||||
// Clear this mf
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
static double lastTime = glfwGetTime();
|
||||
double currentTime = glfwGetTime();
|
||||
deltaTime = float(currentTime - lastTime);
|
||||
lastTime = currentTime;
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
Camera *currentCamera = scene.cameras[scene.activeCamera];
|
||||
|
||||
// Compute the V and P for the MVP
|
||||
glm::mat4 viewMatrix = glm::inverse(glm::translate(glm::mat4(1), currentCamera->position) * (mat4_cast(currentCamera->rotation)));
|
||||
glm::mat4 projectionMatrix = glm::perspective(currentCamera->fov, (float)WIDTH / (float)HEIGHT, currentCamera->nearPlane, currentCamera->farPlane);
|
||||
|
||||
for (int i = 0; i < scene.assets.size(); i++) {
|
||||
Asset *currentAsset = scene.assets[i];
|
||||
|
||||
@ -333,20 +400,38 @@ void render(Scene scene) {
|
||||
glm::mat4 scalingMatrix = glm::scale(glm::mat4(1), currentAsset->scaling);
|
||||
glm::mat4 modelMatrix = translationMatrix * rotationMatrix * scalingMatrix;
|
||||
|
||||
mvp = projectionMatrix * viewMatrix * modelMatrix;
|
||||
glm::mat4 mvp = projectionMatrix * viewMatrix * modelMatrix;
|
||||
|
||||
char assetName[] = "Asset: 00";
|
||||
sprintf(assetName, "Asset: %d", i);
|
||||
ImGui::Begin(assetName);
|
||||
ImGui::gizmo3D(assetName, currentAsset->rotation);
|
||||
ImGui::Text("Frametime/Deltatime (ms): %f", deltaTime * 1000);
|
||||
glm::vec3 rotationEuler = glm::degrees(eulerAngles(currentAsset->rotation));
|
||||
ImGui::DragFloat3("Translate", (float*)¤tAsset->position, 0.01f);
|
||||
ImGui::DragFloat3("Rotate", (float*)&rotationEuler);
|
||||
ImGui::DragFloat3("Scale", (float*)¤tAsset->scaling, 0.01f);
|
||||
currentAsset->rotation = glm::quat(glm::radians(rotationEuler));
|
||||
ImGui::End();
|
||||
|
||||
glUniformMatrix4fv(currentAsset->matrixID, 1, GL_FALSE, &mvp[0][0]);
|
||||
glUniformMatrix4fv(currentAsset->modelMatrixID, 1, GL_FALSE, &modelMatrix[0][0]);
|
||||
glUniformMatrix4fv(currentAsset->viewMatrixID, 1, GL_FALSE, &viewMatrix[0][0]);
|
||||
|
||||
glm::vec3 lightPos = glm::vec3(4, 4, 4);
|
||||
glm::vec3 lightColor = glm::vec3(1, 1, 1);
|
||||
float lightPower = 50;
|
||||
glUniform3f(currentAsset->lightID, lightPos.x, lightPos.y, lightPos.z);
|
||||
glUniform3f(currentAsset->lightColor, lightColor.x, lightColor.y, lightColor.z);
|
||||
glUniform1f(currentAsset->lightPower, lightPower);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, *currentAsset->modelTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, *currentAsset->albedoTexture);
|
||||
// Set sampler texture
|
||||
glUniform1i(currentAsset->textureID, 0);
|
||||
glUniform1i(currentAsset->albedoTextureID, 0);
|
||||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, *currentAsset->specularTexture);
|
||||
glUniform1i(currentAsset->specularTextureID, 1);
|
||||
|
||||
// DRAWING HAPPENS HERE
|
||||
// Vertex Data
|
||||
@ -375,6 +460,10 @@ void render(Scene scene) {
|
||||
glDisableVertexAttribArray(2);
|
||||
}
|
||||
|
||||
if (scene.renderCallback != NULL) {
|
||||
scene.renderCallback();
|
||||
}
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
@ -385,27 +474,61 @@ void render(Scene scene) {
|
||||
|
||||
} // namespace fred
|
||||
|
||||
// Userspace ================================================================ //
|
||||
|
||||
fred::Scene scene;
|
||||
|
||||
void renderCallback() {
|
||||
ImGui::Begin("User Render Callback");
|
||||
ImGui::Text("Frametime (ms): %f", fred::getUnscaledDeltaTime() * 1000);
|
||||
ImGui::Text("FPS: %f", 1/fred::getUnscaledDeltaTime());
|
||||
ImGui::SeparatorText("Camera");
|
||||
fred::Camera *currentCamera = scene.cameras[scene.activeCamera];
|
||||
glm::vec3 rotationEuler = glm::degrees(eulerAngles(currentCamera->rotation));
|
||||
ImGui::DragFloat3("Translate", (float*)¤tCamera->position, 0.01f);
|
||||
ImGui::DragFloat3("Rotate", (float*)&rotationEuler);
|
||||
float fovDeg = glm::degrees(currentCamera->fov);
|
||||
ImGui::DragFloat("FOV", (float*)&fovDeg);
|
||||
currentCamera->fov = glm::radians(fovDeg);
|
||||
currentCamera->rotation = glm::quat(glm::radians(rotationEuler));
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
int main() {
|
||||
fred::initWindow();
|
||||
fred::Model coneModel("../models/model.obj");
|
||||
fred::Model suzanneMod("../models/suzanne.obj");
|
||||
fred::Texture buffBlackGuy("../textures/results/texture_BMP_DXT5_3.DDS");
|
||||
fred::Shader basicShader("../shaders/shader.vert", "../shaders/shader.frag");
|
||||
fred::Asset cone(coneModel, buffBlackGuy, basicShader);
|
||||
fred::Asset coneTwo(coneModel, buffBlackGuy, basicShader);
|
||||
fred::Texture suzanneTexAlb("../textures/results/suzanne_albedo_DXT5.DDS");
|
||||
fred::Texture suzanneTexSpec("../textures/results/suzanne_specular_DXT5.DDS");
|
||||
fred::Shader basicShader("../shaders/basic.vert", "../shaders/basic.frag");
|
||||
fred::Shader basicLitShader("../shaders/basic_lit.vert", "../shaders/basic_lit.frag");
|
||||
fred::Asset cone(coneModel, buffBlackGuy, buffBlackGuy, basicShader);
|
||||
fred::Asset suzanne(suzanneMod, suzanneTexAlb, suzanneTexSpec, basicLitShader);
|
||||
|
||||
fred::Scene scene = fred::Scene();
|
||||
fred::Camera mainCamera(glm::vec3(4, 3, 3));
|
||||
mainCamera.lookAt(glm::vec3(0, 0, 0));
|
||||
|
||||
scene.addAsset(&cone);
|
||||
scene.addAsset(&coneTwo);
|
||||
scene = fred::Scene();
|
||||
|
||||
scene.addCamera(mainCamera);
|
||||
|
||||
scene.addAsset(cone);
|
||||
scene.addAsset(suzanne);
|
||||
|
||||
scene.setRenderCallback(&renderCallback);
|
||||
|
||||
fred::setDeltaTimeMultiplier(20.0f);
|
||||
|
||||
while (fred::shouldExit()) {
|
||||
//while (1) {
|
||||
fred::render(scene);
|
||||
cone.position.x += 0.01;
|
||||
glm::vec3 eulerAngles = glm::eulerAngles(coneTwo.rotation);
|
||||
eulerAngles.x += glm::radians(1.0f);
|
||||
coneTwo.rotation = glm::quat(eulerAngles);
|
||||
cone.position.x += 0.01 * fred::getDeltaTime();
|
||||
glm::vec3 eulerAngles = glm::eulerAngles(suzanne.rotation);
|
||||
eulerAngles.x += glm::radians(1.0f) * fred::getDeltaTime();
|
||||
suzanne.rotation = glm::quat(eulerAngles);
|
||||
}
|
||||
|
||||
fred::destroy();
|
||||
|
||||
return 0;
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <clog/clog.h>
|
||||
#include <clog/extra.h>
|
||||
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
@ -1,41 +0,0 @@
|
||||
<?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/suzanne_albedo_DXT1.DDS
Normal file
BIN
textures/results/suzanne_albedo_DXT1.DDS
Normal file
Binary file not shown.
BIN
textures/results/suzanne_albedo_DXT3.DDS
Normal file
BIN
textures/results/suzanne_albedo_DXT3.DDS
Normal file
Binary file not shown.
BIN
textures/results/suzanne_albedo_DXT5.DDS
Normal file
BIN
textures/results/suzanne_albedo_DXT5.DDS
Normal file
Binary file not shown.
BIN
textures/results/suzanne_specular_DXT1.DDS
Normal file
BIN
textures/results/suzanne_specular_DXT1.DDS
Normal file
Binary file not shown.
BIN
textures/results/suzanne_specular_DXT3.DDS
Normal file
BIN
textures/results/suzanne_specular_DXT3.DDS
Normal file
Binary file not shown.
BIN
textures/results/suzanne_specular_DXT5.DDS
Normal file
BIN
textures/results/suzanne_specular_DXT5.DDS
Normal file
Binary file not shown.
BIN
textures/results/teapot_DXT1.DDS
Normal file
BIN
textures/results/teapot_DXT1.DDS
Normal file
Binary file not shown.
BIN
textures/results/teapot_DXT3.DDS
Normal file
BIN
textures/results/teapot_DXT3.DDS
Normal file
Binary file not shown.
BIN
textures/results/teapot_DXT5.DDS
Normal file
BIN
textures/results/teapot_DXT5.DDS
Normal file
Binary file not shown.
BIN
textures/suzanne_albedo.png
Normal file
BIN
textures/suzanne_albedo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 248 KiB |
BIN
textures/suzanne_specular.png
Normal file
BIN
textures/suzanne_specular.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 106 KiB |
BIN
textures/teapot.png
Normal file
BIN
textures/teapot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 70 KiB |
Loading…
Reference in New Issue
Block a user