95 lines
2.3 KiB
C++
95 lines
2.3 KiB
C++
#include <NBGraphics/GLLoad.hpp>
|
|
#define STB_IMAGE_IMPLEMENTATION
|
|
#include "stb_image.h"
|
|
|
|
#include <NBCore/Errors.hpp>
|
|
#include <NBCore/TypeTraits.hpp>
|
|
#include <NBGraphics/Image.hpp>
|
|
#include <NBGraphics/Mesh.hpp>
|
|
#include <NBGraphics/ProgramPipeline.hpp>
|
|
#include <NBGraphics/VertexData.hpp>
|
|
#include <NBGraphics/Window.hpp>
|
|
#include <NBGraphics/Textures.hpp>
|
|
|
|
|
|
int main() {
|
|
LOG("Howdy!");
|
|
auto window = nb::OGLWindow::CreateWindow(
|
|
400,
|
|
400,
|
|
"Howdy!",
|
|
nb::KeyVal(GLFW_CONTEXT_VERSION_MAJOR, 3),
|
|
nb::KeyVal(GLFW_CONTEXT_VERSION_MINOR, 3)
|
|
);
|
|
nb::OGLWindow::MakeCurrent(window);
|
|
|
|
auto vert = std::make_shared<nb::Shader>(
|
|
GL_VERTEX_SHADER,
|
|
"#version 330 core\n"
|
|
"layout (location = 0) in vec2 aPos;\n"
|
|
"out vec4 vColor;\n"
|
|
"void main()\n"
|
|
"{\n"
|
|
" gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0);\n"
|
|
" vec2 tmp = (aPos+vec2(1.0, 1.0))*0.5;\n"
|
|
" vColor = vec4(tmp.x, 0, tmp.y, 1.0);\n"
|
|
"}\0"
|
|
);
|
|
|
|
LOG(vert->log());
|
|
|
|
auto frag = std::make_shared<nb::Shader>(
|
|
GL_FRAGMENT_SHADER,
|
|
"#version 330 core\n"
|
|
"in vec4 vColor;\n"
|
|
"out vec4 FragColor;\n"
|
|
"void main()\n"
|
|
"{\n"
|
|
" FragColor = vColor;\n"
|
|
"}\n\0"
|
|
);
|
|
|
|
LOG(frag->log());
|
|
|
|
nb::ByteVector data = nb::vectorToBytes<float>({
|
|
-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};
|
|
|
|
nb::IndexedMesh tri(GL_TRIANGLES, data, {nb::VertexAttribute{
|
|
2,
|
|
nb::TypeCodes::FLOAT32,
|
|
false,
|
|
{0, 8}
|
|
}}, indxs);
|
|
LOG(prog.log());
|
|
|
|
using nb::WindowCallbacks;
|
|
|
|
window->setCallback<nb::KEY>(
|
|
[](nb::OGLWindow* w, int key, int, int, int)->void{
|
|
if (key == GLFW_KEY_Q) {
|
|
w->shouldClose(true);
|
|
}
|
|
});
|
|
window->setCallback<nb::CURSOR_POS>(
|
|
[](nb::OGLWindow* w, double x, double y)->void{
|
|
nb::logger.msg("Pos in x is " + std::to_string(x));
|
|
}
|
|
);
|
|
while(!window->shouldClose()) {
|
|
OPENGL_CALL(glClearColor(0.2f, 0.3f, 0.3f, 1.0f));
|
|
OPENGL_CALL(glClear(GL_COLOR_BUFFER_BIT));
|
|
tri.draw();
|
|
window->pollEvents();
|
|
window->swapBuffers();
|
|
}
|
|
|
|
return 0;
|
|
} |