107 lines
2.6 KiB
C++
107 lines
2.6 KiB
C++
#include <NBGraphics/GLLoad.hpp>
|
|
#define STB_IMAGE_IMPLEMENTATION
|
|
#include "stb_image.h"
|
|
|
|
#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!");
|
|
nb::Window window(400, 400, "Hello!");
|
|
window.setWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
window.setWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
|
window.init();
|
|
|
|
auto vert = std::make_shared<nb::Shader>(
|
|
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"
|
|
"void main()\n"
|
|
"{\n"
|
|
" gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0);\n"
|
|
" vPos = tPos;\n"
|
|
"}\0"
|
|
);
|
|
|
|
LOG(vert->log());
|
|
|
|
auto frag = std::make_shared<nb::Shader>(
|
|
GL_FRAGMENT_SHADER,
|
|
"#version 330 core\n"
|
|
"in vec2 vPos;\n"
|
|
"out vec4 FragColor;\n"
|
|
"uniform sampler2D tex;\n"
|
|
"void main()\n"
|
|
"{\n"
|
|
" FragColor = texture(tex, vPos);\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
|
|
});
|
|
|
|
nb::Program prog({vert, frag});
|
|
prog.bind();
|
|
|
|
std::vector<uint32_t> indxs = {0, 1, 2, 0, 2, 3};
|
|
|
|
nb::VertexGroup tri(data, {
|
|
nb::VertexAttribute{
|
|
2,
|
|
GL_FLOAT,
|
|
false,
|
|
{0, 16}
|
|
},
|
|
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);
|
|
tri.draw();
|
|
glfwPollEvents();
|
|
glfwSwapBuffers(window_ptr);
|
|
}
|
|
|
|
return 0;
|
|
} |