Engine core and assets loading refactor

This commit is contained in:
MihailRis
2023-10-30 15:19:58 +03:00
committed by GitHub
parent 972db16a0c
commit 0576316282
10 changed files with 325 additions and 181 deletions
+42
View File
@@ -20,6 +20,19 @@
HudRenderer::HudRenderer() {
// float vertices[] = {
// // x y
// -0.01f,-0.01f,
// 0.01f, 0.01f,
// -0.01f, 0.01f,
// 0.01f,-0.01f,
// };
// int attrs[] = {
// 2, 0 //null terminator
// };
// crosshair = new Mesh(vertices, 4, attrs);
batch = new Batch2D(1024);
uicamera = new Camera(glm::vec3(), Window::height / 1.0f);
uicamera->perspective = false;
@@ -66,6 +79,7 @@ void HudRenderer::draw(Level* level, Assets* assets){
// Chosen block preview
Texture* blocks = assets->getTexture("block");
Texture* sprite = assets->getTexture("slot");
batch->texture(nullptr);
batch->color = vec4(1.0f);
@@ -76,6 +90,13 @@ void HudRenderer::draw(Level* level, Assets* assets){
batch->line(Window::width/2-5, Window::height/2-5, Window::width/2+5, Window::height/2+5, 0.9f, 0.9f, 0.9f, 1.0f);
batch->line(Window::width/2+5, Window::height/2-5, Window::width/2-5, Window::height/2+5, 0.9f, 0.9f, 0.9f, 1.0f);
}
// batch->texture(sprite);
// batch->sprite(Window::width/2-32, uicamera->fov - 80, 64, 64, 16, 0, vec4(1.0f));
// batch->rect(Window::width/2-128-4, Window::height-80-4, 256+8, 64+8,
// 0.85f, 0.85f, 0.85f, 0.95f, 0.95f, 0.95f,
// 0.55f, 0.55f, 0.55f,
// 0.45f, 0.45f, 0.45f, 0.7f, 0.7f, 0.7f, 2);
batch->rect(Window::width/2-128-4, Window::height-80-4, 256+8, 64+8,
0.95f, 0.95f, 0.95f, 0.85f, 0.85f, 0.85f,
0.7f, 0.7f, 0.7f,
@@ -146,6 +167,7 @@ void HudRenderer::draw(Level* level, Assets* assets){
for (uint i = 1; i < count; i++) {
x = xs + step * ((i-1) % (inv_w / step));
y = ys + step * ((i-1) / (inv_w / step));
// batch->rect(x-2, y-2, size+4, size+4);
batch->rect(x-2, y-2, size+4, size+4,
0.45f, 0.45f, 0.45f, 0.55f, 0.55f, 0.55f,
0.7f, 0.7f, 0.7f,
@@ -156,6 +178,13 @@ void HudRenderer::draw(Level* level, Assets* assets){
0.65f, 0.65f, 0.65f, 0.65f, 0.65f, 0.65f, 2);
}
// batch->color = vec4(0.5f, 0.5f, 0.5f, 1.0f);
// for (unsigned i = 1; i < count; i++) {
// x = xs + step * ((i-1) % (inv_w / step));
// y = ys + step * ((i-1) / (inv_w / step));
// batch->rect(x, y, size, size);
// }
//front
batch->texture(blocks);
for (uint i = 1; i < count; i++) {
@@ -171,8 +200,10 @@ void HudRenderer::draw(Level* level, Assets* assets){
if (Events::jclicked(GLFW_MOUSE_BUTTON_LEFT)) {
player->choosenBlock = i;
}
// size = 50;
} else
{
// size = 48;
tint = vec4(1.0f);
}
@@ -183,4 +214,15 @@ void HudRenderer::draw(Level* level, Assets* assets){
}
}
}
// batch->render();
if (Events::_cursor_locked && !level->player->debug){
// Shader* crosshairShader = assets->getShader("crosshair");
// crosshairShader->use();
// crosshairShader->uniform1f("u_ar", (float)Window::height / (float)Window::width);
// crosshairShader->uniform1f("u_scale", 1.0f / ((float)Window::height / 1000.0f));
// glLineWidth(2.0f);
// crosshair->draw(GL_LINES);
}
}