Uhhhhh big big changes

This commit is contained in:
NaifBanana
2026-08-20 08:13:26 -05:00
parent 3e7e6acc3a
commit ac671c3770
20 changed files with 561 additions and 285 deletions
+9 -1
View File
@@ -4,21 +4,29 @@ if (NB_BUILD_TESTS)
enable_testing()
include(GoogleTest)
set(STBIMAGE_PATH ${NBENGINE_ROOT}/../stbi_image)
get_filename_component(STBIMAGE_PATH ${STBIMAGE_PATH} ABSOLUTE)
add_executable(TestWindow
./TestWindow.cpp
)
target_link_libraries(TestWindow
NBGraphics
)
target_include_directories(TestWindow
PRIVATE "${STBIMAGE_PATH}"
)
add_executable(TestImages
./testImages.cpp
)
target_link_libraries(TestImages
NBCore
NBGraphics
GTest::gtest_main
)
target_include_directories(TestImages
PRIVATE "${STBIMAGE_PATH}"
)
gtest_discover_tests(TestImages)
+15 -43
View File
@@ -2,14 +2,16 @@
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#include <NBCore/Errors.hpp>
#include <NBGraphics/Image.hpp>
#include <NBGraphics/ProgramPipeline.hpp>
#include <NBGraphics/VertexArray.hpp>
#include <NBGraphics/Window.hpp>
#include <NBGraphics/Textures.hpp>
int main() {
nb::logger.log("Howdy!");
LOG("Howdy!");
nb::Window window(400, 400, "Hello!");
window.setWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
window.setWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
@@ -19,12 +21,12 @@ int main() {
GL_VERTEX_SHADER,
"#version 330 core\n"
"layout (location = 0) in vec2 aPos;\n"
"layout (location = 1) in vec2 tPos;\n"
"out vec2 vPos;\n"
"out vec4 vColor;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0);\n"
" vPos = tPos;\n"
" vec2 tmp = (aPos+vec2(1.0, 1.0))*0.5;\n"
" vColor = vec4(tmp.x, 0, tmp.y, 1.0);\n"
"}\0"
);
@@ -33,71 +35,41 @@ int main() {
auto frag = std::make_shared<nb::Shader>(
GL_FRAGMENT_SHADER,
"#version 330 core\n"
"in vec2 vPos;\n"
"in vec4 vColor;\n"
"out vec4 FragColor;\n"
"uniform sampler2D tex;\n"
"void main()\n"
"{\n"
" FragColor = texture(tex, vPos);\n"
" FragColor = vColor;\n"
"}\n\0"
);
LOG(frag->log());
nb::ByteVector data = nb::vectorToBytes<float>({
-0.5, -0.5, 0,0,
-0.5, 0.5, 0,1,
0.5, 0.5, 1,1,
0.5, -0.5, 1,0
-0.5, -0.5,
0, 0.5,
0.5, -0.5
});
nb::Program prog({vert, frag});
prog.bind();
std::vector<uint32_t> indxs = {0, 1, 2, 0, 2, 3};
std::vector<uint32_t> indxs = {0, 1, 2};
nb::VertexGroup tri(data, {
nb::VertexAttribute{
2,
GL_FLOAT,
false,
{0, 16}
{0, 8}
},
nb::VertexAttribute{
2,
GL_FLOAT,
false,
{8, 16}
}
}, indxs);
tri.bind();
int width, height, numChannels;
auto raw_img_data = stbi_load(
"./awesomeface.png",
&width,
&height,
&numChannels,
0
);
LOG(numChannels);
using RGBA = nb::Pixel<uint8_t, nb::Red, nb::Green, nb::Blue, nb::Alpha>;
nb::ImageReference<RGBA> img(width, height, raw_img_data);
auto tex = nb::ImageTexture<RGBA>();
tex.parameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
tex.parameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
tex.setImage(img);
tex.bind();
tri.bind();
LOG(img.at(256, 256).r);
stbi_image_free(raw_img_data);
LOG(prog.log());
GLFWwindow* window_ptr = window.getWindow();
while(!glfwWindowShouldClose(window_ptr)) {
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
OPENGL_CALL(glClearColor(0.2f, 0.3f, 0.3f, 1.0f));
OPENGL_CALL(glClear(GL_COLOR_BUFFER_BIT));
tri.draw();
glfwPollEvents();
glfwSwapBuffers(window_ptr);