Start day 16, scene refactor.

This commit is contained in:
Zed A. Shaw 2026-08-26 13:22:27 -04:00
parent f2a20876f3
commit 3041ae0172
73 changed files with 14114 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,40 @@
#include <fuc2/run.hpp>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include "dbc.hpp"
TEST_SET(shader_tests);
TEST_SET(model_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
};
return run_tests(tests, argc, argv);
}

View file

@ -0,0 +1,5 @@
fuc2_tests = files(
'main.cpp',
'shader_tests.cpp',
'model_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),
}
};
}