BLT-With-Graphics-Template/tests/src/main.cpp

93 lines
2.5 KiB
C++
Raw Normal View History

2023-11-28 01:56:10 -05:00
#include <blt/gfx/window.h>
2023-12-28 16:14:12 -05:00
#include <blt/gfx/shader.h>
#include <blt/gfx/texture.h>
#include <blt/gfx/model.h>
#include <blt/std/logging.h>
2023-12-16 01:32:25 -05:00
#include <imgui.h>
2023-12-26 21:14:01 -05:00
#include "blt/gfx/imgui/IconsFontAwesome5.h"
2023-11-28 01:56:10 -05:00
2023-12-28 16:14:12 -05:00
#include <shaders/test.vert>
#include <shaders/test.frag>
const float raw_vertices[18] = {
// first triangle
0.5f, 0.5f, 0.0f, // top right
0.5f, -0.5f, 0.0f, // bottom right
-0.5f, 0.5f, 0.0f, // top left
// second triangle
0.5f, -0.5f, 0.0f, // bottom right
-0.5f, -0.5f, 0.0f, // bottom left
-0.5f, 0.5f, 0.0f // top left
};
float vertices[20] = {
// positions // texture coords
0.5f, 0.5f, 0.0f, 1.0f, 1.0f, // top right
0.5f, -0.5f, 0.0f, 1.0f, 0.0f, // bottom right
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, // bottom left
-0.5f, 0.5f, 0.0f, 0.0f, 1.0f // top left
};
const unsigned int indices[6] = { // note that we start from 0!
0, 1, 3, // first triangle
1, 2, 3 // second triangle
};
blt::gfx::vertex_array* vao;
blt::gfx::shader_t* shader;
blt::gfx::texture_gl2D* texture;
2023-11-28 01:56:10 -05:00
void init()
{
2023-12-28 16:14:12 -05:00
using namespace blt::gfx;
vbo_t vertices_vbo;
vbo_t indices_vbo;
vertices_vbo.create();
indices_vbo.create(GL_ELEMENT_ARRAY_BUFFER);
vertices_vbo.allocate(sizeof(vertices), vertices);
indices_vbo.allocate(sizeof(indices), indices);
vao = new vertex_array();
vao->bindVBO(vertices_vbo, 0, 3, GL_FLOAT, 5 * sizeof(float), 0);
vao->bindVBO(vertices_vbo, 1, 2, GL_FLOAT, 5 * sizeof(float), 3 * sizeof(float));
vao->bindElement(indices_vbo);
shader = new shader_t(shader_test_vert, shader_test_frag);
shader->bindAttribute(0, "vertex");
shader->bindAttribute(1, "uv_in");
texture_file file("../resources/textures/cumdollar.jpg");
texture = new texture_gl2D(file.texture());
2023-11-28 01:56:10 -05:00
}
void update(std::int32_t width, std::int32_t height)
{
2023-12-16 03:19:27 -05:00
ImGui::ShowDemoWindow();
2023-12-26 21:14:01 -05:00
ImGui::Text("%s among %d items", ICON_FA_FILE, 0);
ImGui::Button(ICON_FA_SEARCH " Search");
ImGui::End();
2023-12-28 16:14:12 -05:00
shader->bind();
glActiveTexture(GL_TEXTURE0);
texture->bind();
vao->bind();
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
2023-11-28 01:56:10 -05:00
}
2023-11-27 23:53:20 -05:00
int main()
{
2023-11-28 01:56:10 -05:00
blt::gfx::init(blt::gfx::window_data{"My Sexy Window", init, update}.setSyncInterval(1));
2023-12-28 16:14:12 -05:00
delete vao;
delete shader;
delete texture;
2023-11-28 01:56:10 -05:00
blt::gfx::cleanup();
2023-11-27 23:53:20 -05:00
return 0;
}