Huge graphics overhaul
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
#include "GLLoad.hpp"
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
||||
#include "Image.hpp"
|
||||
#include "ProgramPipeline.hpp"
|
||||
#include "VertexArray.hpp"
|
||||
#include "Window.hpp"
|
||||
#include "Textures.hpp"
|
||||
|
||||
int main() {
|
||||
nb::logger.log("Howdy!");
|
||||
@@ -10,54 +15,90 @@ int main() {
|
||||
window.setWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
window.init();
|
||||
|
||||
nb::logger.log("Goob");
|
||||
|
||||
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("Vertex Shader: " + vert->log());
|
||||
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 = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
|
||||
" FragColor = texture(tex, vPos);\n"
|
||||
"}\n\0"
|
||||
);
|
||||
|
||||
LOG("Fragment shader: " + frag->log());
|
||||
LOG(frag->log());
|
||||
|
||||
nb::ByteVector data = nb::vectorToBytes<float>({
|
||||
-0.5, -0.5, 0.5, -0.5, 0.0, 0.5
|
||||
-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, 8}
|
||||
{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)) {
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
tri.draw();
|
||||
glfwPollEvents();
|
||||
glfwSwapBuffers(window_ptr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user