Setup for day 18.

This commit is contained in:
Zed A. Shaw 2026-08-28 11:53:01 -04:00
parent 032f10ef44
commit 993f148710
87 changed files with 14992 additions and 0 deletions

View file

@ -0,0 +1,10 @@
#version 330 core
layout (location = 0) in vec3 aPos; // the position variable has attribute position 0
out vec4 vertexColor; // specify a color output to the fragment shader
void main()
// syntax error here
gl_Position = vec4(aPos, 1.0); // see how we directly give a vec3 to vec4's constructor
vertexColor = vec4(0.5, 0.0, 0.0, 1.0); // set the output variable to a dark-red color
}

View file

@ -0,0 +1,74 @@
{
"material_test": {
"ambient": [0.1, 0.1, 0.1],
"shininess": 32.0,
"diffuseMap": 0,
"specularMap": 0
},
"lighting_test": {
"directional": [
{
"position": [0, 0, 0.0],
"direction":[-0.2, -1.0, -0.3],
"ambient":[0.2, 0.2, 0.2],
"diffuse":[0.8, 0.8, 0.8],
"specular":[1.0, 1.0, 1.0],
"constant": 0.0,
"linear": 0.0,
"quadratic": 0.0,
"cut_off": 0.0,
"outer_cut_off": 0.0
}
],
"positioned": [
{
"position": [1.2, 1.0, 2.0],
"direction":[-0.2, -1.0, -0.3],
"ambient":[0.2, 0.2, 0.2],
"diffuse":[0.8, 0.8, 0.8],
"specular":[1.0, 1.0, 1.0],
"constant": 1.0,
"linear": 0.09,
"quadratic": 0.032,
"cut_off": 12.5,
"outer_cut_off": 17.5
}
],
"spot": [
],
"camera": {
"position":[2.2, 1.0, 2.0],
"direction":[0.0, 0.0, -1.0],
"ambient":[0.2, 0.2, 0.2],
"diffuse":[0.8, 0.8, 0.8],
"specular":[1.0, 1.0, 1.0],
"constant": 1.0,
"linear": 0.09,
"quadratic": 0.032,
"cut_off": 12.5,
"outer_cut_off": 17.5
}
},
"camera_test": {
"position": [0.0, 0.0, 3.0],
"front": [0.0, 0.0, -1.0],
"up": [0.0, 1.0, 0.0],
"direction": [0.0, 0.0, 0.0],
"movement_speed": 20.0
},
"model_test": {
"directory": "assets",
"model_path": "create.obj"
},
"thing_test": {
"model": "crate",
"position": [0.0, 0.0, 0.0],
"material": "crate"
},
"shader_test": {
"vertex_path": "shaders/16-vert.glsl",
"frag_path": "shaders/16-frag.glsl"
}
}

View file

@ -0,0 +1,46 @@
#include <fuc2/testing.hpp>
#include "components.hpp"
#include <fstream>
#include "json.hpp"
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using namespace fuc2;
/*
* This also tests Mesh by using Model to load them.
*/
namespace config_tests {
void test_json_components() {
std::ifstream f{"tests/config.json"};
auto j = json::parse(f);
auto mat = j["material_test"].get<components::Material>();
CHECK(mat.ambient.x == 0.1f, "wrong value");
auto light = j["lighting_test"].get<components::Lighting>();
auto camera = j["camera_test"].get<components::Camera>();
auto model = j["model_test"].get<components::Model>();
auto thing = j["thing_test"].get<components::Thing>();
}
void test_load_json_config() {
std::ifstream f{"config.json"};
auto j = json::parse(f);
auto scene = j["scene"].get<components::Scene>();
}
fuc2::Set TESTS{
.name="config",
.options={ .fail_fast=false },
.tests={
TEST(test_json_components),
TEST(test_load_json_config),
}
};
}

View file

@ -0,0 +1,42 @@
#include <fuc2/run.hpp>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include "dbc.hpp"
TEST_SET(shader_tests);
TEST_SET(model_tests);
TEST_SET(config_tests);
using namespace fuc2;
int main(int argc, char* argv[]) {
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
if (window == NULL)
{
dbc::log("Failed to create GLFW window");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
// glad: load all OpenGL function pointers
// ---------------------------------------
if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
dbc::log("Failed to initialize GLAD");
return -1;
}
std::vector<fuc2::Set> tests{
shader_tests::TESTS,
model_tests::TESTS,
config_tests::TESTS,
};
return run_tests(tests, argc, argv);
}

View file

@ -0,0 +1,6 @@
fuc2_tests = files(
'main.cpp',
'shader_tests.cpp',
'model_tests.cpp',
'config_tests.cpp',
)

View file

@ -0,0 +1,42 @@
#include <deque>
#include <string>
#include <fuc2/testing.hpp>
#include "model.hpp"
#include "shader.hpp"
using namespace fuc2;
/*
* This also tests Mesh by using Model to load them.
*/
namespace model_tests {
void test_load_textures() {
Shader shader{"shaders/14-vert.glsl", "shaders/14-frag.glsl"};
Model popcorn{"assets", "popcorn_model_a.glb"};
popcorn.draw(shader);
Model crate_glb{"assets", "crate.glb"};
crate_glb.draw(shader);
Model crate_obj{"assets", "crate.obj"};
crate_obj.draw(shader);
}
void test_failures() {
auto runner = [&]() {
Model bad_obj{"assets", "does_not_exist.obj"};
};
BLOWS_UP(runner, "should fail on missing file.");
}
fuc2::Set TESTS{
.name="models",
.options={ .fail_fast=false },
.tests={
TEST(test_load_textures),
TEST(test_failures),
}
};
}

View file

@ -0,0 +1,33 @@
#include <deque>
#include <string>
#include <fuc2/testing.hpp>
#include "shader.hpp"
using namespace fuc2;
namespace shader_tests {
void test_load_shaders() {
Shader shader("shaders/3.3.shader.vs", "shaders/3.3.shader.fs");
shader.use();
CHECK(shader.ID != UINT_MAX, "Shader not initialized");
}
void test_compile_fail() {
auto runner = [&]() {
Shader shader("tests/bad_shader.vs", "shaders/3.3.shader.fs");
};
BLOWS_UP(runner, "compile fail should blow up");
}
fuc2::Set TESTS{
.name="shaders",
.options={ .fail_fast=false },
.tests={
TEST(test_load_shaders),
TEST(test_compile_fail),
}
};
}